Пример #1
0
def _check_extra_parameter(extra):
    """Check whether the extra parameters can be parsed.
    """
    if extra:
        if not isinstance(extra, list):
            _errors.ConfigurationError(
                "Extra parameters must be provided as a list: %s." %
                (extra, )
            )
        kv_to_dict(extra)
Пример #2
0
def _preprocess_filters(generic_filters, meta_filters):
    """Process filters.
    """
    if generic_filters:
        generic_filters = kv_to_dict(generic_filters)
    else:
        generic_filters = {}

    if meta_filters:
        meta_filters = kv_to_dict(meta_filters)
    else:
        meta_filters = {}

    meta_filters['mysql-fabric'] = 'True'

    if any(key in reserved_meta for key in generic_filters.iterkeys()):
        raise ConfigurationError(
            "Generic filters option cannot have keyords in the following "
            "list: %s." % (str(reserved_meta), ))

    return generic_filters, meta_filters
Пример #3
0
def _preprocess_filters(generic_filters, meta_filters):
    """Process filters.
    """
    if generic_filters:
        generic_filters = kv_to_dict(generic_filters)
    else:
        generic_filters = {}

    if meta_filters:
        meta_filters = kv_to_dict(meta_filters)
    else:
        meta_filters = {}

    meta_filters['mysql-fabric'] = 'True'

    if any(key in reserved_meta for key in generic_filters.iterkeys()):
        raise ConfigurationError(
            "Generic filters option cannot have keyords in the following "
            "list: %s." % (str(reserved_meta), )
        )

    return generic_filters, meta_filters
Пример #4
0
def _fix_credentials(provider, credentials):
    """Add extra stuff to the credentials dictionary.
    """
    extra = {}
    if provider.extra:
        extra = kv_to_dict(provider.extra)
    credentials.update(extra)

    # By default, the keystone module is used for authentication. However,
    # the Nova API allow providers to specify their own authentication
    # system. In the case, it is needed to load the authentication plugin
    # which shall be used.
    auth_system = credentials.get("auth_system", None)
    if auth_system and auth_system != "keystone":
        auth_plugin = novaclient.auth_plugin.load_plugin(auth_system)
    else:
        auth_plugin = None
    credentials.update({"auth_plugin": auth_plugin})
Пример #5
0
def _fix_credentials(provider, credentials):
    """Add extra stuff to the credentials dictionary.
    """
    extra = {}
    if provider.extra:
        extra = kv_to_dict(provider.extra)
    credentials.update(extra)

    # By default, the keystone module is used for authentication. However,
    # the Nova API allow providers to specify their own authentication
    # system. In the case, it is needed to load the authentication plugin
    # which shall be used.
    auth_system = credentials.get('auth_system', None)
    if auth_system and auth_system != "keystone":
        auth_plugin = novaclient.auth_plugin.load_plugin(auth_system)
    else:
        auth_plugin = None
    credentials.update({'auth_plugin' : auth_plugin})
Пример #6
0
    def execute(self, event, locks=None, args=None, kwargs=None):
        """Trigger the execution of an event.

        :param event: Event's identification.
        :type event: String
        :param args: Event's non-keyworded arguments.
        :param kwargs: Event's keyworded arguments.

        :return: :class:`CommandResult` instance with UUID of the
                 procedures that were triggered.
        """
        # Prepare lockable objects.
        lockable_objects = None
        if locks:
            lockable_objects = set()
            for lock in locks:
                lockable_objects.add(lock.strip())

        # Prepare list arguments.
        param_args = []
        if args is not None:
            param_args = args

        # Prepare key word arguments.
        param_kwargs = {}
        if kwargs is not None:
            param_kwargs = kv_to_dict(kwargs)

        # Define the result set format.
        rset = ResultSet(names=['uuid'], types=[str])

        _LOGGER.debug("Triggering event (%s) with arguments: %s, %s.", event,
                      param_args, param_kwargs)

        # Trigger the event and add the UUID of all procedures queued
        # to the result.
        procedures = _events.trigger(event, lockable_objects, *param_args,
                                     **param_kwargs)
        for procedure in procedures:
            rset.append_row([str(procedure.uuid)])

        return CommandResult(None, results=rset)
Пример #7
0
    def execute(self, event, locks=None, args=None, kwargs=None):
        """Trigger the execution of an event.

        :param event: Event's identification.
        :type event: String
        :param args: Event's non-keyworded arguments.
        :param kwargs: Event's keyworded arguments.

        :return: :class:`CommandResult` instance with UUID of the
                 procedures that were triggered.
        """
        # Prepare lockable objects.
        lockable_objects = None
        if locks:
            lockable_objects = set()
            for lock in locks:
                lockable_objects.add(lock.strip())

        # Prepare list arguments.
        param_args = []
        if args is not None:
            param_args = args

        # Prepare key word arguments.
        param_kwargs = {}
        if kwargs is not None:
            param_kwargs = kv_to_dict(kwargs)

        # Define the result set format.
        rset = ResultSet(names=["uuid"], types=[str])

        _LOGGER.debug("Triggering event (%s) with arguments: %s, %s.", event, param_args, param_kwargs)

        # Trigger the event and add the UUID of all procedures queued
        # to the result.
        procedures = _events.trigger(event, lockable_objects, *param_args, **param_kwargs)
        for procedure in procedures:
            rset.append_row([str(procedure.uuid)])

        return CommandResult(None, results=rset)
Пример #8
0
def _preprocess_parameters(parameters, machine_group_uuid, provider):
    """Process paramaters.
    """
    # Check whether all parameters are expected.
    for key, value in parameters.items():
        if key not in VALID_PARAMETERS and (value is not None and value):
            raise MachineError(
                "Parameter (%s) is not in the set of possible parameters: %s.",
                key, VALID_PARAMETERS)
        elif key not in VALID_PARAMETERS:
            del parameters[key]

    # 1. Put image parameter in the appropriate format.
    if parameters['image']:
        parameters['image'] = kv_to_dict(parameters['image'])
    elif provider.default_image:
        parameters['image'] = {'name': provider.default_image}
    if not parameters['image']:
        raise MachineError("No valid image hasn't been found.")

    # 2. Put flavor parameter in the appropriate format.
    if parameters['flavor']:
        parameters['flavor'] = kv_to_dict(parameters['flavor'])
    elif provider.default_flavor:
        parameters['flavor'] = {'name': provider.default_flavor}
    if not parameters['flavor']:
        raise MachineError("No valid flavor hasn't been found.")

    # 3. Check the parameter number_machines.
    number_machines = parameters['number_machines']
    try:
        number_machines = int(number_machines)
        parameters['number_machines'] = number_machines
    except TypeError:
        number_machines = 1
        parameters['number_machines'] = number_machines
    if number_machines <= 0:
        raise MachineError(
            "Number of machines must be greater than zero (%s)." %
            (number_machines, ))

    # 4. We don't need to check the availability_zone parameter

    # 5. We don't need to check the parameter key_name parameter.

    # 6. Put the security_groups parameter in the appropriate format.
    if parameters['security_groups']:
        security_groups = parameters['security_groups'].split(',')
        parameters['security_groups'] = security_groups

    # 7. Check the private_newtwork parameter.
    private_nics = parameters['private_nics']
    private_network = parameters['private_network']
    if private_network and private_nics:
        raise ConfigurationError(
            "Can't define both private_network (%s) and private_nics "
            "parameters (%s)." % (private_network, private_nics))

    # 8. Check the public_newtwork parameter.
    public_nics = parameters['public_nics']
    public_network = parameters['public_network']
    if public_network and public_nics:
        raise ConfigurationError(
            "Can't define both public_network (%s) and public_nics "
            "parameters (%s)." % (public_network, public_nics))

    # 9. Read userdata parameter which must be a path to a file.
    if parameters['userdata']:
        try:
            src = parameters['userdata']
            userdata = open(src)
        except IOError as error:
            raise ConfigurationError("Can't open '%(src)s': %(exc)s" % {
                'src': src,
                'exc': error
            })
        parameters['userdata'] = userdata

    # 10. We don't need to check the swap parameter

    # 11. Put the block_device parameter in the appropriate format.
    if parameters['block_device']:
        raise ConfigurationError(
            "Parameter block_device is not supported yet.")

    # 12. Put the scheduler_hints parameter in the appropriate format.
    if parameters['scheduler_hints']:
        parameters['scheduler_hints'] = \
            kv_to_dict(parameters['scheduler_hints'])

    # 13. Put the private_nics parameter in the appropriate format.
    if parameters['private_nics']:
        raise ConfigurationError(
            "Parameter private_nics is not supported yet.")

    # 14. Put the public_nics parameter in the appropriate format.
    if parameters['public_nics']:
        raise ConfigurationError("Parameter public_nics is not supported yet.")

    # 15. Put meta parameter in the appropriate format.
    reserved_value = ('True',
                      str(FabricNode().version), str(FabricNode().uuid),
                      str(FabricNode().group_uuid), machine_group_uuid)
    assert len(reserved_meta) == len(reserved_value)
    if parameters['meta']:
        parameters['meta'] = kv_to_dict(parameters['meta'])
        if any(key in reserved_meta for key in parameters['meta'].iterkeys()):
            raise ConfigurationError(
                "The meta parameter cannot have keywords in the following "
                "list: %s. They are reserved for internal use." %
                (str(reserved_meta), ))
    else:
        parameters['meta'] = {}

    meta = dict(zip(reserved_meta, reserved_value))
    parameters['meta'].update(meta)
Пример #9
0
def _preprocess_parameters(parameters, machine_group_uuid, provider):
    """Process paramaters.
    """
    # Check whether all parameters are expected.
    for key, value in parameters.items():
        if key not in VALID_PARAMETERS and (value is not None and value):
            raise MachineError(
                "Parameter (%s) is not in the set of possible parameters: %s.",
                key, VALID_PARAMETERS
            )
        elif key not in VALID_PARAMETERS:
            del parameters[key]

    # 1. Put image parameter in the appropriate format.
    if parameters['image']:
        parameters['image'] = kv_to_dict(parameters['image'])
    elif provider.default_image:
        parameters['image'] = {'name' : provider.default_image}
    if not parameters['image']:
        raise MachineError("No valid image hasn't been found.")

    # 2. Put flavor parameter in the appropriate format.
    if parameters['flavor']:
        parameters['flavor'] = kv_to_dict(parameters['flavor'])
    elif provider.default_flavor:
        parameters['flavor'] = {'name' : provider.default_flavor}
    if not parameters['flavor']:
        raise MachineError("No valid flavor hasn't been found.")

    # 3. Check the parameter number_machines.
    number_machines = parameters['number_machines']
    try:
        number_machines = int(number_machines)
        parameters['number_machines'] = number_machines
    except TypeError:
        number_machines = 1
        parameters['number_machines'] = number_machines
    if number_machines <= 0:
        raise MachineError(
            "Number of machines must be greater than zero (%s)." %
            (number_machines, )
        )

    # 4. We don't need to check the availability_zone parameter

    # 5. We don't need to check the parameter key_name parameter.

    # 6. Put the security_groups parameter in the appropriate format.
    if parameters['security_groups']:
        security_groups = parameters['security_groups'].split(',')
        parameters['security_groups'] = security_groups

    # 7. Check the private_newtwork parameter.
    private_nics = parameters['private_nics']
    private_network = parameters['private_network']
    if private_network and private_nics:
        raise ConfigurationError(
            "Can't define both private_network (%s) and private_nics "
            "parameters (%s)." % (private_network, private_nics)
        )

    # 8. Check the public_newtwork parameter.
    public_nics = parameters['public_nics']
    public_network = parameters['public_network']
    if public_network and public_nics:
        raise ConfigurationError(
            "Can't define both public_network (%s) and public_nics "
            "parameters (%s)." % (public_network, public_nics)
        )

    # 9. Read userdata parameter which must be a path to a file.
    if parameters['userdata']:
        try:
            src = parameters['userdata']
            userdata = open(src)
        except IOError as error:
            raise ConfigurationError(
                "Can't open '%(src)s': %(exc)s" % {'src': src, 'exc': error}
            )
        parameters['userdata'] = userdata

    # 10. We don't need to check the swap parameter

    # 11. Put the block_device parameter in the appropriate format.
    if parameters['block_device']:
        raise ConfigurationError(
            "Parameter block_device is not supported yet."
        )

    # 12. Put the scheduler_hints parameter in the appropriate format.
    if parameters['scheduler_hints']:
        parameters['scheduler_hints'] = \
            kv_to_dict(parameters['scheduler_hints'])

    # 13. Put the private_nics parameter in the appropriate format.
    if parameters['private_nics']:
        raise ConfigurationError(
            "Parameter private_nics is not supported yet."
        )

    # 14. Put the public_nics parameter in the appropriate format.
    if parameters['public_nics']:
        raise ConfigurationError(
            "Parameter public_nics is not supported yet."
        )

    # 15. Put meta parameter in the appropriate format.
    reserved_value = (
        'True', str(FabricNode().version), str(FabricNode().uuid),
        str(FabricNode().group_uuid), machine_group_uuid
    )
    assert len(reserved_meta) == len(reserved_value)
    if parameters['meta']:
        parameters['meta'] = kv_to_dict(parameters['meta'])
        if any(key in reserved_meta for key in parameters['meta'].iterkeys()):
            raise ConfigurationError(
                "The meta parameter cannot have keywords in the following "
                "list: %s. They are reserved for internal use." %
                (str(reserved_meta), )
            )
    else:
        parameters['meta'] = {}

    meta = dict(zip(reserved_meta, reserved_value))
    parameters['meta'].update(meta)