Пример #1
0
def build(name="autotest", template="ubuntu-default", branch="master",
          template_path=None, config="pubcloud-neutron.yaml",
          dry=False, log=None, log_level="INFO", provisioner="rackspace",
          secret_path=None):
    """
    Build an OpenStack Cluster
    """
    util.set_log_level(log_level)

    # Provision deployment
    _load_config(config, secret_path)
    cprovisioner = get_provisioner(provisioner)

    util.logger.info("Building deployment object for {0}".format(name))
    deployment = MonsterChefDeployment.fromfile(
        name, template, branch, cprovisioner, template_path)

    if dry:
        try:
            deployment.update_environment()
        except Exception:
            error = traceback.print_exc()
            util.logger.error(error)
            raise

    else:
        util.logger.info(deployment)
        try:
            deployment.build()
        except Exception:
            error = traceback.print_exc()
            util.logger.error(error)
            raise

    util.logger.info(deployment)
Пример #2
0
 def from_chef_node(cls, node, product=None, environment=None,
                    deployment=None, provisioner=None, branch=None):
     """
     Restores node from chef node
     """
     remote_api = None
     if deployment:
         remote_api = deployment.environment.remote_api
     if remote_api:
         rnode = ChefNode(node.name, remote_api)
         if rnode.exists:
             node = rnode
     ipaddress = node['ipaddress']
     user = node['current_user']
     default_pass = util.config['secrets']['default_pass']
     password = node.get('password', default_pass)
     name = node.name
     archive = node.get('archive', {})
     status = archive.get('status', "provisioning")
     if not provisioner:
         provisioner_name = archive.get('provisioner', "razor2")
         provisioner = get_provisioner(provisioner_name)
     run_list = node.run_list
     crnode = cls(ipaddress, user, password, product, environment,
                  deployment, name, provisioner, branch,
                  status=status, run_list=run_list)
     crnode.add_features(archive.get('features', []))
     return crnode
Пример #3
0
    def from_chef_environment(cls, environment):
        """
        Rebuilds a Deployment given a chef environment
        :param environment: name of environment
        :type environment: string
        :rtype: Chef
        """

        local_api = autoconfigure()
        env = ChefEnvironment(environment, api=local_api)
        override = env.override_attributes
        default = env.default_attributes
        chef_auth = override.get('remote_chef', None)
        remote_api = None
        if chef_auth and chef_auth["key"]:
            remote_api = ChefServer._remote_chef_api(chef_auth)
            renv = ChefEnvironment(environment, api=remote_api)
            override = renv.override_attributes
            default = renv.default_attributes
        environment = MonsterChefEnvironment(env.name,
                                             local_api,
                                             description=env.name,
                                             default=default,
                                             override=override,
                                             remote_api=remote_api)

        name = env.name
        deployment_args = override.get('deployment', {})
        features = deployment_args.get('features', {})
        os_name = deployment_args.get('os_name', None)
        branch = deployment_args.get('branch', None)
        status = deployment_args.get('status', "provisioning")
        product = deployment_args.get('product', None)
        provisioner_name = deployment_args.get('provisioner', "razor")
        provisioner = get_provisioner(provisioner_name)

        deployment = cls.deployment_config(features,
                                           name,
                                           os_name,
                                           branch,
                                           environment,
                                           provisioner,
                                           status,
                                           product=product)

        nodes = deployment_args.get('nodes', [])
        for node in (ChefNode(n, local_api) for n in nodes):
            if not node.exists:
                util.logger.error("Non existant chef node:{0}".format(
                    node.name))
                continue
            cnode = MonsterChefNode.from_chef_node(node,
                                                   deployment_args['os_name'],
                                                   product, environment,
                                                   deployment, provisioner,
                                                   deployment_args['branch'])
            deployment.nodes.append(cnode)
        return deployment
Пример #4
0
def build(name="build", template="precise-default", branch="master",
          config=None, destroy=False, dry=False, log=None, log_level="INFO",
          provisioner="razor", test=False, secret_path=None):
    """
    Builds an OpenStack Cluster
    """
    _set_log(log, log_level)

    # Magic to get the template location from the branch
    if branch == "master":
        template_file = "default"
    else:
        temp_branch = branch.lstrip('v')
        if "rc" in temp_branch:
            template_file = temp_branch.rstrip("rc").replace('.', '_')
        else:
            template_file = temp_branch.replace('.', '_')

    # provisiong deployment
    util.config = Config(config, secret_path=secret_path)
    cprovisioner = get_provisioner(provisioner)
    deployment = MonsterChefDeployment.fromfile(
        name, template, branch, cprovisioner, template_file)
    if dry:
        # build environment
        try:
            deployment.update_environment()
        except Exception:
            util.logger.error(traceback.print_exc())
            if destroy:
                deployment.destroy()
            sys.exit(1)

    else:
        util.logger.info(deployment)
        # build deployment
        try:
            deployment.build()
        except Exception:
            util.logger.error(traceback.print_exc())
            if destroy:
                deployment.destroy()
            sys.exit(1)

    util.logger.info(deployment)

    if test:
        try:
            TempestNeutron(deployment).test()
        except Exception:
            util.logger.error(traceback.print_exc())
            if destroy:
                deployment.destroy()
            sys.exit(1)

    if destroy:
        deployment.destroy()
Пример #5
0
    def from_chef_environment(cls, environment):
        """
        Rebuilds a Deployment given a chef environment
        :param environment: name of environment
        :type environment: string
        :rtype: Chef
        """

        local_api = autoconfigure()
        environ = ChefEnvironment(environment, api=local_api)
        if not environ.exists:
            util.logger.error("The specified environment, {0}, does not"
                              "exist.".format(environment))
            exit(1)
        override = environ.override_attributes
        default = environ.default_attributes
        chef_auth = override.get('remote_chef', None)
        remote_api = None
        if chef_auth and chef_auth["key"]:
            remote_api = ChefServer._remote_chef_api(chef_auth)
            renv = ChefEnvironment(environment, api=remote_api)
            override = renv.override_attributes
            default = renv.default_attributes
        environment = MonsterChefEnvironment(
            environ.name, local_api, description=environ.name,
            default=default, override=override, remote_api=remote_api)

        name = environ.name
        deployment_args = override.get('deployment', {})
        features = deployment_args.get('features', {})
        os_name = deployment_args.get('os_name', None)
        branch = deployment_args.get('branch', None)
        status = deployment_args.get('status', "provisioning")
        product = deployment_args.get('product', None)
        provisioner_name = deployment_args.get('provisioner', "razor2")
        provisioner = get_provisioner(provisioner_name)

        deployment = cls.deployment_config(features, name, os_name, branch,
                                           environment, provisioner, status,
                                           product=product)

        nodes = deployment_args.get('nodes', [])
        for node in (ChefNode(n, local_api) for n in nodes):
            if not node.exists:
                util.logger.error("Non existant chef node:{0}".
                                  format(node.name))
                continue
            cnode = MonsterChefNode.from_chef_node(node, product, environment,
                                                   deployment, provisioner,
                                                   deployment_args['branch'])
            deployment.nodes.append(cnode)
        return deployment
Пример #6
0
 def provisioner(self):
     return get_provisioner(self.provisioner_name)