コード例 #1
0
    def add_resource_association(self, context, service_type, provider_name,
                                 resource_id, expire_session=True):
        r = self.get_service_providers(context,
                                       filters={'service_type': [service_type],
                                                'name': [provider_name]})
        if not r:
            raise pconf.ServiceProviderNotFound(provider=provider_name,
                                                service_type=service_type)

        # we don't actually need service type for association.
        # resource_id is unique and belongs to specific service
        # which knows its type
        servicetype_obj.ProviderResourceAssociation(
            context, provider_name=provider_name,
            resource_id=resource_id).create()
        # NOTE(blogan): the ProviderResourceAssociation relationship will not
        # be populated if a resource was created before this.  The expire_all
        # will force the session to go retrieve the new data when that
        # resource will be read again.  It has been suggested that we can
        # crawl through everything in the mapper to find the resource with
        # the ID that matches resource_id and expire that one, but we can
        # just start with this.
        # NOTE(ralonsoh): to be removed once the new engine facade is fully
        # implanted in Neutron.
        if expire_session:
            context.session.expire_all()
コード例 #2
0
    def add_resource_association(self, context, service_type, provider_name,
                                 resource_id):
        r = self.get_service_providers(context,
                                       filters={
                                           'service_type': [service_type],
                                           'name': [provider_name]
                                       })
        if not r:
            raise pconf.ServiceProviderNotFound(provider=provider_name,
                                                service_type=service_type)

        with context.session.begin(subtransactions=True):
            # we don't actually need service type for association.
            # resource_id is unique and belongs to specific service
            # which knows its type
            assoc = st_model.ProviderResourceAssociation(
                provider_name=provider_name, resource_id=resource_id)
            context.session.add(assoc)
        # NOTE(blogan): the ProviderResourceAssociation relationship will not
        # be populated if a resource was created before this.  The expire_all
        # will force the session to go retrieve the new data when that
        # resource will be read again.  It has been suggested that we can
        # crawl through everything in the mapper to find the resource with
        # the ID that matches resource_id and expire that one, but we can
        # just start with this.
        context.session.expire_all()
コード例 #3
0
 def check_provider_exists(self, provider_name):
     """
     Check if service-appliance-set for provider exists in the API
     """
     try:
         sas_fq_name = ["default-global-system-config"]
         sas_fq_name.append(provider_name)
         sas_obj = self._api.service_appliance_set_read(fq_name=sas_fq_name)
     except NoIdError:
         raise pconf.ServiceProviderNotFound(
             provider=provider_name, service_type=constants.LOADBALANCER)
     return sas_obj
コード例 #4
0
    def create(self, context, pool):
        """
        Create a loadbalancer_pool object.
        """
        p = pool['pool']
        try:
            sas_fq_name = ["default-global-system-config"]
            sas_fq_name.append(p['provider'])
            sas_obj = self._api.service_appliance_set_read(fq_name=sas_fq_name)
        except NoIdError:
            raise pconf.ServiceProviderNotFound(
                provider=p['provider'], service_type=constants.LOADBALANCER)

        tenant_id = self._get_tenant_id_for_create(context, p)
        project = self._project_read(project_id=tenant_id)

        if p['listener_id']:
            try:
                ll = self._api.loadbalancer_listener_read(id=p['listener_id'])
            except NoIdError:
                raise loadbalancerv2.EntityNotFound(name='Listener',
                                                    id=p['listener_id'])
            project_id = ll.parent_uuid
            if str(uuid.UUID(tenant_id)) != project_id:
                raise n_exc.NotAuthorized()
        else:
            ll = None

        pool_uuid = uuidutils.generate_uuid()
        name = self._get_resource_name('loadbalancer-pool', project, p['name'],
                                       pool_uuid)
        props = self.make_properties(p)
        id_perms = IdPermsType(enable=True, description=p['description'])
        pool = LoadbalancerPool(name,
                                project,
                                loadbalancer_pool_properties=props,
                                loadbalancer_pool_provider=p['provider'],
                                id_perms=id_perms,
                                display_name=p['name'])
        pool.uuid = pool_uuid

        pool.set_service_appliance_set(sas_obj)

        if ll:
            pool_exists = ll.get_loadbalancer_pool_back_refs()
            if pool_exists is not None:
                raise loadbalancerv2.OnePoolPerListener(
                    listener_id=p['listener_id'],
                    pool_id=pool_exists[0]['uuid'])
            pool.set_loadbalancer_listener(ll)

        self._api.loadbalancer_pool_create(pool)
        return self.make_dict(pool)
コード例 #5
0
    def add_resource_association(self, context, service_type, provider_name,
                                 resource_id):
        r = self.conf.get_service_providers(
            filters={'service_type': service_type, 'name': provider_name})
        if not r:
            raise pconf.ServiceProviderNotFound(service_type=service_type)

        with context.session.begin(subtransactions=True):
            # we don't actually need service type for association.
            # resource_id is unique and belongs to specific service
            # which knows its type
            assoc = ProviderResourceAssociation(provider_name=provider_name,
                                                resource_id=resource_id)
            context.session.add(assoc)
コード例 #6
0
    def create(self, context, pool):
        """
        Create a loadbalancer_pool object.
        """
        p = pool['pool']
        try:
            sas_fq_name = ["default-global-system-config"]
            sas_fq_name.append(p['provider'])
            sas_obj = self._api.service_appliance_set_read(fq_name=sas_fq_name)
        except NoIdError:
            raise pconf.ServiceProviderNotFound(
                provider=p['provider'], service_type=constants.LOADBALANCER)

        tenant_id = self._get_tenant_id_for_create(context, p)
        project = self._project_read(project_id=tenant_id)

        uuid = uuidutils.generate_uuid()
        name = self._get_resource_name('loadbalancer-pool', project, p['name'],
                                       uuid)
        props = self.make_properties(p)
        id_perms = IdPermsType(enable=True, description=p['description'])
        pool = LoadbalancerPool(name,
                                project,
                                loadbalancer_pool_properties=props,
                                loadbalancer_pool_provider=p['provider'],
                                id_perms=id_perms,
                                display_name=p['name'])
        pool.uuid = uuid

        if p['health_monitors']:
            for hm in p['health_monitors']:
                try:
                    mon = self._api.loadbalancer_healthmonitor_read(id=hm)
                except NoIdError:
                    raise loadbalancer.HealthMonitorNotFound(monitor_id=hm)
                pool.add_loadbalancer_healthmonitor(mon)

        pool.set_service_appliance_set(sas_obj)

        # Custom attributes
        if p['custom_attributes'] != attr.ATTR_NOT_SPECIFIED:
            custom_attributes = KeyValuePairs()
            self.create_update_custom_attributes(p['custom_attributes'],
                                                 custom_attributes)
            pool.set_loadbalancer_pool_custom_attributes(custom_attributes)

        self._api.loadbalancer_pool_create(pool)
        return self.make_dict(pool)
コード例 #7
0
 def validate_provider(self, provider):
     if provider not in self.drivers:
         raise pconf.ServiceProviderNotFound(
             provider=provider, service_type=constants.LOADBALANCER)