def run(self, *args, **kwargs): self.args = args log.msg('Running action against "%s": %s args: %s timeout: %s' % (self.hostname, self.action, self.args, self.timeout), system='salt-simple', logLevel=logging.DEBUG) cmd = get_config().getstring('salt', 'remote_command', 'salt') killhook = kwargs.get('__killhook') if killhook: killhook.addCallback(lambda r: log.msg('"%s" to "%s" aborted' % (self.action, self.hostname))) timeout = ('--timeout=%s' % self.timeout) if self.timeout is not None else None args = (list(reduce(lambda a, b: a + b, map(lambda a: (dict_to_kwargs(a) if type(a) is dict else ['"%s"' % str(a)]), args))) if args else []) output = yield subprocess.async_check_output( filter(None, (cmd.split(' ') + ['--no-color', '--out=json', timeout, self.hostname, self.action] + args)), killhook=killhook) log.msg('Action "%s" to "%s" finished.' % (self.action, self.hostname), system='salt-simple', logLevel=logging.DEBUG) data = json.loads(output) if output else {} rdata = self._handle_errors(data) defer.returnValue(rdata)
def run(self, *args, **kwargs): self.args = args log.debug('Running action against "%s": %s args: %s timeout: %s', self.hostname, self.action, self.args, self.timeout) cmd = get_config().getstring('salt', 'remote_command', 'salt') killhook = kwargs.get('__killhook') if killhook: killhook.addCallback(lambda r: log.warning( '"%s" to "%s" aborted', self.action, self.hostname)) timeout = ('--timeout=%s' % self.timeout) if self.timeout is not None else None args = (list( reduce( lambda a, b: a + b, map( lambda a: (dict_to_kwargs(a) if type(a) is dict else ['"%s"' % str(a)]), args))) if args else []) output = yield subprocess.async_check_output(filter( None, (cmd.split(' ') + ['--no-color', '--out=json', timeout, self.hostname, self.action ] + args)), killhook=killhook) log.debug('Action "%s" to "%s" finished.', self.action, self.hostname) data = json.loads(output) if output else {} rdata = self._handle_errors(data) defer.returnValue(rdata)
def execute(self, context, *args, **kw): @db.ro_transact def check_backend(context): return context.__parent__.backend != 'kvm' if (yield check_backend(context)): return cmd = ['undefined'] try: vm_parameters = args[1] secret = get_config().getstring('deploy', 'dhcp_key', 'secret') server = get_config().getstring('deploy', 'dhcp_server', 'localhost') server_port = get_config().getstring('deploy', 'dhcp_server_port', '7911') hook_script = get_config().getstring('deploy', 'hook_script_deallocate', 'scripts/deallocate_dhcp_ip.sh') mac_addr = getattr(context, 'mac_address') cmd = [hook_script, secret, server, server_port, mac_addr, str(vm_parameters['ip_address']), vm_parameters['uuid']] yield subprocess.async_check_output(cmd) except error.ProcessTerminated: log.msg('Executing allocate_dhcp_ip.sh hook script failed: %s' % (cmd)) log.err(system='deploy-hook-kvm') raise except Exception: log.err(system='undeploy') raise
def execute(self, context, *args, **kw): @db.ro_transact def check_backend(context): return context.__parent__.backend != 'kvm' if (yield check_backend(context)): return cmd = ['undefined'] try: vm_parameters = args[1] secret = get_config().getstring('deploy', 'dhcp_key', 'secret') server = get_config().getstring('deploy', 'dhcp_server', 'localhost') server_port = get_config().getstring('deploy', 'dhcp_server_port', '7911') hook_script = get_config().getstring( 'deploy', 'hook_script_allocate', 'scripts/allocate_dhcp_ip.sh') @db.transact def ensure_compute_mac_address(context): mac_address = getattr(context, 'mac_address', None) if not mac_address: mac_address = mac_addr_kvm_generator() context.mac_address = unicode(mac_address) vm_parameters.update({'mac_address': mac_address}) return mac_address mac_address = yield ensure_compute_mac_address(context) cmd = [ hook_script, secret, server, server_port, mac_address, str(vm_parameters['ip_address']), vm_parameters['uuid'] ] yield subprocess.async_check_output(cmd) except error.ProcessTerminated: log.msg('Executing allocate_dhcp_ip.sh hook script failed: %s' % (cmd)) log.err(system='deploy-hook-kvm') raise except Exception: log.err(system='deploy-hook-kvm') raise
def execute(self, context, *args, **kw): @db.ro_transact def check_backend(context): return context.__parent__.backend != 'kvm' if (yield check_backend(context)): return cmd = ['undefined'] try: vm_parameters = args[1] secret = get_config().getstring('deploy', 'dhcp_key', 'secret') server = get_config().getstring('deploy', 'dhcp_server', 'localhost') server_port = get_config().getstring('deploy', 'dhcp_server_port', '7911') hook_script = get_config().getstring('deploy', 'hook_script_allocate', 'scripts/allocate_dhcp_ip.sh') @db.transact def ensure_compute_mac_address(context): mac_address = getattr(context, 'mac_address', None) if not mac_address: mac_address = mac_addr_kvm_generator() context.mac_address = unicode(mac_address) vm_parameters.update({'mac_address': mac_address}) return mac_address mac_address = yield ensure_compute_mac_address(context) cmd = [hook_script, secret, server, server_port, mac_address, str(vm_parameters['ip_address']), vm_parameters['uuid']] yield subprocess.async_check_output(cmd) except error.ProcessTerminated: log.msg('Executing allocate_dhcp_ip.sh hook script failed: %s' % (cmd)) log.err(system='deploy-hook-kvm') raise except Exception: log.err(system='deploy-hook-kvm') raise
def execute(self, context, *args, **kw): @db.ro_transact def check_backend(context): return context.__parent__.backend != 'kvm' if (yield check_backend(context)): return cmd = ['undefined'] try: vm_parameters = args[1] secret = get_config().getstring('deploy', 'dhcp_key', 'secret') server = get_config().getstring('deploy', 'dhcp_server', 'localhost') server_port = get_config().getstring('deploy', 'dhcp_server_port', '7911') hook_script = get_config().getstring( 'deploy', 'hook_script_deallocate', 'scripts/deallocate_dhcp_ip.sh') mac_addr = getattr(context, 'mac_address') cmd = [ hook_script, secret, server, server_port, mac_addr, str(vm_parameters['ip_address']), vm_parameters['uuid'] ] yield subprocess.async_check_output(cmd) except error.ProcessTerminated: log.msg('Executing allocate_dhcp_ip.sh hook script failed: %s' % (cmd)) log.err(system='deploy-hook-kvm') raise except Exception: log.err(system='undeploy') raise
def get_master_version(): output = yield subprocess.async_check_output(['salt-master', '--version']) version = output.strip(' \n').split(' ')[1] defer.returnValue(version)