class MuranoClient(object): """ Wrapper for Docker client """ def __init__(self): self.container = None self.dc = DockerManager() def blueprint_deployment_test(self, user, blueprint, spec='default', image='default'): """ Try to process a blueprint and return results :param blueprint: blueprint to deploy :param spec: spec to deploy :param image: image to deploy to :return: dictionary with results """ LOG.debug("Sending blueprint to docker server at %s" % self.dc._url) b_success = True msg = {} self.dc.run_container(image) msg['install'] = self.run_install(blueprint) b_success &= msg['install']['success'] msg['test'] = self.run_test(blueprint) b_success &= msg['test']['success'] msg['deploy'] = self.run_deploy(blueprint) b_success &= msg['deploy']['success'] # check execution output if b_success: msg['result'] = { 'success': True, 'result': "Blueprint %s successfully deployed\n" % blueprint } else: msg['result'] = { 'success': False, 'result': "Error deploying blueprint {}\n".format(blueprint) } LOG.error(_LW(msg)) self.dc.remove_container() return msg def run_deploy(self, user, blueprint, spec, image): """ Run blueprint deployment :param blueprint: blueprint to deploy :return msg: dictionary with results and state """ try: # launch execution self.dc.container = self.dc.run_container(image) cmd_deploy = CONF.clients_murano.cmd_deploy resp_launch = self.dc.execute_command(cmd_deploy) msg = {'success': True, 'response': resp_launch} LOG.debug(_("Launch result: %s") % resp_launch) if resp_launch is None or "FATAL" in resp_launch: msg['success'] = False except Exception as e: self.dc.remove_container(self.container) LOG.error(_LW("Blueprint deployment exception %s" % e)) raise CookbookDeploymentException(blueprint=blueprint) return msg def run_test(self, user, blueprint, image): """ Test blueprint syntax :param blueprint: blueprint to test :return msg: dictionary with results and state """ try: self.dc.container = self.dc.run_container(image) cmd_syntax = CONF.clients_murano.cmd_syntax.format(blueprint) resp_test = self.dc.execute_command(cmd_syntax) msg = {'success': True, 'response': resp_test} for line in resp_test.splitlines(): if "ERROR" in line: msg['success'] = False LOG.debug(_("Test result: %s") % resp_test) except Exception as e: self.dc.remove_container(self.container) LOG.error(_LW("Blueprint syntax exception %s" % e)) raise CookbookSyntaxException(blueprint=blueprint) return msg def run_install(self, user, blueprint, image): """Run download and install command :param blueprint: blueprint to process :return msg: operation result """ try: self.dc.container = self.dc.run_container(image) cmd_install = CONF.clients_murano.cmd_install.format(blueprint) resp_install = self.dc.execute_command(cmd_install) msg = {'success': True, 'response': resp_install} for line in resp_install.splitlines(): if "ERROR" in line: msg['success'] = False LOG.debug(_("Install result: %s") % resp_install) except Exception as e: self.dc.remove_container(self.container) LOG.error(_LW("Murano install exception: %s" % e)) raise CookbookInstallException(blueprint=blueprint) return msg
class ChefClient(object): """ Wrapper for Docker client """ def __init__(self): self.dc = DockerManager() def run_install(self, user, cookbook, image): """Run download and install command :param cookbook: cookbook to process :return msg: operation result """ # try: contname = self.dc.generate_container_name(user, cookbook, image) cbpath = os.path.join(CONF.clients_git.repo_path, self.dc.generate_user_name(user)) # set chef default cookbook path cmd_path = "echo \"cookbook_path ['{}']\nlog_level :debug \"> /etc/chef/client.rb".format( cbpath) LOG.debug("Chef path: %s" % cmd_path) self.dc.execute_command(contname, cmd_path) # set knife default cookbook path cmd_path = "echo \"cookbook_path ['{}']\nlog_level :debug \"> /etc/chef/knife.rb".format( cbpath) LOG.debug("Knife path: %s" % cmd_path) self.dc.execute_command(contname, cmd_path) # run install command currentpath = os.path.join(cbpath, cookbook) cmd_install = CONF.clients_chef.cmd_install.format(currentpath, cbpath) LOG.debug("Install command: %s" % cmd_install) resp_install = self.dc.execute_command(contname, cmd_install) msg = {'success': True, 'response': resp_install} for line in resp_install.splitlines(): if "ERROR" in line: msg['success'] = False LOG.debug("Install result: %s" % resp_install) # except Exception as e: # LOG.error(_LW("Chef install exception: %s" % e)) # raise CookbookInstallException(cookbook=cookbook) return msg def run_test(self, user, cookbook, image): """ Test cookbook syntax :param cookbook: cookbook to test :return msg: dictionary with results and state """ # try: contname = self.dc.generate_container_name(user, cookbook, image) cmd_syntax = CONF.clients_chef.cmd_syntax.format(cookbook) LOG.debug("Syntax cmd: %s" % cmd_syntax) resp_test = self.dc.execute_command(contname, cmd_syntax) msg = {'success': True, 'response': resp_test} for line in resp_test.splitlines(): if "ERROR" in line: msg['success'] = False LOG.debug("Test result: %s" % resp_test) # except Exception as e: # self.dc.remove_container(contname) # LOG.error(_LW("Cookbook syntax exception %s" % e)) # raise CookbookSyntaxException(cookbook=cookbook) return msg def run_deploy(self, user, cookbook, recipe, image): """ Run cookbook deployment :param cookbook: cookbook to deploy :return msg: dictionary with results and state """ # try: # launch execution contname = self.dc.generate_container_name(user, cookbook, image) # # run deploy cmd_deploy = CONF.clients_chef.cmd_deploy.format( cookbook, recipe.replace(".rb", "")) resp_launch = self.dc.execute_command(contname, cmd_deploy) msg = {'success': True, 'response': resp_launch} LOG.debug("Launch result: %s" % resp_launch) if resp_launch is None or "FATAL" in resp_launch: msg['success'] = False # except Exception as e: # self.dc.remove_container(self.container) # LOG.error(_LW("Cookbook deployment exception %s" % e)) # raise CookbookDeploymentException(cookbook=cookbook) return msg def cookbook_deployment_test(self, user, cookbook, recipe='default', image='default'): """ Try to process a cookbook and return results :param cookbook: cookbook to deploy :param recipe: recipe to deploy :param image: image to deploy to :return: dictionary with results """ LOG.debug("Sending cookbook to docker server at %s" % self.dc._url) b_success = True msg = {} self.dc.run_container(user, cookbook, image) # inject custom solo.json/solo.rb file json_cont = CONF.clients_chef.cmd_config % (cookbook, recipe) cmd_inject = CONF.clients_chef.cmd_inject.format(json_cont) self.dc.execute_command( self.dc.generate_container_name(user, cookbook, image), cmd_inject) msg['install'] = self.run_install(user, cookbook, image) b_success &= msg['install']['success'] msg['test'] = self.run_test(user, cookbook, image) b_success &= msg['test']['success'] msg['deploy'] = self.run_deploy(user, cookbook, image) b_success &= msg['deploy']['success'] # check execution output if b_success: msg['result'] = { 'success': True, 'result': "Cookbook %s successfully deployed\n" % cookbook } else: msg['result'] = { 'success': False, 'result': "Error deploying cookbook {}\n".format(cookbook) } LOG.error(msg) self.dc.remove_container(image) return msg
class PuppetClient(object): """ Wrapper for Docker client """ def __init__(self): self.container = None self.dc = DockerManager() def cookbook_deployment_test(self, user, cookbook, recipe='default', image='default'): """ Try to process a cookbook and return results :param cookbook: cookbook to deploy :param recipe: recipe to deploy :param image: image to deploy to :return: dictionary with results """ LOG.debug("Sending cookbook to docker server at %s" % self.dc._url) b_success = True msg = {} self.dc.run_container(image) # inject custom solo.json/solo.rb file json_cont = CONF.clients_puppet.cmd_config % (cookbook, recipe) cmd_inject = CONF.clients_puppet.cmd_inject.format(json_cont) self.dc.execute_command(cmd_inject) msg['install'] = self.run_install(cookbook) b_success &= msg['install']['success'] msg['test'] = self.run_test(cookbook) b_success &= msg['test']['success'] msg['deploy'] = self.run_deploy(cookbook) b_success &= msg['deploy']['success'] # check execution output if b_success: msg['result'] = { 'success': True, 'result': "Cookbook %s successfully deployed\n" % cookbook } else: msg['result'] = { 'success': False, 'result': "Error deploying cookbook {}\n".format(cookbook) } LOG.error(_LW(msg)) self.dc.remove_container() return msg def run_install(self, user, cookbook, image): """Run download and install command :param cookbook: cookbook to process :return msg: operation result """ try: self.dc.container = self.dc.run_container(image) cmd_install = CONF.clients_puppet.cmd_install.format(cookbook) resp_install = self.dc.execute_command(cmd_install) msg = {'success': True, 'response': resp_install} for line in resp_install.splitlines(): if "ERROR" in line: msg['success'] = False LOG.debug(_("Install result: %s") % resp_install) except Exception as e: self.dc.remove_container(self.container) LOG.error(_LW("Chef install exception: %s" % e)) raise CookbookInstallException(cookbook=cookbook) return msg def run_test(self, user, cookbook, image): """ Test cookbook syntax :param cookbook: cookbook to test :return msg: dictionary with results and state """ try: self.dc.container = self.dc.run_container(image) cmd_syntax = CONF.clients_puppet.cmd_syntax.format(cookbook) resp_test = self.dc.execute_command(cmd_syntax) msg = {'success': True, 'response': resp_test} for line in resp_test.splitlines(): if "ERROR" in line: msg['success'] = False LOG.debug(_("Test result: %s") % resp_test) except Exception as e: self.dc.remove_container(self.container) LOG.error(_LW("Cookbook syntax exception %s" % e)) raise CookbookSyntaxException(cookbook=cookbook) return msg def run_deploy(self, user, cookbook, recipe, image): """ Run cookbook deployment :param cookbook: cookbook to deploy :return msg: dictionary with results and state """ try: # launch execution self.dc.container = self.dc.run_container(image) cmd_deploy = CONF.clients_puppet.cmd_deploy resp_launch = self.dc.execute_command(cmd_deploy) msg = {'success': True, 'response': resp_launch} LOG.debug(_("Launch result: %s") % resp_launch) if resp_launch is None or "FATAL" in resp_launch: msg['success'] = False except Exception as e: self.dc.remove_container(self.container) LOG.error(_LW("Cookbook deployment exception %s" % e)) raise CookbookDeploymentException(cookbook=cookbook) return msg
class MuranoClient(object): """ Wrapper for Docker client """ def __init__(self): self.container = None self.dc = DockerManager() def blueprint_deployment_test(self, user, blueprint, spec='default', image='default'): """ Try to process a blueprint and return results :param blueprint: blueprint to deploy :param spec: spec to deploy :param image: image to deploy to :return: dictionary with results """ LOG.debug("Sending blueprint to docker server at %s" % self.dc._url) b_success = True msg = {} self.dc.run_container(image) msg['install'] = self.run_install(blueprint) b_success &= msg['install']['success'] msg['test'] = self.run_test(blueprint) b_success &= msg['test']['success'] msg['deploy'] = self.run_deploy(blueprint) b_success &= msg['deploy']['success'] # check execution output if b_success: msg['result'] = { 'success': True, 'result': "Blueprint %s successfully deployed\n" % blueprint } else: msg['result'] = { 'success': False, 'result': "Error deploying blueprint {}\n".format(blueprint) } LOG.error(_LW(msg)) self.dc.remove_container() return msg def run_deploy(self, user, blueprint, spec, image): """ Run blueprint deployment :param blueprint: blueprint to deploy :return msg: dictionary with results and state """ try: # launch execution self.dc.container = self.dc.run_container(image) cmd_deploy = CONF.clients_murano.cmd_deploy resp_launch = self.dc.execute_command(cmd_deploy) msg = { 'success': True, 'response': resp_launch } LOG.debug(_("Launch result: %s") % resp_launch) if resp_launch is None or "FATAL" in resp_launch: msg['success'] = False except Exception as e: self.dc.remove_container(self.container) LOG.error(_LW("Blueprint deployment exception %s" % e)) raise CookbookDeploymentException(blueprint=blueprint) return msg def run_test(self, user, blueprint, image): """ Test blueprint syntax :param blueprint: blueprint to test :return msg: dictionary with results and state """ try: self.dc.container = self.dc.run_container(image) cmd_syntax = CONF.clients_murano.cmd_syntax.format(blueprint) resp_test = self.dc.execute_command(cmd_syntax) msg = { 'success': True, 'response': resp_test } for line in resp_test.splitlines(): if "ERROR" in line: msg['success'] = False LOG.debug(_("Test result: %s") % resp_test) except Exception as e: self.dc.remove_container(self.container) LOG.error(_LW("Blueprint syntax exception %s" % e)) raise CookbookSyntaxException(blueprint=blueprint) return msg def run_install(self, user, blueprint, image): """Run download and install command :param blueprint: blueprint to process :return msg: operation result """ try: self.dc.container = self.dc.run_container(image) cmd_install = CONF.clients_murano.cmd_install.format(blueprint) resp_install = self.dc.execute_command(cmd_install) msg = { 'success': True, 'response': resp_install } for line in resp_install.splitlines(): if "ERROR" in line: msg['success'] = False LOG.debug(_("Install result: %s") % resp_install) except Exception as e: self.dc.remove_container(self.container) LOG.error(_LW("Murano install exception: %s" % e)) raise CookbookInstallException(blueprint=blueprint) return msg
class ChefClient(object): """ Wrapper for Docker client """ def __init__(self): self.dc = DockerManager() def run_install(self, user, cookbook, image): """Run download and install command :param cookbook: cookbook to process :return msg: operation result """ # try: contname = self.dc.generate_container_name(user, cookbook, image) cbpath = os.path.join(CONF.clients_git.repo_path, self.dc.generate_user_name(user)) # set chef default cookbook path cmd_path = "echo \"cookbook_path ['{}']\nlog_level :debug \"> /etc/chef/client.rb".format(cbpath) LOG.debug("Chef path: %s" % cmd_path) self.dc.execute_command(contname, cmd_path) # set knife default cookbook path cmd_path = "echo \"cookbook_path ['{}']\nlog_level :debug \"> /etc/chef/knife.rb".format(cbpath) LOG.debug("Knife path: %s" % cmd_path) self.dc.execute_command(contname, cmd_path) # run install command currentpath = os.path.join(cbpath, cookbook) cmd_install = CONF.clients_chef.cmd_install.format(currentpath, cbpath) LOG.debug("Install command: %s" % cmd_install) resp_install = self.dc.execute_command(contname, cmd_install) msg = { 'success': True, 'response': resp_install } for line in resp_install.splitlines(): if "ERROR" in line: msg['success'] = False LOG.debug("Install result: %s" % resp_install) # except Exception as e: # LOG.error(_LW("Chef install exception: %s" % e)) # raise CookbookInstallException(cookbook=cookbook) return msg def run_test(self, user, cookbook, image): """ Test cookbook syntax :param cookbook: cookbook to test :return msg: dictionary with results and state """ # try: contname = self.dc.generate_container_name(user, cookbook, image) cmd_syntax = CONF.clients_chef.cmd_syntax.format(cookbook) LOG.debug("Syntax cmd: %s" % cmd_syntax) resp_test = self.dc.execute_command(contname, cmd_syntax) msg = { 'success': True, 'response': resp_test } for line in resp_test.splitlines(): if "ERROR" in line: msg['success'] = False LOG.debug("Test result: %s" % resp_test) # except Exception as e: # self.dc.remove_container(contname) # LOG.error(_LW("Cookbook syntax exception %s" % e)) # raise CookbookSyntaxException(cookbook=cookbook) return msg def run_deploy(self, user, cookbook, recipe, image): """ Run cookbook deployment :param cookbook: cookbook to deploy :return msg: dictionary with results and state """ # try: # launch execution contname = self.dc.generate_container_name(user, cookbook, image) # # run deploy cmd_deploy = CONF.clients_chef.cmd_deploy.format(cookbook, recipe.replace(".rb", "")) resp_launch = self.dc.execute_command(contname, cmd_deploy) msg = { 'success': True, 'response': resp_launch } LOG.debug("Launch result: %s" % resp_launch) if resp_launch is None or "FATAL" in resp_launch: msg['success'] = False # except Exception as e: # self.dc.remove_container(self.container) # LOG.error(_LW("Cookbook deployment exception %s" % e)) # raise CookbookDeploymentException(cookbook=cookbook) return msg def cookbook_deployment_test(self, user, cookbook, recipe='default', image='default'): """ Try to process a cookbook and return results :param cookbook: cookbook to deploy :param recipe: recipe to deploy :param image: image to deploy to :return: dictionary with results """ LOG.debug("Sending cookbook to docker server at %s" % self.dc._url) b_success = True msg = {} self.dc.run_container(user, cookbook, image) # inject custom solo.json/solo.rb file json_cont = CONF.clients_chef.cmd_config % (cookbook, recipe) cmd_inject = CONF.clients_chef.cmd_inject.format(json_cont) self.dc.execute_command(self.dc.generate_container_name(user, cookbook, image), cmd_inject) msg['install'] = self.run_install(user, cookbook, image) b_success &= msg['install']['success'] msg['test'] = self.run_test(user, cookbook, image) b_success &= msg['test']['success'] msg['deploy'] = self.run_deploy(user, cookbook, image) b_success &= msg['deploy']['success'] # check execution output if b_success: msg['result'] = { 'success': True, 'result': "Cookbook %s successfully deployed\n" % cookbook } else: msg['result'] = { 'success': False, 'result': "Error deploying cookbook {}\n".format(cookbook) } LOG.error(msg) self.dc.remove_container(image) return msg
class PuppetClient(object): """ Wrapper for Docker client """ def __init__(self): self.container = None self.dc = DockerManager() def cookbook_deployment_test(self, user, cookbook, recipe='default', image='default'): """ Try to process a cookbook and return results :param cookbook: cookbook to deploy :param recipe: recipe to deploy :param image: image to deploy to :return: dictionary with results """ LOG.debug("Sending cookbook to docker server at %s" % self.dc._url) b_success = True msg = {} self.dc.run_container(image) # inject custom solo.json/solo.rb file json_cont = CONF.clients_puppet.cmd_config % (cookbook, recipe) cmd_inject = CONF.clients_puppet.cmd_inject.format(json_cont) self.dc.execute_command(cmd_inject) msg['install'] = self.run_install(cookbook) b_success &= msg['install']['success'] msg['test'] = self.run_test(cookbook) b_success &= msg['test']['success'] msg['deploy'] = self.run_deploy(cookbook) b_success &= msg['deploy']['success'] # check execution output if b_success: msg['result'] = { 'success': True, 'result': "Cookbook %s successfully deployed\n" % cookbook } else: msg['result'] = { 'success': False, 'result': "Error deploying cookbook {}\n".format(cookbook) } LOG.error(_LW(msg)) self.dc.remove_container() return msg def run_install(self, user, cookbook, image): """Run download and install command :param cookbook: cookbook to process :return msg: operation result """ try: self.dc.container = self.dc.run_container(image) cmd_install = CONF.clients_puppet.cmd_install.format(cookbook) resp_install = self.dc.execute_command(cmd_install) msg = { 'success': True, 'response': resp_install } for line in resp_install.splitlines(): if "ERROR" in line: msg['success'] = False LOG.debug(_("Install result: %s") % resp_install) except Exception as e: self.dc.remove_container(self.container) LOG.error(_LW("Chef install exception: %s" % e)) raise CookbookInstallException(cookbook=cookbook) return msg def run_test(self, user, cookbook, image): """ Test cookbook syntax :param cookbook: cookbook to test :return msg: dictionary with results and state """ try: self.dc.container = self.dc.run_container(image) cmd_syntax = CONF.clients_puppet.cmd_syntax.format(cookbook) resp_test = self.dc.execute_command(cmd_syntax) msg = { 'success': True, 'response': resp_test } for line in resp_test.splitlines(): if "ERROR" in line: msg['success'] = False LOG.debug(_("Test result: %s") % resp_test) except Exception as e: self.dc.remove_container(self.container) LOG.error(_LW("Cookbook syntax exception %s" % e)) raise CookbookSyntaxException(cookbook=cookbook) return msg def run_deploy(self, user, cookbook, recipe, image): """ Run cookbook deployment :param cookbook: cookbook to deploy :return msg: dictionary with results and state """ try: # launch execution self.dc.container = self.dc.run_container(image) cmd_deploy = CONF.clients_puppet.cmd_deploy resp_launch = self.dc.execute_command(cmd_deploy) msg = { 'success': True, 'response': resp_launch } LOG.debug(_("Launch result: %s") % resp_launch) if resp_launch is None or "FATAL" in resp_launch: msg['success'] = False except Exception as e: self.dc.remove_container(self.container) LOG.error(_LW("Cookbook deployment exception %s" % e)) raise CookbookDeploymentException(cookbook=cookbook) return msg