Ejemplo n.º 1
0
    def _create_overcloudrc(self, stack, parsed_args):
        overcloud_endpoint = utils.get_overcloud_endpoint(stack)
        overcloud_ip = six.moves.urllib.parse.urlparse(
            overcloud_endpoint).hostname

        rc_params = {
            'NOVA_VERSION': '1.1',
            'COMPUTE_API_VERSION': '1.1',
            'OS_USERNAME': '******',
            'OS_TENANT_NAME': 'admin',
            'OS_NO_CACHE': 'True',
            'OS_CLOUDNAME': stack.stack_name,
            'no_proxy': "%(no_proxy)s,%(overcloud_ip)s" % {
                'no_proxy': parsed_args.no_proxy,
                'overcloud_ip': overcloud_ip,
            }
        }
        rc_params.update({
            'OS_PASSWORD':
            utils.get_password('OVERCLOUD_ADMIN_PASSWORD'),
            'OS_AUTH_URL':
            utils.get_overcloud_endpoint(stack),
        })
        with open('%src' % stack.stack_name, 'w') as f:
            for key, value in rc_params.items():
                f.write("export %(key)s=%(value)s\n" % {
                    'key': key,
                    'value': value
                })
    def _create_overcloudrc(self, stack, parsed_args):
        overcloud_endpoint = utils.get_overcloud_endpoint(stack)
        overcloud_ip = six.moves.urllib.parse.urlparse(
            overcloud_endpoint).hostname

        rc_params = {
            'NOVA_VERSION': '1.1',
            'COMPUTE_API_VERSION': '1.1',
            'OS_USERNAME': '******',
            'OS_TENANT_NAME': 'admin',
            'OS_NO_CACHE': 'True',
            'OS_CLOUDNAME': stack.stack_name,
            'no_proxy': "%(no_proxy)s,%(overcloud_ip)s" % {
                'no_proxy': parsed_args.no_proxy,
                'overcloud_ip': overcloud_ip,
            }
        }
        rc_params.update({
            'OS_PASSWORD': utils.get_password('OVERCLOUD_ADMIN_PASSWORD'),
            'OS_AUTH_URL': utils.get_overcloud_endpoint(stack),
        })
        with open('%src' % stack.stack_name, 'w') as f:
            for key, value in rc_params.items():
                f.write("export %(key)s=%(value)s\n" %
                        {'key': key, 'value': value})
    def _deploy_postconfig(self, stack, parsed_args):
        self.log.debug("_deploy_postconfig(%s)" % parsed_args)

        overcloud_endpoint = utils.get_overcloud_endpoint(stack)
        # NOTE(jaosorior): The overcloud endpoint can contain an IP address or
        # an FQDN depending on how what it's configured to output in the
        # tripleo-heat-templates. Such a configuration can be done by
        # overriding the EndpointMap through parameter_defaults.
        overcloud_ip_or_fqdn = six.moves.urllib.parse.urlparse(
            overcloud_endpoint).hostname

        keystone_admin_ip = utils.get_endpoint('KeystoneAdmin', stack)
        no_proxy = os.environ.get('no_proxy', overcloud_ip_or_fqdn)
        no_proxy_list = map(utils.bracket_ipv6,
                            [no_proxy, overcloud_ip_or_fqdn,
                             keystone_admin_ip])
        os.environ['no_proxy'] = ','.join(
            [x for x in no_proxy_list if x is not None])

        utils.remove_known_hosts(overcloud_ip_or_fqdn)

        if not self._endpoints_managed(stack):
            self._keystone_init(overcloud_endpoint, overcloud_ip_or_fqdn,
                                parsed_args, stack)
        else:
            self.log.debug("Keystone endpoints and services are managed by "
                           "puppet. Skipping post-config.")
    def _deploy_postconfig(self, stack, parsed_args):
        self.log.debug("_deploy_postconfig(%s)" % parsed_args)

        overcloud_endpoint = utils.get_overcloud_endpoint(stack)
        # NOTE(jaosorior): The overcloud endpoint can contain an IP address or
        # an FQDN depending on how what it's configured to output in the
        # tripleo-heat-templates. Such a configuration can be done by
        # overriding the EndpointMap through parameter_defaults.
        overcloud_ip_or_fqdn = six.moves.urllib.parse.urlparse(
            overcloud_endpoint).hostname

        no_proxy = [os.environ.get('no_proxy'), overcloud_ip_or_fqdn]
        os.environ['no_proxy'] = ','.join(
            [x for x in no_proxy if x is not None])

        utils.remove_known_hosts(overcloud_ip_or_fqdn)

        self._keystone_init(overcloud_endpoint, overcloud_ip_or_fqdn,
                            parsed_args, stack)
    def _deploy_postconfig(self, stack, parsed_args):
        self.log.debug("_deploy_postconfig(%s)" % parsed_args)

        overcloud_endpoint = utils.get_overcloud_endpoint(stack)
        # NOTE(jaosorior): The overcloud endpoint can contain an IP address or
        # an FQDN depending on how what it's configured to output in the
        # tripleo-heat-templates. Such a configuration can be done by
        # overriding the EndpointMap through parameter_defaults.
        overcloud_ip_or_fqdn = six.moves.urllib.parse.urlparse(
            overcloud_endpoint).hostname

        no_proxy = [os.environ.get('no_proxy'), overcloud_ip_or_fqdn]
        os.environ['no_proxy'] = ','.join(
            [x for x in no_proxy if x is not None])

        utils.remove_known_hosts(overcloud_ip_or_fqdn)

        self._keystone_init(overcloud_endpoint, overcloud_ip_or_fqdn,
                            parsed_args, stack)
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)" % parsed_args)

        self._validate_args(parsed_args)

        errors, warnings = self._predeploy_verify_capabilities(parsed_args)
        if errors > 0:
            self.log.error(
                "Configuration has %d errors, fix them before proceeding. "
                "Ignoring these errors is likely to lead to a failed deploy.",
                errors)
            if parsed_args.validation_warnings_fatal or \
                    parsed_args.validation_errors_fatal:
                return
        if warnings > 0:
            self.log.error(
                "Configuration has %d warnings, fix them before proceeding. ",
                warnings)
            if parsed_args.validation_warnings_fatal:
                return
        else:
            self.log.info("SUCCESS: No warnings or errors in deploy "
                          "configuration, proceeding.")

        clients = self.app.client_manager
        orchestration_client = clients.tripleoclient.orchestration

        stack = utils.get_stack(orchestration_client, parsed_args.stack)
        stack_create = stack is None
        if stack_create:
            self.log.info("No stack found, will be doing a stack create")
        else:
            self.log.info("Stack found, will be doing a stack update")

        try:
            self._pre_heat_deploy()

            if parsed_args.rhel_reg:
                if parsed_args.reg_method == 'satellite':
                    sat_required_args = (parsed_args.reg_org
                                         and parsed_args.reg_sat_url
                                         and parsed_args.reg_activation_key)
                    if not sat_required_args:
                        raise exceptions.DeploymentError(
                            "ERROR: In order to use satellite registration, "
                            "you must specify --reg-org, --reg-sat-url, and "
                            "--reg-activation-key.")
                else:
                    portal_required_args = (parsed_args.reg_org
                                            and parsed_args.reg_activation_key)
                    if not portal_required_args:
                        raise exceptions.DeploymentError(
                            "ERROR: In order to use portal registration, you "
                            "must specify --reg-org, and "
                            "--reg-activation-key.")

            if parsed_args.dry_run:
                print("Validation Finished")
                return True

            self._deploy_tripleo_heat_templates(stack, parsed_args)

            # Get a new copy of the stack after stack update/create. If it was
            # a create then the previous stack object would be None.
            stack = utils.get_stack(orchestration_client, parsed_args.stack)

            utils.create_overcloudrc(stack, parsed_args.no_proxy)
            utils.create_tempest_deployer_input()

            if stack_create:
                self._deploy_postconfig(stack, parsed_args)

            overcloud_endpoint = utils.get_overcloud_endpoint(stack)
            print("Overcloud Endpoint: {0}".format(overcloud_endpoint))
            print("Overcloud Deployed")
            return True
        except exceptions.DeploymentError as err:
            print("Deployment failed: ", err, file=sys.stderr)
            return False
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)" % parsed_args)

        self._validate_args(parsed_args)

        errors, warnings = self._predeploy_verify_capabilities(parsed_args)
        if errors > 0:
            self.log.error(
                "Configuration has %d errors, fix them before proceeding. "
                "Ignoring these errors is likely to lead to a failed deploy.",
                errors)
            if parsed_args.validation_warnings_fatal or \
                    parsed_args.validation_errors_fatal:
                return
        if warnings > 0:
            self.log.error(
                "Configuration has %d warnings, fix them before proceeding. ",
                warnings)
            if parsed_args.validation_warnings_fatal:
                return
        else:
            self.log.info("SUCCESS: No warnings or errors in deploy "
                          "configuration, proceeding.")

        clients = self.app.client_manager
        orchestration_client = clients.tripleoclient.orchestration()

        stack = utils.get_stack(orchestration_client, parsed_args.stack)
        stack_create = stack is None
        if stack_create:
            self.log.info("No stack found, will be doing a stack create")
        else:
            self.log.info("Stack found, will be doing a stack update")

        try:
            self._pre_heat_deploy()

            if parsed_args.rhel_reg:
                if parsed_args.reg_method == 'satellite':
                    sat_required_args = (parsed_args.reg_org and
                                         parsed_args.reg_sat_url and
                                         parsed_args.reg_activation_key)
                    if not sat_required_args:
                        raise exceptions.DeploymentError(
                            "ERROR: In order to use satellite registration, "
                            "you must specify --reg-org, --reg-sat-url, and "
                            "--reg-activation-key.")
                else:
                    portal_required_args = (parsed_args.reg_org and
                                            parsed_args.reg_activation_key)
                    if not portal_required_args:
                        raise exceptions.DeploymentError(
                            "ERROR: In order to use portal registration, you "
                            "must specify --reg-org, and "
                            "--reg-activation-key.")

            self._deploy_tripleo_heat_templates(stack, parsed_args)

            # Get a new copy of the stack after stack update/create. If it was
            # a create then the previous stack object would be None.
            stack = utils.get_stack(orchestration_client, parsed_args.stack)

            self._create_overcloudrc(stack, parsed_args)
            self._create_tempest_deployer_input()

            if stack_create:
                self._deploy_postconfig(stack, parsed_args)

            overcloud_endpoint = utils.get_overcloud_endpoint(stack)
            print("Overcloud Endpoint: {0}".format(overcloud_endpoint))
            print("Overcloud Deployed")
            return True
        except exceptions.DeploymentError as err:
            print("Deployment failed: ", err, file=sys.stderr)
            return False
    def _deploy_postconfig(self, stack, parsed_args):
        self.log.debug("_deploy_postconfig(%s)" % parsed_args)

        overcloud_endpoint = utils.get_overcloud_endpoint(stack)
        overcloud_ip = six.moves.urllib.parse.urlparse(
            overcloud_endpoint).hostname

        no_proxy = [os.environ.get('no_proxy'), overcloud_ip]
        os.environ['no_proxy'] = ','.join(
            [x for x in no_proxy if x is not None])

        service_ips = utils.get_service_ips(stack)

        utils.remove_known_hosts(overcloud_ip)

        keystone_ip = service_ips.get('KeystoneAdminVip')
        if not keystone_ip:
            keystone_ip = overcloud_ip

        keystone.initialize(
            keystone_ip,
            utils.get_password('OVERCLOUD_ADMIN_TOKEN'),
            '*****@*****.**',
            utils.get_password('OVERCLOUD_ADMIN_PASSWORD'),
            public=overcloud_ip,
            user=parsed_args.overcloud_ssh_user)

        # NOTE(bcrochet): Bad hack. Remove the ssl_port info from the
        # os_cloud_config.SERVICES dictionary
        for service_name, data in keystone.SERVICES.iteritems():
            data.pop('ssl_port', None)

        services = {}
        for service, data in six.iteritems(utils.SERVICE_LIST):
            service_data = data.copy()
            service_data.pop('password_field', None)
            password_field = data.get('password_field')
            if password_field:
                service_data['password'] = utils.get_password(password_field)

            service_name = re.sub('v[0-9]+', '',
                                  service.capitalize() + 'InternalVip')
            internal_vip = service_ips.get(service_name)
            if internal_vip:
                service_data['internal_host'] = internal_vip
            services.update({service: service_data})

        keystone_client = clients.get_keystone_client(
            'admin',
            utils.get_password('OVERCLOUD_ADMIN_PASSWORD'),
            'admin',
            overcloud_endpoint)
        keystone.setup_endpoints(
            services,
            client=keystone_client,
            os_auth_url=overcloud_endpoint,
            public_host=overcloud_ip)

        compute_client = clients.get_nova_bm_client(
            'admin',
            utils.get_password('OVERCLOUD_ADMIN_PASSWORD'),
            'admin',
            overcloud_endpoint)
        compute_client.flavors.create('m1.demo', 512, 1, 10, 'auto')
    def _deploy_postconfig(self, stack, parsed_args):
        self.log.debug("_deploy_postconfig(%s)" % parsed_args)

        overcloud_endpoint = utils.get_overcloud_endpoint(stack)
        overcloud_ip = six.moves.urllib.parse.urlparse(
            overcloud_endpoint).hostname

        no_proxy = [os.environ.get('no_proxy'), overcloud_ip]
        os.environ['no_proxy'] = ','.join(
            [x for x in no_proxy if x is not None])

        service_ips = utils.get_service_ips(stack)

        utils.remove_known_hosts(overcloud_ip)

        keystone_ip = service_ips.get('KeystoneAdminVip')
        if not keystone_ip:
            keystone_ip = overcloud_ip

        # Note (spredzy): This was deprecated at the begining of
        # the Mitaka cycle. Should be good to remove for the
        # next N cycle.
        keystone.initialize(
            keystone_ip,
            utils.get_password('OVERCLOUD_ADMIN_TOKEN'),
            '*****@*****.**',
            utils.get_password('OVERCLOUD_ADMIN_PASSWORD'),
            public=overcloud_ip,
            user=parsed_args.overcloud_ssh_user)

        # NOTE(bcrochet): Bad hack. Remove the ssl_port info from the
        # os_cloud_config.SERVICES dictionary
        for service_name, data in keystone.SERVICES.iteritems():
            data.pop('ssl_port', None)

        services = {}
        for service, data in six.iteritems(constants.SERVICE_LIST):
            service_data = data.copy()
            service_data.pop('password_field', None)
            password_field = data.get('password_field')
            if password_field:
                service_data['password'] = utils.get_password(password_field)

            service_name = re.sub('v[0-9]+', '',
                                  service.capitalize() + 'InternalVip')
            internal_vip = service_ips.get(service_name)
            if internal_vip:
                service_data['internal_host'] = internal_vip
            services.update({service: service_data})

        # Note (spredzy): This was deprecated at the begining of
        # the Mitaka cycle. Should be good to remove for the
        # next N cycle.
        try:
            keystone_client = clients.get_keystone_client(
                'admin',
                utils.get_password('OVERCLOUD_ADMIN_PASSWORD'),
                'admin',
                overcloud_endpoint)
            keystone.setup_endpoints(
                services,
                client=keystone_client,
                os_auth_url=overcloud_endpoint,
                public_host=overcloud_ip)
        except kscexc.Conflict:
            pass
        else:
            self.log.warning("Setting up keystone endpoints via "
                             "os-cloud-config. This behavior is "
                             "deprecated and will be removed in "
                             "a future release.  Please update "
                             "your heat templates to a version "
                             "that does Keystone initialization "
                             "via Puppet.")

        compute_client = clients.get_nova_bm_client(
            'admin',
            utils.get_password('OVERCLOUD_ADMIN_PASSWORD'),
            'admin',
            overcloud_endpoint)
        compute_client.flavors.create('m1.demo', 512, 1, 10, 'auto')
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)" % parsed_args)
        self._setup_clients(parsed_args)

        # Swiftclient logs things like 404s at error level, which is a problem
        # because we use EAFP to check for the existence of files.  Turn off
        # most swiftclient logging to avoid cluttering up our output with
        # pointless tracebacks.
        sc_logger = logging.getLogger("swiftclient")
        sc_logger.setLevel(logging.CRITICAL)

        self._validate_args(parsed_args)

        stack = utils.get_stack(self.orchestration_client, parsed_args.stack)

        if stack and stack.stack_status == 'IN_PROGRESS':
            raise exceptions.StackInProgress(
                "Unable to deploy as the stack '{}' status is '{}'".format(
                    stack.stack_name, stack.stack_status))

        parameters = self._update_parameters(parsed_args, stack)

        if not parsed_args.disable_validations:
            errors, warnings = self._predeploy_verify_capabilities(
                stack, parameters, parsed_args)
            if errors > 0:
                self.log.error(
                    "Configuration has %d errors, fix them before "
                    "proceeding. Ignoring these errors is likely to lead to "
                    "a failed deploy.", errors)
                if parsed_args.validation_warnings_fatal or \
                        parsed_args.validation_errors_fatal:
                    raise exceptions.InvalidConfiguration()
            if warnings > 0:
                self.log.error(
                    "Configuration has %d warnings, fix them before "
                    "proceeding.", warnings)
                if parsed_args.validation_warnings_fatal:
                    raise exceptions.InvalidConfiguration()
            else:
                self.log.info("SUCCESS: No warnings or errors in deploy "
                              "configuration, proceeding.")

        stack_create = stack is None
        if stack_create:
            self.log.info("No stack found, will be doing a stack create")
        else:
            self.log.info("Stack found, will be doing a stack update")

        if parsed_args.rhel_reg:
            if parsed_args.reg_method == 'satellite':
                sat_required_args = (parsed_args.reg_org
                                     and parsed_args.reg_sat_url
                                     and parsed_args.reg_activation_key)
                if not sat_required_args:
                    raise exceptions.DeploymentError(
                        "ERROR: In order to use satellite registration, "
                        "you must specify --reg-org, --reg-sat-url, and "
                        "--reg-activation-key.")
            else:
                portal_required_args = (parsed_args.reg_org
                                        and parsed_args.reg_activation_key)
                if not portal_required_args:
                    raise exceptions.DeploymentError(
                        "ERROR: In order to use portal registration, you "
                        "must specify --reg-org, and "
                        "--reg-activation-key.")

        if parsed_args.dry_run:
            print("Validation Finished")
            return

        self._deploy_tripleo_heat_templates_tmpdir(stack, parsed_args)

        # Get a new copy of the stack after stack update/create. If it was
        # a create then the previous stack object would be None.
        stack = utils.get_stack(self.orchestration_client, parsed_args.stack)

        if parsed_args.update_plan_only:
            # If we are only updating the plan, then we either wont have a
            # stack yet or there wont be any changes and the following code
            # wont do anything.
            return

        if parsed_args.config_download:
            print("Deploying overcloud configuration")

            deployment.config_download(self.log,
                                       self.clients,
                                       stack,
                                       parsed_args.templates,
                                       parsed_args.deployed_server,
                                       parsed_args.overcloud_ssh_user,
                                       parsed_args.overcloud_ssh_key,
                                       parsed_args.output_dir,
                                       verbosity=self.app_args.verbose_level)

        # Force fetching of attributes
        stack.get()

        overcloudrcs = deployment.overcloudrc(self.workflow_client,
                                              container=stack.stack_name,
                                              no_proxy=parsed_args.no_proxy)

        rcpath = utils.write_overcloudrc(stack.stack_name, overcloudrcs)
        utils.create_tempest_deployer_input()

        # Run postconfig on create or force. Use force to makes sure endpoints
        # are created with deploy reruns and upgrades
        if (stack_create or parsed_args.force_postconfig
                and not parsed_args.skip_postconfig):
            self._deploy_postconfig(stack, parsed_args)

        overcloud_endpoint = utils.get_overcloud_endpoint(stack)

        horizon_url = deployment.get_horizon_url(self.clients,
                                                 stack=stack.stack_name)

        print("Overcloud Endpoint: {0}".format(overcloud_endpoint))
        print("Overcloud Horizon Dashboard URL: {0}".format(horizon_url))
        print("Overcloud rc file: {0}".format(rcpath))
        print("Overcloud Deployed")
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)" % parsed_args)
        self._setup_clients(parsed_args)

        # Swiftclient logs things like 404s at error level, which is a problem
        # because we use EAFP to check for the existence of files.  Turn off
        # most swiftclient logging to avoid cluttering up our output with
        # pointless tracebacks.
        sc_logger = logging.getLogger("swiftclient")
        sc_logger.setLevel(logging.CRITICAL)

        self._validate_args(parsed_args)

        # Throw warning if deprecated service is enabled and
        # ask user if deployment should still be continued.
        if parsed_args.environment_files:
            utils.check_deprecated_service_is_enabled(
                parsed_args.environment_files)

        stack = utils.get_stack(self.orchestration_client, parsed_args.stack)

        self._update_parameters(parsed_args, stack)

        stack_create = stack is None
        if stack_create:
            self.log.info("No stack found, will be doing a stack create")
        else:
            self.log.info("Stack found, will be doing a stack update")

        if parsed_args.dry_run:
            print("Validation Finished")
            return

        start = time.time()

        if not parsed_args.config_download_only:
            self._deploy_tripleo_heat_templates_tmpdir(stack, parsed_args)

        # Get a new copy of the stack after stack update/create. If it was
        # a create then the previous stack object would be None.
        stack = utils.get_stack(self.orchestration_client, parsed_args.stack)

        if parsed_args.update_plan_only:
            # If we are only updating the plan, then we either wont have a
            # stack yet or there wont be any changes and the following code
            # wont do anything.
            return

        if parsed_args.config_download:
            print("Deploying overcloud configuration")
            deployment.set_deployment_status(
                clients=self.clients,
                plan=stack.stack_name,
                status='DEPLOYING'
            )

            try:
                if not parsed_args.config_download_only:
                    deployment.get_hosts_and_enable_ssh_admin(
                        stack,
                        parsed_args.overcloud_ssh_network,
                        parsed_args.overcloud_ssh_user,
                        self.get_key_pair(parsed_args),
                        parsed_args.overcloud_ssh_port_timeout,
                        verbosity=utils.playbook_verbosity(self=self)
                    )

                if parsed_args.config_download_timeout:
                    timeout = parsed_args.config_download_timeout
                else:
                    used = int((time.time() - start) // 60)
                    timeout = parsed_args.timeout - used
                    if timeout <= 0:
                        raise exceptions.DeploymentError(
                            'Deployment timed out after %sm' % used)

                deployment_options = {}
                if parsed_args.deployment_python_interpreter:
                    deployment_options['ansible_python_interpreter'] = \
                        parsed_args.deployment_python_interpreter

                deployment.config_download(
                    self.log,
                    self.clients,
                    stack,
                    parsed_args.overcloud_ssh_network,
                    parsed_args.output_dir,
                    parsed_args.override_ansible_cfg,
                    timeout=parsed_args.overcloud_ssh_port_timeout,
                    verbosity=utils.playbook_verbosity(self=self),
                    deployment_options=deployment_options,
                    in_flight_validations=parsed_args.inflight,
                    deployment_timeout=timeout,
                    tags=parsed_args.tags,
                    skip_tags=parsed_args.skip_tags,
                    limit_hosts=utils.playbook_limit_parse(
                        limit_nodes=parsed_args.limit
                    )
                )
                deployment.set_deployment_status(
                    clients=self.clients,
                    plan=stack.stack_name,
                    status='DEPLOY_SUCCESS')
            except Exception:
                deployment.set_deployment_status(
                    clients=self.clients,
                    plan=stack.stack_name,
                    status='DEPLOY_FAILED'
                )
                raise

        # Force fetching of attributes
        stack.get()

        rcpath = deployment.create_overcloudrc(container=stack.stack_name,
                                               no_proxy=parsed_args.no_proxy)

        # Copy clouds.yaml to the cloud user directory
        user = getpwuid(os.stat(constants.CLOUD_HOME_DIR).st_uid).pw_name
        utils.copy_clouds_yaml(user)
        utils.create_tempest_deployer_input()

        # Run postconfig on create or force. Use force to makes sure endpoints
        # are created with deploy reruns and upgrades
        if (stack_create or parsed_args.force_postconfig
                and not parsed_args.skip_postconfig):
            self._deploy_postconfig(stack, parsed_args)

        overcloud_endpoint = utils.get_overcloud_endpoint(stack)

        horizon_url = deployment.get_horizon_url(stack=stack.stack_name)

        print("Overcloud Endpoint: {0}".format(overcloud_endpoint))
        print("Overcloud Horizon Dashboard URL: {0}".format(horizon_url))
        print("Overcloud rc file: {0}".format(rcpath))
        print("Overcloud Deployed")
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)" % parsed_args)

        # Swiftclient logs things like 404s at error level, which is a problem
        # because we use EAFP to check for the existence of files.  Turn off
        # most swiftclient logging to avoid cluttering up our output with
        # pointless tracebacks.
        sc_logger = logging.getLogger("swiftclient")
        sc_logger.setLevel(logging.CRITICAL)

        self._validate_args(parsed_args)

        clients = self.app.client_manager
        orchestration_client = clients.orchestration

        stack = utils.get_stack(orchestration_client, parsed_args.stack)

        if stack and stack.stack_status == 'IN_PROGRESS':
            raise exceptions.StackInProgress(
                "Unable to deploy as the stack '{}' status is '{}'".format(
                    stack.stack_name, stack.stack_status))

        parameters = self._update_parameters(
            parsed_args, clients.network, stack)

        errors, warnings = self._predeploy_verify_capabilities(
            stack, parameters, parsed_args)
        if errors > 0:
            self.log.error(
                "Configuration has %d errors, fix them before proceeding. "
                "Ignoring these errors is likely to lead to a failed deploy.",
                errors)
            if parsed_args.validation_warnings_fatal or \
                    parsed_args.validation_errors_fatal:
                return
        if warnings > 0:
            self.log.error(
                "Configuration has %d warnings, fix them before proceeding. ",
                warnings)
            if parsed_args.validation_warnings_fatal:
                return
        else:
            self.log.info("SUCCESS: No warnings or errors in deploy "
                          "configuration, proceeding.")

        stack_create = stack is None
        if stack_create:
            self.log.info("No stack found, will be doing a stack create")
        else:
            self.log.info("Stack found, will be doing a stack update")

        if parsed_args.rhel_reg:
            if parsed_args.reg_method == 'satellite':
                sat_required_args = (parsed_args.reg_org and
                                     parsed_args.reg_sat_url and
                                     parsed_args.reg_activation_key)
                if not sat_required_args:
                    raise exceptions.DeploymentError(
                        "ERROR: In order to use satellite registration, "
                        "you must specify --reg-org, --reg-sat-url, and "
                        "--reg-activation-key.")
            else:
                portal_required_args = (parsed_args.reg_org and
                                        parsed_args.reg_activation_key)
                if not portal_required_args:
                    raise exceptions.DeploymentError(
                        "ERROR: In order to use portal registration, you "
                        "must specify --reg-org, and "
                        "--reg-activation-key.")

        if parsed_args.dry_run:
            print("Validation Finished")
            return

        self._deploy_tripleo_heat_templates_tmpdir(stack, parsed_args)

        # Get a new copy of the stack after stack update/create. If it was
        # a create then the previous stack object would be None.
        stack = utils.get_stack(orchestration_client, parsed_args.stack)

        if parsed_args.update_plan_only:
            # If we are only updating the plan, then we either wont have a
            # stack yet or there wont be any changes and the following code
            # wont do anything.
            return

        # Force fetching of attributes
        stack.get()

        utils.create_overcloudrc(clients, stack, parsed_args.no_proxy)
        utils.create_tempest_deployer_input()

        # Run postconfig on create or force. Use force to makes sure endpoints
        # are created with deploy reruns and upgrades
        if (stack_create or parsed_args.force_postconfig
                and not parsed_args.skip_postconfig):
            self._deploy_postconfig(stack, parsed_args)

        overcloud_endpoint = utils.get_overcloud_endpoint(stack)
        print("Overcloud Endpoint: {0}".format(overcloud_endpoint))
        print("Overcloud Deployed")
Ejemplo n.º 13
0
    def _deploy_postconfig(self, stack, parsed_args):
        self.log.debug("_deploy_postconfig(%s)" % parsed_args)

        overcloud_endpoint = utils.get_overcloud_endpoint(stack)
        # NOTE(jaosorior): The overcloud endpoint can contain an IP address or
        # an FQDN depending on how what it's configured to output in the
        # tripleo-heat-templates. Such a configuration can be done by
        # overriding the EndpointMap through parameter_defaults.
        overcloud_ip_or_fqdn = six.moves.urllib.parse.urlparse(
            overcloud_endpoint).hostname

        no_proxy = [os.environ.get('no_proxy'), overcloud_ip_or_fqdn]
        os.environ['no_proxy'] = ','.join(
            [x for x in no_proxy if x is not None])

        service_ips = utils.get_service_ips(stack)

        utils.remove_known_hosts(overcloud_ip_or_fqdn)

        keystone_admin_ip = service_ips.get('KeystoneAdminVip')
        keystone_internal_ip = service_ips.get('KeystoneInternalVip')
        tls_enabled = self._is_tls_enabled(overcloud_endpoint)
        keystone_tls_host = None
        if not keystone_admin_ip:
            keystone_admin_ip = overcloud_ip_or_fqdn
        if not keystone_internal_ip:
            keystone_internal_ip = overcloud_ip_or_fqdn
        if tls_enabled:
            # NOTE(jaosorior): This triggers set up the keystone endpoint with
            # the https protocol and the required port set in
            # keystone.initialize.
            keystone_tls_host = overcloud_ip_or_fqdn

        keystone.initialize(
            keystone_admin_ip,
            utils.get_password('OVERCLOUD_ADMIN_TOKEN'),
            '*****@*****.**',
            utils.get_password('OVERCLOUD_ADMIN_PASSWORD'),
            ssl=keystone_tls_host,
            public=overcloud_ip_or_fqdn,
            user=parsed_args.overcloud_ssh_user,
            admin=keystone_admin_ip,
            internal=keystone_internal_ip)

        if not tls_enabled:
            # NOTE(bcrochet): Bad hack. Remove the ssl_port info from the
            # os_cloud_config.SERVICES dictionary
            for service_name, data in keystone.SERVICES.iteritems():
                data.pop('ssl_port', None)

        services = {}
        for service, data in six.iteritems(constants.SERVICE_LIST):
            service_data = data.copy()
            service_data.pop('password_field', None)
            password_field = data.get('password_field')
            if password_field:
                service_data['password'] = utils.get_password(password_field)

            service_name = re.sub('v[0-9]+', '',
                                  service.capitalize() + 'InternalVip')
            internal_vip = service_ips.get(service_name)
            if internal_vip:
                service_data['internal_host'] = internal_vip
            services.update({service: service_data})

        keystone_client = clients.get_keystone_client(
            'admin',
            utils.get_password('OVERCLOUD_ADMIN_PASSWORD'),
            'admin',
            overcloud_endpoint)
        keystone.setup_endpoints(
            services,
            client=keystone_client,
            os_auth_url=overcloud_endpoint,
            public_host=overcloud_ip_or_fqdn)
Ejemplo n.º 14
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)" % parsed_args)
        self._setup_clients(parsed_args)

        # Swiftclient logs things like 404s at error level, which is a problem
        # because we use EAFP to check for the existence of files.  Turn off
        # most swiftclient logging to avoid cluttering up our output with
        # pointless tracebacks.
        sc_logger = logging.getLogger("swiftclient")
        sc_logger.setLevel(logging.CRITICAL)

        self._validate_args(parsed_args)

        # Throw warning if deprecated service is enabled and
        # ask user if deployment should still be continued.
        if parsed_args.environment_files:
            utils.check_deprecated_service_is_enabled(
                parsed_args.environment_files)

        stack = utils.get_stack(self.orchestration_client, parsed_args.stack)

        if stack and stack.stack_status == 'IN_PROGRESS':
            raise exceptions.StackInProgress(
                "Unable to deploy as the stack '{}' status is '{}'".format(
                    stack.stack_name, stack.stack_status))

        self._update_parameters(parsed_args, stack)

        stack_create = stack is None
        if stack_create:
            self.log.info("No stack found, will be doing a stack create")
        else:
            self.log.info("Stack found, will be doing a stack update")

        if parsed_args.dry_run:
            print("Validation Finished")
            return

        start = time.time()

        if not parsed_args.config_download_only:
            self._deploy_tripleo_heat_templates_tmpdir(stack, parsed_args)

        # Get a new copy of the stack after stack update/create. If it was
        # a create then the previous stack object would be None.
        stack = utils.get_stack(self.orchestration_client, parsed_args.stack)

        if parsed_args.update_plan_only:
            # If we are only updating the plan, then we either wont have a
            # stack yet or there wont be any changes and the following code
            # wont do anything.
            return

        if parsed_args.config_download:
            print("Deploying overcloud configuration")
            deployment.set_deployment_status(
                self.clients, 'deploying',
                plan=stack.stack_name)

            try:
                if not parsed_args.config_download_only:
                    deployment.get_hosts_and_enable_ssh_admin(
                        self.log, self.clients, stack,
                        parsed_args.overcloud_ssh_network,
                        parsed_args.overcloud_ssh_user,
                        parsed_args.overcloud_ssh_key)

                if parsed_args.config_download_timeout:
                    timeout = parsed_args.config_download_timeout * 60
                else:
                    used = int(time.time() - start)
                    timeout = (parsed_args.timeout * 60) - used

                deployment_options = {}
                if parsed_args.deployment_python_interpreter:
                    deployment_options['ansible_python_interpreter'] = \
                        parsed_args.deployment_python_interpreter

                deployment.config_download(
                    self.log, self.clients, stack,
                    parsed_args.templates, parsed_args.overcloud_ssh_user,
                    parsed_args.overcloud_ssh_key,
                    parsed_args.overcloud_ssh_network,
                    parsed_args.output_dir,
                    parsed_args.override_ansible_cfg,
                    timeout,
                    verbosity=self.app_args.verbose_level,
                    deployment_options=deployment_options,
                    in_flight_validations=parsed_args.inflight)
            except Exception:
                deployment.set_deployment_status(
                    self.clients, 'failed',
                    plan=stack.stack_name)
                raise

        # Force fetching of attributes
        stack.get()

        overcloudrcs = deployment.create_overcloudrc(
            self.clients, container=stack.stack_name,
            no_proxy=parsed_args.no_proxy)

        # Create overcloud clouds.yaml
        cloud_data = deployment.create_cloudsyaml(
            self.clients, container=stack.stack_name)
        cloud_yaml_dir = os.path.join(constants.CLOUD_HOME_DIR,
                                      constants.CLOUDS_YAML_DIR)
        cloud_user_id = os.stat(constants.CLOUD_HOME_DIR).st_uid
        cloud_group_id = os.stat(constants.CLOUD_HOME_DIR).st_gid
        clouds_yaml.create_clouds_yaml(
            cloud=cloud_data,
            cloud_yaml_dir=cloud_yaml_dir,
            user_id=cloud_user_id,
            group_id=cloud_group_id)
        rcpath = utils.write_overcloudrc(stack.stack_name, overcloudrcs)
        utils.create_tempest_deployer_input()

        # Run postconfig on create or force. Use force to makes sure endpoints
        # are created with deploy reruns and upgrades
        if (stack_create or parsed_args.force_postconfig
                and not parsed_args.skip_postconfig):
            self._deploy_postconfig(stack, parsed_args)

        overcloud_endpoint = utils.get_overcloud_endpoint(stack)

        horizon_url = deployment.get_horizon_url(
            self.clients, stack=stack.stack_name)

        print("Overcloud Endpoint: {0}".format(overcloud_endpoint))
        print("Overcloud Horizon Dashboard URL: {0}".format(horizon_url))
        print("Overcloud rc file: {0}".format(rcpath))
        print("Overcloud Deployed")
Ejemplo n.º 15
0
    def _deploy_postconfig(self, stack, parsed_args):
        self.log.debug("_deploy_postconfig(%s)" % parsed_args)

        overcloud_endpoint = utils.get_overcloud_endpoint(stack)
        # NOTE(jaosorior): The overcloud endpoint can contain an IP address or
        # an FQDN depending on how what it's configured to output in the
        # tripleo-heat-templates. Such a configuration can be done by
        # overriding the EndpointMap through parameter_defaults.
        overcloud_ip_or_fqdn = six.moves.urllib.parse.urlparse(
            overcloud_endpoint).hostname

        no_proxy = [os.environ.get('no_proxy'), overcloud_ip_or_fqdn]
        os.environ['no_proxy'] = ','.join(
            [x for x in no_proxy if x is not None])

        service_ips = utils.get_service_ips(stack)

        utils.remove_known_hosts(overcloud_ip_or_fqdn)

        keystone_admin_ip = service_ips.get('KeystoneAdminVip')
        keystone_internal_ip = service_ips.get('KeystoneInternalVip')
        tls_enabled = self._is_tls_enabled(overcloud_endpoint)
        keystone_tls_host = None
        if not keystone_admin_ip:
            keystone_admin_ip = overcloud_ip_or_fqdn
        if not keystone_internal_ip:
            keystone_internal_ip = overcloud_ip_or_fqdn
        if tls_enabled:
            # NOTE(jaosorior): This triggers set up the keystone endpoint with
            # the https protocol and the required port set in
            # keystone.initialize.
            keystone_tls_host = overcloud_ip_or_fqdn

        keystone.initialize(keystone_admin_ip,
                            utils.get_password('OVERCLOUD_ADMIN_TOKEN'),
                            '*****@*****.**',
                            utils.get_password('OVERCLOUD_ADMIN_PASSWORD'),
                            ssl=keystone_tls_host,
                            public=overcloud_ip_or_fqdn,
                            user=parsed_args.overcloud_ssh_user,
                            admin=keystone_admin_ip,
                            internal=keystone_internal_ip)

        if not tls_enabled:
            # NOTE(bcrochet): Bad hack. Remove the ssl_port info from the
            # os_cloud_config.SERVICES dictionary
            for service_name, data in keystone.SERVICES.iteritems():
                data.pop('ssl_port', None)

        services = {}
        for service, data in six.iteritems(constants.SERVICE_LIST):
            service_data = data.copy()
            service_data.pop('password_field', None)
            password_field = data.get('password_field')
            if password_field:
                service_data['password'] = utils.get_password(password_field)

            service_name = re.sub('v[0-9]+', '',
                                  service.capitalize() + 'InternalVip')
            internal_vip = service_ips.get(service_name)
            if internal_vip:
                service_data['internal_host'] = internal_vip
            services.update({service: service_data})

        keystone_client = clients.get_keystone_client(
            'admin', utils.get_password('OVERCLOUD_ADMIN_PASSWORD'), 'admin',
            overcloud_endpoint)
        keystone.setup_endpoints(services,
                                 client=keystone_client,
                                 os_auth_url=overcloud_endpoint,
                                 public_host=overcloud_ip_or_fqdn)
Ejemplo n.º 16
0
    def _deploy_postconfig(self, stack, parsed_args):
        self.log.debug("_deploy_postconfig(%s)" % parsed_args)

        overcloud_endpoint = utils.get_overcloud_endpoint(stack)
        overcloud_ip = six.moves.urllib.parse.urlparse(
            overcloud_endpoint).hostname

        no_proxy = [os.environ.get('no_proxy'), overcloud_ip]
        os.environ['no_proxy'] = ','.join(
            [x for x in no_proxy if x is not None])

        service_ips = utils.get_service_ips(stack)

        utils.remove_known_hosts(overcloud_ip)

        keystone_ip = service_ips.get('KeystoneAdminVip')
        if not keystone_ip:
            keystone_ip = overcloud_ip

        # Note (spredzy): This was deprecated at the begining of
        # the Mitaka cycle. Should be good to remove for the
        # next N cycle.
        keystone.initialize(keystone_ip,
                            utils.get_password('OVERCLOUD_ADMIN_TOKEN'),
                            '*****@*****.**',
                            utils.get_password('OVERCLOUD_ADMIN_PASSWORD'),
                            public=overcloud_ip,
                            user=parsed_args.overcloud_ssh_user)

        # NOTE(bcrochet): Bad hack. Remove the ssl_port info from the
        # os_cloud_config.SERVICES dictionary
        for service_name, data in keystone.SERVICES.iteritems():
            data.pop('ssl_port', None)

        services = {}
        for service, data in six.iteritems(constants.SERVICE_LIST):
            service_data = data.copy()
            service_data.pop('password_field', None)
            password_field = data.get('password_field')
            if password_field:
                service_data['password'] = utils.get_password(password_field)

            service_name = re.sub('v[0-9]+', '',
                                  service.capitalize() + 'InternalVip')
            internal_vip = service_ips.get(service_name)
            if internal_vip:
                service_data['internal_host'] = internal_vip
            services.update({service: service_data})

        # Note (spredzy): This was deprecated at the begining of
        # the Mitaka cycle. Should be good to remove for the
        # next N cycle.
        try:
            keystone_client = clients.get_keystone_client(
                'admin', utils.get_password('OVERCLOUD_ADMIN_PASSWORD'),
                'admin', overcloud_endpoint)
            keystone.setup_endpoints(services,
                                     client=keystone_client,
                                     os_auth_url=overcloud_endpoint,
                                     public_host=overcloud_ip)
        except kscexc.Conflict:
            pass
        else:
            self.log.warning("Setting up keystone endpoints via "
                             "os-cloud-config. This behavior is "
                             "deprecated and will be removed in "
                             "a future release.  Please update "
                             "your heat templates to a version "
                             "that does Keystone initialization "
                             "via Puppet.")

        compute_client = clients.get_nova_bm_client(
            'admin', utils.get_password('OVERCLOUD_ADMIN_PASSWORD'), 'admin',
            overcloud_endpoint)
        compute_client.flavors.create('m1.demo', 512, 1, 10, 'auto')