def create_network_precommit(self, context):
        """Allocate resources for a new network.

        :param context: NetworkContext instance describing the new
        network.

        Create a new network, allocating resources as necessary in the
        database. Called inside transaction context on session. Call
        cannot block.  Raising an exception will result in a rollback
        of the current transaction.
        """
        vnh = self.handlers[Hndl.VirtualNetwork]
        logger.info("Function '%s' context is: %s" %
                    (sys._getframe().f_code.co_name, dump(context)))
        vn_obj = vnh.neutron_dict_to_vn(vnh.create_vn_obj(context.current),
                                        context.current)
        # Force contrail to use same uuid as neutron (easier update/delete)
        vn_obj.uuid = context.current['id']
        net = self._vnc_lib.virtual_network_create(vn_obj)
        if vn_obj.router_external:
            fip_pool_obj = vnc_api.FloatingIpPool('floating-ip-pool', vn_obj)
            self._vnc_lib.floating_ip_pool_create(fip_pool_obj)
        logger.info("New network returned by contrail: %s" % dump(net))
        logger.info("Net object (%s) ((current is: %s)) is: %s" %
                    (type(vn_obj), type(context.current), dump(vn_obj)))
 def handle_delete(self):
     vnc = vnc_api.VncApi(username = self.properties[self.USER], password = self.properties[self.PASSWORD], 
                          tenant_name = self.properties[self.KEYSTONE_NAME], api_server_host = self.properties[self.API_SERVER])
     tenant = vnc.project_read(fq_name = [self.properties[self.DOMAIN], self.properties[self.TENANT_NAME]])
     vn_public = vnc.virtual_network_read(fq_name = [self.properties[self.DOMAIN], self.properties[self.TENANT_NAME], 
                                                     self.properties[self.PUBLIC_NETWORK]])
     pool = vnc_api.FloatingIpPool(name = self.properties[self.POOL_NAME], parent_obj = vn_public)
     tenant.del_floating_ip_pool(pool)
     vnc.floating_ip_pool_delete(pool.uuid)
     vnc.project_update(tenant)
Пример #3
0
 def _update_external_router_attr(self, router_external, vn_obj):
     if router_external and not vn_obj.router_external:
         fip_pool_obj = vnc_api.FloatingIpPool('floating-ip-pool',
                                               vn_obj)
         self._vnc_lib.floating_ip_pool_create(fip_pool_obj)
     else:
         fip_pools = vn_obj.get_floating_ip_pools()
         for fip_pool in fip_pools or []:
             try:
                 self._vnc_lib.floating_ip_pool_delete(id=fip_pool['uuid'])
             except vnc_api.RefsExistError:
                 self._raise_contrail_exception(
                     'NetworkInUse', net_id=vn_obj.uuid, resource='network')
Пример #4
0
    def resource_create(self, context, network_q):
        contrail_extensions_enabled = self._kwargs.get(
            'contrail_extensions_enabled', False)
        vn_obj = self.neutron_dict_to_vn(self.create_vn_obj(network_q),
                                         network_q)
        self._resource_create(vn_obj)

        if vn_obj.router_external:
            fip_pool_obj = vnc_api.FloatingIpPool('floating-ip-pool', vn_obj)
            self._vnc_lib.floating_ip_pool_create(fip_pool_obj)

        ret_network_q = self.vn_to_neutron_dict(
            vn_obj, contrail_extensions_enabled=contrail_extensions_enabled)

        return ret_network_q
    def handle_create(self):
        parent_obj = None
        if parent_obj is None and self.properties.get(self.VIRTUAL_NETWORK):
            try:
                parent_obj = self.vnc_lib().virtual_network_read(
                    id=self.properties.get(self.VIRTUAL_NETWORK))
            except vnc_api.NoIdError:
                parent_obj = self.vnc_lib().virtual_network_read(
                    fq_name_str=self.properties.get(self.VIRTUAL_NETWORK))
            except:
                parent_obj = None

        if parent_obj is None:
            raise Exception('Error: parent is not specified in template!')

        obj_0 = vnc_api.FloatingIpPool(name=self.properties[self.NAME],
                                       parent_obj=parent_obj)

        if self.properties.get(self.DISPLAY_NAME) is not None:
            obj_0.set_display_name(self.properties.get(self.DISPLAY_NAME))
        if self.properties.get(self.FLOATING_IP_POOL_PREFIXES) is not None:
            obj_1 = vnc_api.FloatingIpPoolType()
            if self.properties.get(self.FLOATING_IP_POOL_PREFIXES, {}).get(
                    self.FLOATING_IP_POOL_PREFIXES_SUBNET) is not None:
                for index_1 in range(
                        len(
                            self.properties.get(
                                self.FLOATING_IP_POOL_PREFIXES, {}).get(
                                    self.FLOATING_IP_POOL_PREFIXES_SUBNET))):
                    obj_2 = vnc_api.SubnetType()
                    if self.properties.get(
                            self.FLOATING_IP_POOL_PREFIXES,
                        {}).get(
                            self.FLOATING_IP_POOL_PREFIXES_SUBNET,
                            {})[index_1].get(
                                self.FLOATING_IP_POOL_PREFIXES_SUBNET_IP_PREFIX
                            ) is not None:
                        obj_2.set_ip_prefix(
                            self.properties.get(
                                self.FLOATING_IP_POOL_PREFIXES,
                                {}).get(self.FLOATING_IP_POOL_PREFIXES_SUBNET,
                                        {})
                            [index_1].get(
                                self.FLOATING_IP_POOL_PREFIXES_SUBNET_IP_PREFIX
                            ))
                    if self.properties.get(
                            self.FLOATING_IP_POOL_PREFIXES,
                        {}).get(
                            self.FLOATING_IP_POOL_PREFIXES_SUBNET, {}
                        )[index_1].get(
                            self.FLOATING_IP_POOL_PREFIXES_SUBNET_IP_PREFIX_LEN
                        ) is not None:
                        obj_2.set_ip_prefix_len(
                            self.properties.get(
                                self.FLOATING_IP_POOL_PREFIXES,
                                {}).get(self.FLOATING_IP_POOL_PREFIXES_SUBNET,
                                        {})
                            [index_1].get(
                                self.
                                FLOATING_IP_POOL_PREFIXES_SUBNET_IP_PREFIX_LEN)
                        )
                    obj_1.add_subnet(obj_2)
            obj_0.set_floating_ip_pool_prefixes(obj_1)

        try:
            obj_uuid = super(ContrailFloatingIpPool,
                             self).resource_create(obj_0)
        except:
            raise Exception(
                _('floating-ip-pool %s could not be updated.') % self.name)

        self.resource_id_set(obj_uuid)