Example #1
0
    def _load_config(self):
        # Global defaults
        for dk, dv in defaults.GLOBAL_DEFAULTS.items():
            if not hasattr(self._config, dk):
                LOG.debug("setting global default %s=%s", dk, dv)
                setattr(self._config, dk, dv)
            else:
                LOG.debug("global setting %s=%s", dk,
                          getattr(self._config, dk))

        self._devices = {}
        for k, v in self._config.devices.items():
            if 'status' in v and not v['status']:
                LOG.debug("status is False, skipping dev: %s", v)
            else:
                for x in defaults.DEVICE_REQUIRED_FIELDS:
                    if x not in v:
                        msg = "device %s missing required value %s, skipping" % (
                            k, x)
                        LOG.error(msg)
                        raise a10_ex.InvalidDeviceConfig(msg)

                v['key'] = k
                self._devices[k] = v

                # Old configs had a name field
                if 'name' not in v:
                    self._devices[k]['name'] = k

                # Figure out port and protocol
                protocol = self._devices[k].get('protocol', 'https')
                port = self._devices[k].get('port', {
                    'http': 80,
                    'https': 443
                }[protocol])
                self._devices[k]['protocol'] = protocol
                self._devices[k]['port'] = port

                # Device defaults
                for dk, dv in defaults.DEVICE_OPTIONAL_DEFAULTS.items():
                    if dk not in self._devices[k]:
                        self._devices[k][dk] = dv

                LOG.debug("A10Config, device %s=%s", k, self._devices[k])

        self._vthunder = None
        if hasattr(self._config, 'vthunder'):
            self._vthunder = self._config.vthunder

            for x in defaults.VTHUNDER_REQUIRED_FIELDS:
                if x not in self._vthunder:
                    msg = "vthunder definition missing required value %s, skipping" % x
                    LOG.error(msg)
                    raise a10_ex.InvalidDeviceConfig(msg)

            # vThunder defaults
            for vk, vv in defaults.VTHUNDER_OPTIONAL_DEFAULTS.items():
                if vk not in self._vthunder:
                    self._vthunder[vk] = vv
            for dk, dv in defaults.DEVICE_OPTIONAL_DEFAULTS.items():
                if dk not in self._vthunder:
                    self._vthunder[dk] = dv

        # Setup db foo
        if self._config.use_database and self._config.database_connection is None:
            self._config.database_connection = self._get_neutron_db_string()

        if self._config.keystone_auth_url is None:
            self._config.keystone_auth_url = self._get_neutron_conf(
                'keystone_authtoken', 'auth_uri')

        # Setup some backwards compat stuff
        self.config = OldConfig(self)
Example #2
0
    def _load_config(self):
        # Global defaults
        for dk, dv in defaults.GLOBAL_DEFAULTS.items():
            if not hasattr(self._config, dk):
                LOG.debug("setting global default %s=%s", dk, dv)
                setattr(self._config, dk, dv)
            else:
                LOG.debug("global setting %s=%s", dk,
                          getattr(self._config, dk))

        self._devices = {}
        if not hasattr(self._config, "devices"):
            self._config.devices = {}

        for k, v in self._config.devices.items():
            if 'status' in v and not v['status']:
                LOG.debug("status is False, skipping dev: %s", v)
            else:
                for x in defaults.DEVICE_REQUIRED_FIELDS:
                    if x not in v:
                        msg = "device %s missing required value %s, skipping" % (
                            k, x)
                        LOG.error(msg)
                        raise a10_ex.InvalidDeviceConfig(msg)

                v['key'] = k
                self._devices[k] = v

                # Old configs had a name field
                if 'name' not in v:
                    self._devices[k]['name'] = k

                # Figure out port and protocol
                protocol = self._devices[k].get('protocol', 'https')
                port = self._devices[k].get('port', {
                    'http': 80,
                    'https': 443
                }[protocol])
                self._devices[k]['protocol'] = protocol
                self._devices[k]['port'] = port

                # Device defaults
                for dk, dv in defaults.DEVICE_OPTIONAL_DEFAULTS.items():
                    if dk not in self._devices[k]:
                        self._devices[k][dk] = dv

                LOG.debug("A10Config, device %s=%s", k, self._devices[k])

        self._vthunder = None

        if hasattr(self._config, 'vthunder'):
            self._vthunder = self._config.vthunder

            for x in defaults.VTHUNDER_REQUIRED_FIELDS:
                if x not in self._vthunder:
                    msg = "vthunder definition missing required value %s, skipping" % x
                    LOG.error(msg)
                    raise a10_ex.InvalidDeviceConfig(msg)

            # vThunder defaults
            for vk, vv in defaults.VTHUNDER_OPTIONAL_DEFAULTS.items():
                if vk not in self._vthunder:
                    self._vthunder[vk] = vv
            for dk, dv in defaults.DEVICE_OPTIONAL_DEFAULTS.items():
                if dk not in self._vthunder:
                    self._vthunder[dk] = dv

        # Setup db foo
        if self._config.use_database and self._config.database_connection is None:
            self._config.database_connection = self._get_neutron_db_string()

        if self._config.keystone_auth_url is None:
            self._config.keystone_auth_url = self._get_neutron_conf(
                'keystone_authtoken', 'auth_uri')

        # TODO(mdurrant) - There's a way to do this with getattr/setattr
        self._vport_defaults = {}
        if hasattr(self._config, "vport_defaults"):
            self._vport_defaults = self._config.vport_defaults

        self._vport_expressions = {}
        if hasattr(self._config, "vport_expressions"):
            self._vport_expressions = self._config.vport_expressions

        self._virtual_server_expressions = {}
        if hasattr(self._config, "virtual_server_expressions"):
            self._virtual_server_expressions = self._config.virtual_server_expressions

        self._service_group_expressions = {}
        if hasattr(self._config, "service_group_expressions"):
            self._service_group_expressions = self._config.service_group_expressions

        self._member_expressions = {}
        if hasattr(self._config, "member_expressions"):
            self._member_expressions = self._config.member_expressions

        self._monitor_expressions = {}
        if hasattr(self._config, "monitor_expressions"):
            self._monitor_expressions = self._config.monitor_expressions

        # self._vlan_interfaces = {}
        # if hasattr(self._config, "vlan_interfaces"):
        #    self._vlan_interfaces = self._config.vlan_interfaces

        self._plumb_vlan_dhcp = False
        if hasattr(self._config, "plumb_vlan_dhcp"):
            self._plumb_vlan_dhcp = self._config.plumb_vlan_dhcp

        self._vlan_binding_level = None
        if hasattr(self._config, "vlan_binding_level"):
            self._vlan_binding_level = self._config.vlan_binding_level

        # Setup some backwards compat stuff
        self.config = OldConfig(self)
Example #3
0
    def __init__(self, config_name='config'):
        # Look for config in the virtual environment
        # virtualenv puts the original prefix in sys.real_prefix
        # pyenv puts it in sys.base_prefix
        venv_d = os.path.join(sys.prefix, 'etc/a10')
        has_prefix = (hasattr(sys, 'real_prefix')
                      or hasattr(sys, 'base_prefix'))
        env_override = os.environ.get('A10_CONFIG_DIR', None)
        if config_name is None:
            config_name = 'config'
        #if config_name is not None:
        #    d = config_name
        #elif env_override is not None:
        #    d = env_override
        #elif has_prefix and os.path.exists(venv_d):
        #    d = venv_d
        #elif os.path.exists('/etc/neutron/services/loadbalancer/a10networks'):
        if os.path.exists('/etc/neutron/services/loadbalancer/a10networks'):
            d = '/etc/neutron/services/loadbalancer/a10networks'
        else:
            d = '/etc/a10'
        self._config_dir = os.environ.get('A10_CONFIG_DIR', d)

        real_sys_path = sys.path
        sys.path = [self._config_dir]
        try:
            try:
                f, path, description = imp.find_module(config_name)
                self._config = imp.load_module(config_name, f, path,
                                               description)
                LOG.info("config loaded succesfuly: " + str(config_name))
            except ImportError as e:
                LOG.error("A10Config could not find %s/%s", self._config_dir,
                          config_name)
                self._config = blank_config

            # Global defaults
            for dk, dv in defaults.GLOBAL_DEFAULTS.items():
                if not hasattr(self._config, dk):
                    LOG.debug("setting global default %s=%s", dk, dv)
                    setattr(self._config, dk, dv)
                else:
                    LOG.debug("global setting %s=%s", dk,
                              getattr(self._config, dk))

            self._devices = {}
            for k, v in self._config.devices.items():
                if 'status' in v and not v['status']:
                    LOG.debug("status is False, skipping dev: %s", v)
                else:
                    for x in defaults.DEVICE_REQUIRED_FIELDS:
                        if x not in v:
                            msg = "device %s missing required value %s, skipping" % (
                                k, x)
                            LOG.error(msg)
                            raise a10_ex.InvalidDeviceConfig(msg)

                    v['key'] = k
                    self._devices[k] = v

                    # Old configs had a name field
                    if 'name' not in v:
                        self._devices[k]['name'] = k

                    # Figure out port and protocol
                    protocol = self._devices[k].get('protocol', 'https')
                    port = self._devices[k].get('port', {
                        'http': 80,
                        'https': 443
                    }[protocol])
                    self._devices[k]['protocol'] = protocol
                    self._devices[k]['port'] = port

                    # Device defaults
                    for dk, dv in defaults.DEVICE_OPTIONAL_DEFAULTS.items():
                        if dk not in self._devices[k]:
                            self._devices[k][dk] = dv

                    LOG.debug("A10Config, device %s=%s", k, self._devices[k])

            # Setup db foo
            if self._config.use_database and self._config.database_connection is None:
                self._config.database_connection = self._get_neutron_db_string(
                )

            # Setup some backwards compat stuff
            self.config = OldConfig(self)

        finally:
            sys.path = real_sys_path