Support for hostname templates and updated naming
Change-Id: I1d46a456fdecaecaf873b31012d9178e75f37711
This commit is contained in:
parent
17d12a1b88
commit
9feed1b9a5
@ -43,7 +43,7 @@ def task_received(task, message_id):
|
||||
reporter = reporting.Reporter(rmqclient, message_id, task['id'])
|
||||
|
||||
command_dispatcher = CommandDispatcher(
|
||||
task['name'], rmqclient, task['token'], task['tenant_id'])
|
||||
'e' + task['id'], rmqclient, task['token'], task['tenant_id'])
|
||||
workflows = []
|
||||
for path in glob.glob("data/workflows/*.xml"):
|
||||
log.debug('Loading XML {0}'.format(path))
|
||||
|
@ -57,10 +57,10 @@ def prepare_user_data(context, hostname, service, unit,
|
||||
replacements = {
|
||||
'%RABBITMQ_HOST%': settings.host,
|
||||
'%RABBITMQ_INPUT_QUEUE%': '-'.join(
|
||||
[str(context['/dataSource']['name']),
|
||||
['e' + str(context['/dataSource']['id']),
|
||||
str(service), str(unit)]).lower(),
|
||||
'%RESULT_QUEUE%': '-execution-results-{0}'.format(
|
||||
str(context['/dataSource']['name'])).lower(),
|
||||
'%RESULT_QUEUE%': '-execution-results-e{0}'.format(
|
||||
str(context['/dataSource']['id'])).lower(),
|
||||
'%RABBITMQ_USER%': settings.login,
|
||||
'%RABBITMQ_PASSWORD%': settings.password,
|
||||
'%RABBITMQ_VHOST%': settings.virtual_host
|
||||
@ -86,7 +86,7 @@ def set_config_params(template_data, replacements):
|
||||
return template_data
|
||||
|
||||
|
||||
counter = 0
|
||||
counters = {}
|
||||
|
||||
|
||||
def int2base(x, base):
|
||||
@ -108,12 +108,23 @@ def int2base(x, base):
|
||||
return ''.join(digits)
|
||||
|
||||
|
||||
def generate_hostname(**kwargs):
|
||||
global counter
|
||||
def generate_hostname(pattern, service_id, **kwargs):
|
||||
if not pattern:
|
||||
return _generate_random_hostname()
|
||||
elif '#' in pattern:
|
||||
counter = counters.get(service_id) or 1
|
||||
counters[service_id] = counter + 1
|
||||
return pattern.replace('#', str(counter), 1)
|
||||
else:
|
||||
return pattern
|
||||
|
||||
|
||||
def _generate_random_hostname():
|
||||
counter = counters.get('') or 1
|
||||
prefix = ''.join(random.choice(string.lowercase) for _ in range(5))
|
||||
timestamp = int2base(int(time.time() * 1000), 36)[:8]
|
||||
suffix = int2base(counter, 36)
|
||||
counter = (counter + 1) % 1296
|
||||
counters[''] = (counter + 1) % 1296
|
||||
return prefix + timestamp + suffix
|
||||
|
||||
|
||||
|
@ -17,27 +17,27 @@ class WindowsAgentExecutor(CommandBase):
|
||||
self._results_queue = '-execution-results-%s' % str(stack).lower()
|
||||
rmqclient.declare(self._results_queue)
|
||||
|
||||
def execute(self, template, mappings, host, service, callback):
|
||||
with open('data/templates/agent/%s.template' % template) as file:
|
||||
template_data = file.read()
|
||||
def execute(self, template, mappings, unit, service, callback):
|
||||
with open('data/templates/agent/%s.template' % template) as t_file:
|
||||
template_data = t_file.read()
|
||||
|
||||
template_data = conductor.helpers.transform_json(
|
||||
json.loads(template_data), mappings)
|
||||
|
||||
id = str(uuid.uuid4()).lower()
|
||||
host = ('%s-%s-%s' % (self._stack, service, host)).lower()
|
||||
msg_id = str(uuid.uuid4()).lower()
|
||||
queue = ('%s-%s-%s' % (self._stack, service, unit)).lower()
|
||||
self._pending_list.append({
|
||||
'id': id,
|
||||
'id': msg_id,
|
||||
'callback': callback
|
||||
})
|
||||
|
||||
msg = Message()
|
||||
msg.body = template_data
|
||||
msg.id = id
|
||||
self._rmqclient.declare(host)
|
||||
self._rmqclient.send(message=msg, key=host)
|
||||
msg.id = msg_id
|
||||
self._rmqclient.declare(queue)
|
||||
self._rmqclient.send(message=msg, key=queue)
|
||||
log.info('Sending RMQ message {0} to {1} with id {2}'.format(
|
||||
template_data, host, id))
|
||||
template_data, queue, msg_id))
|
||||
|
||||
def has_pending_commands(self):
|
||||
return len(self._pending_list) > 0
|
||||
|
@ -13,11 +13,11 @@
|
||||
<update-cf-stack template="Windows">
|
||||
<parameter name="mappings">
|
||||
<map>
|
||||
<mapping name="instanceName"><select path="::name"/>-<select path="name"/></mapping>
|
||||
<mapping name="instanceName"><select path="state.hostname"/></mapping>
|
||||
<mapping name="userData">
|
||||
<prepare-user-data>
|
||||
<parameter name="hostname"><select path="state.hostname"/></parameter>
|
||||
<parameter name="unit"><select path="name"/></parameter>
|
||||
<parameter name="unit"><select path="id"/></parameter>
|
||||
<parameter name="service"><select path="::id"/></parameter>
|
||||
</prepare-user-data>
|
||||
</mapping>
|
||||
@ -43,8 +43,8 @@
|
||||
|
||||
<rule match="$.services.activeDirectories[*].units[?(@.state.instanceName and @.adminPassword and @.adminPassword != @.state.adminPassword)]">
|
||||
<send-command template="SetPassword">
|
||||
<parameter name="host">
|
||||
<select path="name"/>
|
||||
<parameter name="unit">
|
||||
<select path="id"/>
|
||||
</parameter>
|
||||
<parameter name="service">
|
||||
<select path="::id"/>
|
||||
@ -66,8 +66,8 @@
|
||||
|
||||
<rule match="$.services.activeDirectories[?(@.adminPassword and @.adminPassword != @.state.domainAdminPassword)].units[?(@.state.instanceName and @.isMaster)]">
|
||||
<send-command template="SetPassword">
|
||||
<parameter name="host">
|
||||
<select path="name"/>
|
||||
<parameter name="unit">
|
||||
<select path="id"/>
|
||||
</parameter>
|
||||
<parameter name="service">
|
||||
<select path="::id"/>
|
||||
@ -93,8 +93,8 @@
|
||||
<parameter name="text">Creating Primary Domain Controller on unit <select path="name"/></parameter>
|
||||
</report>
|
||||
<send-command template="CreatePrimaryDC">
|
||||
<parameter name="host">
|
||||
<select path="name"/>
|
||||
<parameter name="unit">
|
||||
<select path="id"/>
|
||||
</parameter>
|
||||
<parameter name="service">
|
||||
<select path="::id"/>
|
||||
@ -121,8 +121,8 @@
|
||||
|
||||
<rule match="$.services.activeDirectories[?(@.state.primaryDc and not @.state.primaryDcIp)].units[?(@.state.instanceName and @.isMaster)]">
|
||||
<send-command template="AskDnsIp" result="ip">
|
||||
<parameter name="host">
|
||||
<select path="name"/>
|
||||
<parameter name="unit">
|
||||
<select path="id"/>
|
||||
</parameter>
|
||||
<parameter name="service">
|
||||
<select path="::id"/>
|
||||
@ -146,8 +146,8 @@
|
||||
<parameter name="match">/$.services.activeDirectories[?(@.domain == '<select path="domain"/>' and @.state.primaryDcIp)]</parameter>
|
||||
|
||||
<send-command template="JoinDomain">
|
||||
<parameter name="host">
|
||||
<select path="name" source="unit"/>
|
||||
<parameter name="unit">
|
||||
<select path="id" source="unit"/>
|
||||
</parameter>
|
||||
<parameter name="service">
|
||||
<select path="id" source="service"/>
|
||||
@ -186,8 +186,8 @@
|
||||
<parameter name="text">Creating Secondary Domain Controller on unit <select path="name"/></parameter>
|
||||
</report>
|
||||
<send-command template="CreateSecondaryDC">
|
||||
<parameter name="host">
|
||||
<select path="name"/>
|
||||
<parameter name="unit">
|
||||
<select path="id"/>
|
||||
</parameter>
|
||||
<parameter name="service">
|
||||
<select path="::id"/>
|
||||
|
@ -13,11 +13,11 @@
|
||||
<update-cf-stack template="Windows">
|
||||
<parameter name="mappings">
|
||||
<map>
|
||||
<mapping name="instanceName"><select path="::name"/>-<select path="name"/></mapping>
|
||||
<mapping name="instanceName"><select path="state.hostname"/></mapping>
|
||||
<mapping name="userData">
|
||||
<prepare-user-data>
|
||||
<parameter name="hostname"><select path="state.hostname"/></parameter>
|
||||
<parameter name="unit"><select path="name"/></parameter>
|
||||
<parameter name="unit"><select path="id"/></parameter>
|
||||
<parameter name="service"><select path="::id"/></parameter>
|
||||
</prepare-user-data>
|
||||
</mapping>
|
||||
@ -43,8 +43,8 @@
|
||||
|
||||
<rule match="$.services.aspNetApps[?(@.adminPassword and @.adminPassword != @.state.adminPassword)].units[?(@.state.instanceName)]">
|
||||
<send-command template="SetPassword">
|
||||
<parameter name="host">
|
||||
<select path="name"/>
|
||||
<parameter name="unit">
|
||||
<select path="id"/>
|
||||
</parameter>
|
||||
<parameter name="service">
|
||||
<select path="::id"/>
|
||||
@ -70,8 +70,8 @@
|
||||
<parameter name="text">Creating IIS Web Server on unit <select path="name"/></parameter>
|
||||
</report>
|
||||
<send-command template="InstallIIS">
|
||||
<parameter name="host">
|
||||
<select path="name"/>
|
||||
<parameter name="unit">
|
||||
<select path="id"/>
|
||||
</parameter>
|
||||
<parameter name="service">
|
||||
<select path="::id"/>
|
||||
@ -92,8 +92,8 @@
|
||||
<parameter name="text">Deploying Web App on unit <select path="name"/></parameter>
|
||||
</report>
|
||||
<send-command template="DeployWebApp">
|
||||
<parameter name="host">
|
||||
<select path="name"/>
|
||||
<parameter name="unit">
|
||||
<select path="id"/>
|
||||
</parameter>
|
||||
<parameter name="service">
|
||||
<select path="::id"/>
|
||||
|
@ -1,7 +1,12 @@
|
||||
<workflow>
|
||||
|
||||
<rule match="$.services[*][*].units[?(@.state.hostname is None)]">
|
||||
<set path="state.hostname"><generate-hostname/></set>
|
||||
<set path="state.hostname">
|
||||
<generate-hostname>
|
||||
<parameter name="pattern"><select path="::unitNamingPattern"/></parameter>
|
||||
<parameter name="service_id"><select path="::id"/></parameter>
|
||||
</generate-hostname>
|
||||
</set>
|
||||
</rule>
|
||||
|
||||
<rule match="$[?(not @.state.deleted)]">
|
||||
|
@ -13,11 +13,11 @@
|
||||
<update-cf-stack template="Windows">
|
||||
<parameter name="mappings">
|
||||
<map>
|
||||
<mapping name="instanceName"><select path="::name"/>-<select path="name"/></mapping>
|
||||
<mapping name="instanceName"><select path="state.hostname"/></mapping>
|
||||
<mapping name="userData">
|
||||
<prepare-user-data>
|
||||
<parameter name="hostname"><select path="state.hostname"/></parameter>
|
||||
<parameter name="unit"><select path="name"/></parameter>
|
||||
<parameter name="unit"><select path="id"/></parameter>
|
||||
<parameter name="service"><select path="::id"/></parameter>
|
||||
</prepare-user-data>
|
||||
</mapping>
|
||||
@ -43,8 +43,8 @@
|
||||
|
||||
<rule match="$.services.webServers[?(@.adminPassword and @.adminPassword != @.state.adminPassword)].units[?(@.state.instanceName)]">
|
||||
<send-command template="SetPassword">
|
||||
<parameter name="host">
|
||||
<select path="name"/>
|
||||
<parameter name="unit">
|
||||
<select path="id"/>
|
||||
</parameter>
|
||||
<parameter name="service">
|
||||
<select path="::id"/>
|
||||
@ -71,8 +71,8 @@
|
||||
<parameter name="text">Creating IIS Web Server on unit <select path="name"/></parameter>
|
||||
</report>
|
||||
<send-command template="InstallIIS">
|
||||
<parameter name="host">
|
||||
<select path="name"/>
|
||||
<parameter name="unit">
|
||||
<select path="id"/>
|
||||
</parameter>
|
||||
<parameter name="service">
|
||||
<select path="::id"/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user