bug fix
This commit is contained in:
parent
9d38355517
commit
a9a3cbc573
@ -1,98 +1,98 @@
|
|||||||
import base64
|
import base64
|
||||||
|
|
||||||
import xml_code_engine
|
import xml_code_engine
|
||||||
import config
|
import config
|
||||||
from random import choice
|
from random import choice
|
||||||
import time
|
import time
|
||||||
import string
|
import string
|
||||||
|
|
||||||
|
|
||||||
def update_cf_stack(engine, context, body, template,
|
def update_cf_stack(engine, context, body, template,
|
||||||
mappings, arguments, **kwargs):
|
mappings, arguments, **kwargs):
|
||||||
command_dispatcher = context['/commandDispatcher']
|
command_dispatcher = context['/commandDispatcher']
|
||||||
|
|
||||||
callback = lambda result: engine.evaluate_content(
|
callback = lambda result: engine.evaluate_content(
|
||||||
body.find('success'), context)
|
body.find('success'), context)
|
||||||
|
|
||||||
command_dispatcher.execute(
|
command_dispatcher.execute(
|
||||||
name='cf', command='CreateOrUpdate', template=template,
|
name='cf', command='CreateOrUpdate', template=template,
|
||||||
mappings=mappings, arguments=arguments, callback=callback)
|
mappings=mappings, arguments=arguments, callback=callback)
|
||||||
|
|
||||||
|
|
||||||
def delete_cf_stack(engine, context, body, **kwargs):
|
def delete_cf_stack(engine, context, body, **kwargs):
|
||||||
command_dispatcher = context['/commandDispatcher']
|
command_dispatcher = context['/commandDispatcher']
|
||||||
|
|
||||||
callback = lambda result: engine.evaluate_content(
|
callback = lambda result: engine.evaluate_content(
|
||||||
body.find('success'), context)
|
body.find('success'), context)
|
||||||
|
|
||||||
command_dispatcher.execute(
|
command_dispatcher.execute(
|
||||||
name='cf', command='Delete', callback=callback)
|
name='cf', command='Delete', callback=callback)
|
||||||
|
|
||||||
|
|
||||||
def prepare_user_data(context, hostname, service, unit, template='Default', **kwargs):
|
def prepare_user_data(context, hostname, service, unit, template='Default', **kwargs):
|
||||||
settings = config.CONF.rabbitmq
|
settings = config.CONF.rabbitmq
|
||||||
|
|
||||||
with open('data/init.ps1') as init_script_file:
|
with open('data/init.ps1') as init_script_file:
|
||||||
with open('data/templates/agent-config/{0}.template'.format(
|
with open('data/templates/agent-config/{0}.template'.format(
|
||||||
template)) as template_file:
|
template)) as template_file:
|
||||||
init_script = init_script_file.read()
|
init_script = init_script_file.read()
|
||||||
template_data = template_file.read()
|
template_data = template_file.read()
|
||||||
template_data = template_data.replace(
|
template_data = template_data.replace(
|
||||||
'%RABBITMQ_HOST%', settings.host)
|
'%RABBITMQ_HOST%', settings.host)
|
||||||
template_data = template_data.replace(
|
template_data = template_data.replace(
|
||||||
'%RABBITMQ_INPUT_QUEUE%',
|
'%RABBITMQ_INPUT_QUEUE%',
|
||||||
'-'.join([str(context['/dataSource']['id']),
|
'-'.join([str(context['/dataSource']['name']),
|
||||||
str(service), str(unit)]).lower()
|
str(service), str(unit)]).lower()
|
||||||
)
|
)
|
||||||
template_data = template_data.replace(
|
template_data = template_data.replace(
|
||||||
'%RESULT_QUEUE%',
|
'%RESULT_QUEUE%',
|
||||||
'-execution-results-{0}'.format(
|
'-execution-results-{0}'.format(
|
||||||
str(context['/dataSource']['id'])).lower())
|
str(context['/dataSource']['id'])).lower())
|
||||||
|
|
||||||
init_script = init_script.replace(
|
init_script = init_script.replace(
|
||||||
'%WINDOWS_AGENT_CONFIG_BASE64%',
|
'%WINDOWS_AGENT_CONFIG_BASE64%',
|
||||||
base64.b64encode(template_data))
|
base64.b64encode(template_data))
|
||||||
|
|
||||||
init_script = init_script.replace('%INTERNAL_HOSTNAME%', hostname)
|
init_script = init_script.replace('%INTERNAL_HOSTNAME%', hostname)
|
||||||
|
|
||||||
return init_script
|
return init_script
|
||||||
|
|
||||||
counter = 0
|
counter = 0
|
||||||
|
|
||||||
|
|
||||||
def int2base(x, base):
|
def int2base(x, base):
|
||||||
digs = string.digits + string.lowercase
|
digs = string.digits + string.lowercase
|
||||||
if x < 0: sign = -1
|
if x < 0: sign = -1
|
||||||
elif x==0: return '0'
|
elif x==0: return '0'
|
||||||
else: sign = 1
|
else: sign = 1
|
||||||
x *= sign
|
x *= sign
|
||||||
digits = []
|
digits = []
|
||||||
while x:
|
while x:
|
||||||
digits.append(digs[x % base])
|
digits.append(digs[x % base])
|
||||||
x /= base
|
x /= base
|
||||||
if sign < 0:
|
if sign < 0:
|
||||||
digits.append('-')
|
digits.append('-')
|
||||||
digits.reverse()
|
digits.reverse()
|
||||||
return ''.join(digits)
|
return ''.join(digits)
|
||||||
|
|
||||||
|
|
||||||
def generate_hostname(**kwargs):
|
def generate_hostname(**kwargs):
|
||||||
global counter
|
global counter
|
||||||
prefix = ''.join(choice(string.lowercase) for _ in range(5))
|
prefix = ''.join(choice(string.lowercase) for _ in range(5))
|
||||||
timestamp = int2base(int(time.time() * 1000), 36)[:8]
|
timestamp = int2base(int(time.time() * 1000), 36)[:8]
|
||||||
suffix = int2base(counter, 36)
|
suffix = int2base(counter, 36)
|
||||||
counter = (counter + 1) % 1296
|
counter = (counter + 1) % 1296
|
||||||
return prefix + timestamp + suffix
|
return prefix + timestamp + suffix
|
||||||
|
|
||||||
|
|
||||||
xml_code_engine.XmlCodeEngine.register_function(
|
xml_code_engine.XmlCodeEngine.register_function(
|
||||||
update_cf_stack, "update-cf-stack")
|
update_cf_stack, "update-cf-stack")
|
||||||
|
|
||||||
xml_code_engine.XmlCodeEngine.register_function(
|
xml_code_engine.XmlCodeEngine.register_function(
|
||||||
delete_cf_stack, "delete-cf-stack")
|
delete_cf_stack, "delete-cf-stack")
|
||||||
|
|
||||||
xml_code_engine.XmlCodeEngine.register_function(
|
xml_code_engine.XmlCodeEngine.register_function(
|
||||||
prepare_user_data, "prepare-user-data")
|
prepare_user_data, "prepare-user-data")
|
||||||
|
|
||||||
xml_code_engine.XmlCodeEngine.register_function(
|
xml_code_engine.XmlCodeEngine.register_function(
|
||||||
generate_hostname, "generate-hostname")
|
generate_hostname, "generate-hostname")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user