示例#1
0
    def delete(self, overcloud_id):
        """Deletes the given overcloud.

        :param overcloud_id: identifies the overcloud being deleted
        :type  overcloud_id: int

        :raises: tuskar.common.exception.OvercloudNotFound if there
                 is no overcloud with the given ID
        """

        # FIXME(lsmola) this should always try to delete both overcloud
        # and stack. So it requires some exception catch over below.
        # FIXME(lsmola) there is also a workflow needed
        # step one- delete stack and set status deleting in progress to
        # overcloud
        # step 2 - once stack is deleted, delete the overcloud
        LOG.debug("Deleting overcloud with ID: %s" % overcloud_id)
        pecan.request.dbapi.delete_overcloud_by_id(overcloud_id)

        heat_client = HeatClient()
        if not heat_client.exists_stack():
            # If the stack doesn't exist, we have nothing else to do here.
            return

        result = heat_client.delete_stack()

        if not result:
            raise wsme.exc.ClientSideError(_("Failed to delete the Heat overcloud."))
示例#2
0
    def template_parameters(self):
        # TODO(lsmola) returning all possible parameters now, later in J
        # user should pick what to build first and we should return
        # appropriate parameters.
        fixed_params = {template_tools.OVERCLOUD_COMPUTE_ROLE: 1,
                        template_tools.OVERCLOUD_VOLUME_ROLE: 1,
                        template_tools.OVERCLOUD_OBJECT_STORAGE_ROLE: 1}

        # We don't want user to fill flavor based parameters, cause
        # it is already stored in OvercloudRoles, also Image parameters
        # are expected to be default, otherwise our associations
        # will not work.
        except_parameters = ('OvercloudControlFlavor',
                             'OvercloudComputeFlavor',
                             'OvercloudBlockStorageFlavor',
                             'OvercloudSwiftStorageFlavor',
                             'NovaImage',
                             'notcomputeImage',
                             'BlockStorageImage',
                             'SwiftStorageImage',)

        overcloud = template_tools.merge_templates(fixed_params)

        heat_client = HeatClient()
        try:
            allowed_data = heat_client.validate_template(overcloud)
        except Exception as e:
            raise exception.HeatTemplateValidateFailed(unicode(e))

        # Send back only wanted parameters
        template_parameters = dict((key, value) for key, value
                                   in allowed_data['Parameters'].items()
                                   if key not in except_parameters)

        return template_parameters
示例#3
0
    def delete(self, overcloud_id):
        """Deletes the given overcloud.

        :param overcloud_id: identifies the overcloud being deleted
        :type  overcloud_id: int

        :raises: tuskar.common.exception.OvercloudNotFound if there
                 is no overcloud with the given ID
        """

        # FIXME(lsmola) this should always try to delete both overcloud
        # and stack. So it requires some exception catch over below.
        # FIXME(lsmola) there is also a workflow needed
        # step 1- delete stack and set status deleting in progress to
        # overcloud
        # step 2 - once stack is deleted, delete the overcloud
        LOG.debug('Deleting overcloud with ID: %s' % overcloud_id)
        pecan.request.dbapi.delete_overcloud_by_id(overcloud_id)

        heat_client = HeatClient()
        if not heat_client.exists_stack():
            # If the stack doesn't exist, we have nothing else to do here.
            return

        try:
            heat_client.delete_stack()
        except Exception:
            raise exception.HeatStackDeleteFailed()
示例#4
0
def process_stack(attributes, counts, create=False):
    """Helper function for processing the stack.

    Given a params dict containing the Overcloud Roles and initialization
    parameters create or update the stack.

    :param attributes: Dictionary of initialization params and overcloud roles
                       for heat template and initialization of stack
    :type  attributes: dict

    :param counts: Dictionary of counts of roles to be deployed
    :type  counts: dict

    :param create: A flag to designate if we are creating or updating the stack
    :type create: bool
    """

    overcloud = template_tools.merge_templates(parse_counts(counts))
    heat_client = HeatClient()

    stack_exists = heat_client.exists_stack()
    valid, allowed_data = heat_client.validate_template(overcloud)

    if not valid:
        raise exception.InvalidHeatTemplate()

    if stack_exists and create:
        raise exception.StackAlreadyCreated()

    elif not stack_exists and not create:
        raise exception.StackNotFound()

    if create:
        operation = heat_client.create_stack
    else:
        operation = heat_client.update_stack

    res = operation(overcloud, filter_template_attributes(allowed_data, attributes))

    if not res:
        if create:
            raise exception.HeatTemplateCreateFailed()

        raise exception.HeatTemplateUpdateFailed()
示例#5
0
    def template_parameters(self):
        # TODO(lsmola) returning all possible parameters now, later in J
        # user should pick what to build first and we should return
        # appropriate parameters.
        fixed_params = {
            template_tools.OVERCLOUD_COMPUTE_ROLE: 1,
            template_tools.OVERCLOUD_VOLUME_ROLE: 1,
            template_tools.OVERCLOUD_OBJECT_STORAGE_ROLE: 1
        }

        # We don't want user to fill flavor based parameters, cause
        # it is already stored in OvercloudRoles, also Image parameters
        # are expected to be default, otherwise our associations
        # will not work.
        except_parameters = (
            'OvercloudControlFlavor',
            'OvercloudComputeFlavor',
            'OvercloudBlockStorageFlavor',
            'OvercloudSwiftStorageFlavor',
            'NovaImage',
            'notcomputeImage',
            'BlockStorageImage',
            'SwiftStorageImage',
        )

        overcloud = template_tools.merge_templates(fixed_params)

        heat_client = HeatClient()
        try:
            allowed_data = heat_client.validate_template(overcloud)
        except Exception as e:
            raise exception.HeatTemplateValidateFailed(unicode(e))

        # Send back only wanted parameters
        template_parameters = dict(
            (key, value) for key, value in allowed_data['Parameters'].items()
            if key not in except_parameters)

        return template_parameters
示例#6
0
def process_stack(attributes, counts, overcloud_roles, create=False):
    """Helper function for processing the stack.

    Given a params dict containing the Overcloud Roles and initialization
    parameters create or update the stack.

    :param attributes: Dictionary of initialization params and overcloud roles
                       for heat template and initialization of stack
    :type  attributes: dict

    :param counts: Dictionary of counts of roles to be deployed
    :type  counts: dict

    :param overcloud_roles: Dict of (overcloud_role_id, overcloud_role) so
                            we can access image_name and flavor_id of roles
    :type  overcloud_roles: dict

    :param create: A flag to designate if we are creating or updating the stack
    :type create: bool
    """
    heat_client = HeatClient()

    try:
        # Get how many of each role we want and what flavor each role uses.
        parsed_counts, parsed_flavors = parse_counts_and_flavors(
            counts, overcloud_roles)
    except Exception as e:
        raise exception.ParseCountsAndFlavorsFailed(six.text_type(e))

    try:
        # Build the template
        overcloud = template_tools.merge_templates(parsed_counts)
    except Exception as e:
        raise exception.HeatTemplateCreateFailed(six.text_type(e))

    try:
        # Get the parameters that the template accepts and validate
        allowed_data = heat_client.validate_template(overcloud)
    except Exception as e:
        raise exception.HeatTemplateValidateFailed(six.text_type(e))

    stack_exists = heat_client.exists_stack()
    if stack_exists and create:
        raise exception.StackAlreadyCreated()

    elif not stack_exists and not create:
        raise exception.StackNotFound()

    try:
        # Put flavors from OverloudRoles into attributes
        attributes.update(get_flavor_attributes(parsed_flavors))

        # Filter the attributes to allowed only
        filtered_attributes = filter_template_attributes(allowed_data,
                                                         attributes)
    except Exception as e:
        raise exception.HeatStackProcessingAttributesFailed(six.text_type(e))

    if create:
        operation = heat_client.create_stack
    else:
        operation = heat_client.update_stack

    try:
        result = operation(overcloud, filtered_attributes)
    except Exception as e:
        if create:
            raise exception.HeatStackCreateFailed(six.text_type(e))
        else:
            raise exception.HeatStackUpdateFailed(six.text_type(e))

    return result
示例#7
0
def process_stack(attributes, counts, overcloud_roles, create=False):
    """Helper function for processing the stack.

    Given a params dict containing the Overcloud Roles and initialization
    parameters create or update the stack.

    :param attributes: Dictionary of initialization params and overcloud roles
                       for heat template and initialization of stack
    :type  attributes: dict

    :param counts: Dictionary of counts of roles to be deployed
    :type  counts: dict

    :param overcloud_roles: Dict of (overcloud_role_id, overcloud_role) so
                            we can access image_name and flavor_id of roles
    :type  overcloud_roles: dict

    :param create: A flag to designate if we are creating or updating the stack
    :type create: bool
    """
    heat_client = HeatClient()

    try:
        # Get how many of each role we want and what flavor each role uses.
        parsed_counts, parsed_flavors = parse_counts_and_flavors(
            counts, overcloud_roles)
    except Exception as e:
        raise exception.ParseCountsAndFlavorsFailed(six.text_type(e))

    try:
        # Build the template
        overcloud = template_tools.merge_templates(parsed_counts)
    except Exception as e:
        raise exception.HeatTemplateCreateFailed(six.text_type(e))

    try:
        # Get the parameters that the template accepts and validate
        allowed_data = heat_client.validate_template(overcloud)
    except Exception as e:
        raise exception.HeatTemplateValidateFailed(six.text_type(e))

    stack_exists = heat_client.exists_stack()
    if stack_exists and create:
        raise exception.StackAlreadyCreated()

    elif not stack_exists and not create:
        raise exception.StackNotFound()

    try:
        # Put flavors from OverloudRoles into attributes
        attributes.update(get_flavor_attributes(parsed_flavors))

        # Filter the attributes to allowed only
        filtered_attributes = filter_template_attributes(
            allowed_data, attributes)
    except Exception as e:
        raise exception.HeatStackProcessingAttributesFailed(six.text_type(e))

    if create:
        operation = heat_client.create_stack
    else:
        operation = heat_client.update_stack

    try:
        result = operation(overcloud, filtered_attributes)
    except Exception as e:
        if create:
            raise exception.HeatStackCreateFailed(six.text_type(e))
        else:
            raise exception.HeatStackUpdateFailed(six.text_type(e))

    return result