コード例 #1
0
def get_profile_of_flavor(flavor_name, compute_client):
    """Returns profile name for a given flavor name.

    :param flavor_name: Flavor name
    :param compute_client: Compute client object
    :raises: exception.DeriveParamsError: Derive parameters error

    :return: profile name
    """

    try:
        flavor = compute_client.flavors.find(name=flavor_name)
    except Exception as err:
        raise exception.DeriveParamsError(
            'Unable to determine flavor for flavor name: '
            '%(flavor_name)s. Error:%(err)s' % {
                'flavor_name': flavor_name,
                'err': err
            })
    if flavor:
        profile = flavor.get_keys().get('capabilities:profile', '')
        if profile:
            return profile
        raise exception.DeriveParamsError(
            'Unable to determine profile for flavor (flavor name: '
            '%s)' % flavor_name)
    raise exception.DeriveParamsError(
        'Unable to determine flavor for flavor name: '
        '%s' % flavor_name)
コード例 #2
0
    def run(self, context):
        try:
            if not self.num_list:
                err_msg = ("Input param 'num_list' is blank.")
                raise exception.DeriveParamsError(err_msg)

            try:
                # splitting a string (comma delimited list) into
                # list of numbers
                # example: "12,13,14,17" string into [12,13,14,17]
                num_list = [
                    int(num.strip(' ')) for num in self.num_list.split(",")
                ]
            except ValueError as exc:
                err_msg = ("Invalid number in input param "
                           "'num_list': %s" % exc)
                raise exception.DeriveParamsError(err_msg)

            range_list = self.convert_number_to_range_list(num_list)
        except exception.DeriveParamsError as err:
            LOG.error('Derive Params Error: %s', err)
            return actions.Result(error=str(err))

        # converts into comma delimited range list as string
        return ','.join(range_list)
コード例 #3
0
    def get_network_config(self, preview_data, stack_name, role_name):
        result = None
        if preview_data:
            for res in preview_data.resources:
                net_script = self.process_preview_list(res, stack_name,
                                                       role_name)
                if net_script:
                    ns_len = len(net_script)
                    start_index = (net_script.find("echo '{\"network_config\"",
                                                   0, ns_len) + 6)
                    # In file network/scripts/run-os-net-config.sh
                    end_str = "' > /etc/os-net-config/config.json"
                    end_index = net_script.find(end_str, start_index, ns_len)
                    if (end_index > start_index):
                        net_config = net_script[start_index:end_index]
                        if net_config:
                            result = json.loads(net_config)
                    break

        if not result:
            err_msg = ("Unable to determine network config for role '%s'." %
                       self.role_name)
            raise exception.DeriveParamsError(err_msg)

        return result
コード例 #4
0
    def run(self, context):
        try:
            if not self.range_list:
                err_msg = ("Input param 'range_list' is blank.")
                raise exception.DeriveParamsError(err_msg)
            range_list = self.range_list
            # converts into python list if range_list is not list type
            if not isinstance(range_list, list):
                range_list = self.range_list.split(",")

            num_list = self.convert_range_to_number_list(range_list)
        except exception.DeriveParamsError as err:
            LOG.error('Derive Params Error: %s', err)
            return actions.Result(error=str(err))

        # converts into comma delimited number list as string
        return ','.join([str(num) for num in num_list])
コード例 #5
0
    def convert_range_to_number_list(self, range_list):
        num_list = []
        exclude_num_list = []
        try:
            for val in range_list:
                val = val.strip(' ')
                if '^' in val:
                    exclude_num_list.append(int(val[1:]))
                elif '-' in val:
                    split_list = val.split("-")
                    range_min = int(split_list[0])
                    range_max = int(split_list[1])
                    num_list.extend(range(range_min, (range_max + 1)))
                else:
                    num_list.append(int(val))
        except ValueError as exc:
            err_msg = ("Invalid number in input param "
                       "'range_list': %s" % exc)
            raise exception.DeriveParamsError(err_msg)

        # here, num_list is a list of integers
        return [num for num in num_list if num not in exclude_num_list]