Пример #1
0
    def validate_config_data(cls, config_data_dict):
        """Validates distributor config data.

        This will validate a distributor config dataset against the config
        settings the distributor l3 driver supports.

        :param config_data_dict: The config data dictionary to validate.
        :type config_data: dict
        :return: None
        :raises DriverError: An unexpected error occurred.
        :raises UnsupportedOptionError: If the driver does not support
          one of the config_data settings.
        """
        try:
            validate(config_data_dict, config_data_schema.SCHEMAS)
        except js_exceptions.ValidationError as e:
            error_object = ''
            if e.relative_path:
                error_object = '{} '.format(e.relative_path[0])
            raise exceptions.UnsupportedOptionError(
                user_fault_string='{0}{1}'.format(error_object, e.message),
                operator_fault_string=str(e))
        except Exception as e:
            raise exceptions.DriverError(
                user_fault_string='Failed to validate the distributor '
                'config data due to: {}'.format(str(e)),
                operator_fault_string='Failed to validate the distributor '
                'config data due to: {}'.format(str(e)))
Пример #2
0
    def test_DriverError(self):
        driver_error = exceptions.DriverError(
            user_fault_string=self.user_fault_string,
            operator_fault_string=self.operator_fault_string)

        self.assertEqual(self.user_fault_string,
                         driver_error.user_fault_string)
        self.assertEqual(self.operator_fault_string,
                         driver_error.operator_fault_string)
        self.assertIsInstance(driver_error, Exception)
Пример #3
0
    def create_vip_port(self, loadbalancer_id, project_id, vip_dictionary):
        vip_obj = driver_utils.provider_vip_dict_to_vip_obj(vip_dictionary)
        lb_obj = data_models.LoadBalancer(id=loadbalancer_id,
                                          project_id=project_id, vip=vip_obj)

        network_driver = utils.get_network_driver()
        try:
            vip = network_driver.allocate_vip(lb_obj)
        except network_base.AllocateVIPException as e:
            raise exceptions.DriverError(user_fault_string=e.orig_msg,
                                         operator_fault_string=e.orig_msg)

        LOG.info('Amphora provider created VIP port %s for load balancer %s.',
                 vip.port_id, loadbalancer_id)
        return driver_utils.vip_dict_to_provider_dict(vip.to_dict())
Пример #4
0
    def get_supported_flavor_metadata(self):
        """Returns the valid flavor metadata keys and descriptions.

        This extracts the valid flavor metadata keys and descriptions
        from the JSON validation schema and returns it as a dictionary.

        :return: Dictionary of flavor metadata keys and descriptions.
        :raises DriverError: An unexpected error occurred.
        """
        try:
            props = flavor_schema.SUPPORTED_FLAVOR_SCHEMA['properties']
            return {k: v.get('description', '') for k, v in props.items()}
        except Exception as e:
            raise exceptions.DriverError(
                user_fault_string='Failed to get the supported flavor '
                'metadata due to: {}'.format(str(e)),
                operator_fault_string='Failed to get the supported flavor '
                'metadata due to: {}'.format(str(e)))
Пример #5
0
    def get_supported_config_data(cls):
        """Returns the valid l3 distributor config data keys and descriptions.

        This extracts the valid config data keys and descriptions
        from the JSON validation schema and returns it as a dictionary.

        :return: Dictionary of config data keys and descriptions.
        :raises DriverError: An unexpected error occurred.
        """
        try:
            props = config_data_schema.SCHEMAS['properties']
            return {k: v.get('description', '') for k, v in props.items()}
        except Exception as e:
            raise exceptions.DriverError(
                user_fault_string='Failed to get the supported distributor '
                'config data due to: {}'.format(str(e)),
                operator_fault_string='Failed to get the supported '
                'distributor config data due '
                'to: {}'.format(str(e)))
Пример #6
0
    def validate_flavor(self, flavor_dict):
        """Validates flavor profile data.

        This will validate a flavor profile dataset against the flavor
        settings the amphora driver supports.

        :param flavor_dict: The flavor dictionary to validate.
        :type flavor: dict
        :return: None
        :raises DriverError: An unexpected error occurred.
        :raises UnsupportedOptionError: If the driver does not support
          one of the flavor settings.
        """
        try:
            validate(flavor_dict, flavor_schema.SUPPORTED_FLAVOR_SCHEMA)
        except js_exceptions.ValidationError as e:
            error_object = ''
            if e.relative_path:
                error_object = '{} '.format(e.relative_path[0])
            raise exceptions.UnsupportedOptionError(
                user_fault_string='{0}{1}'.format(error_object, e.message),
                operator_fault_string=str(e))
        except Exception as e:
            raise exceptions.DriverError(
                user_fault_string='Failed to validate the flavor metadata '
                'due to: {}'.format(str(e)),
                operator_fault_string='Failed to validate the flavor metadata '
                'due to: {}'.format(str(e)))
        compute_flavor = flavor_dict.get(consts.COMPUTE_FLAVOR, None)
        if compute_flavor:
            compute_driver = stevedore_driver.DriverManager(
                namespace='octavia.compute.drivers',
                name=CONF.controller_worker.compute_driver,
                invoke_on_load=True).driver

            # TODO(johnsom) Fix this to raise a NotFound error
            # when the octavia-lib supports it.
            compute_driver.validate_flavor(compute_flavor)