Beispiel #1
0
    def _create_hosting_device_templates_from_config(self):
        """To be called late during plugin initialization so that any hosting
        device templates defined in the config file is properly inserted in
        the DB.
        """
        hdt_dict = config.get_specific_config('cisco_hosting_device_template')
        attr_info = ciscohostingdevicemanager.RESOURCE_ATTRIBUTE_MAP[
            ciscohostingdevicemanager.DEVICE_TEMPLATES]
        adm_context = neutron_context.get_admin_context()

        for hdt_uuid, kv_dict in hdt_dict.items():
            # ensure hdt_uuid is properly formatted
            hdt_uuid = config.uuidify(hdt_uuid)
            try:
                self.get_hosting_device_template(adm_context, hdt_uuid)
                is_create = False
            except ciscohostingdevicemanager.HostingDeviceTemplateNotFound:
                is_create = True
            kv_dict['id'] = hdt_uuid
            kv_dict['tenant_id'] = self.l3_tenant_id()
            config.verify_resource_dict(kv_dict, True, attr_info)
            hdt = {ciscohostingdevicemanager.DEVICE_TEMPLATE: kv_dict}
            try:
                if is_create:
                    self.create_hosting_device_template(adm_context, hdt)
                else:
                    self.update_hosting_device_template(adm_context,
                                                        kv_dict['id'], hdt)
            except n_exc.NeutronException:
                with excutils.save_and_reraise_exception():
                    LOG.error(_LE('Invalid hosting device template definition '
                                  'in configuration file for template = %s'),
                              hdt_uuid)
Beispiel #2
0
 def _obtain_hosting_device_credentials_from_config(self):
     """Obtains credentials from config file and stores them in memory.
     To be called before hosting device templates defined in the config file
     are created.
     """
     cred_dict = config.get_specific_config(
         'cisco_hosting_device_credential')
     attr_info = {
         'name': {'allow_post': True, 'allow_put': True,
                  'validate': {'type:string': None}, 'is_visible': True,
                  'default': ''},
         'description': {'allow_post': True, 'allow_put': True,
                         'validate': {'type:string': None},
                         'is_visible': True, 'default': ''},
         'user_name': {'allow_post': True, 'allow_put': True,
                       'validate': {'type:string': None},
                       'is_visible': True, 'default': ''},
         'password': {'allow_post': True, 'allow_put': True,
                      'validate': {'type:string': None},
                      'is_visible': True, 'default': ''},
         'type': {'allow_post': True, 'allow_put': True,
                  'validate': {'type:string': None}, 'is_visible': True,
                  'default': ''}}
     self._credentials = {}
     for cred_uuid, kv_dict in cred_dict.items():
         # ensure cred_uuid is properly formatted
         cred_uuid = config.uuidify(cred_uuid)
         config.verify_resource_dict(kv_dict, True, attr_info)
         self._credentials[cred_uuid] = kv_dict
Beispiel #3
0
    def _create_hosting_devices_from_config(self):
        """To be called late during plugin initialization so that any hosting
        device specified in the config file is properly inserted in the DB.
        """
        hd_dict = config.get_specific_config('cisco_hosting_device')
        attr_info = ciscohostingdevicemanager.RESOURCE_ATTRIBUTE_MAP[
            ciscohostingdevicemanager.DEVICES]
        adm_context = neutron_context.get_admin_context()

        for hd_uuid, kv_dict in hd_dict.items():
            # ensure hd_uuid is properly formatted
            hd_uuid = config.uuidify(hd_uuid)
            try:
                old_hd = self.get_hosting_device(adm_context, hd_uuid)
                is_create = False
            except ciscohostingdevicemanager.HostingDeviceNotFound:
                old_hd = {}
                is_create = True
            kv_dict['id'] = hd_uuid
            kv_dict['tenant_id'] = self.l3_tenant_id()
            # make sure we keep using same config agent if it has been assigned
            kv_dict['cfg_agent_id'] = old_hd.get('cfg_agent_id')
            # make sure we keep using management port if it exists
            kv_dict['management_port_id'] = old_hd.get('management_port_id')
            config.verify_resource_dict(kv_dict, True, attr_info)
            hd = {ciscohostingdevicemanager.DEVICE: kv_dict}
            try:
                if is_create:
                    self.create_hosting_device(adm_context, hd)
                else:
                    self.update_hosting_device(adm_context, kv_dict['id'], hd)
            except n_exc.NeutronException:
                with excutils.save_and_reraise_exception():
                    LOG.error(_LE('Invalid hosting device specification in '
                                  'configuration file for device = %s'),
                              hd_uuid)