コード例 #1
0
    def _create_fip_obj(self, fip_q):
        # TODO() for now create from default pool, later
        # use first available pool on net
        net_id = fip_q['floating_network_id']
        try:
            fq_name = self._vnc_lib.floating_ip_pools_list(
                parent_id=net_id)['floating-ip-pools'][0]['fq_name']
        except IndexError:
            # IndexError could happens when an attempt to
            # retrieve a floating ip pool from a private network.
            msg = "Network %s doesn't provide a floatingip pool" % net_id
            self._raise_contrail_exception('BadRequest',
                                           resource="floatingip", msg=msg)

        fip_pool_obj = self._vnc_lib.floating_ip_pool_read(fq_name=fq_name)
        fip_name = str(uuid.uuid4())
        fip_obj = vnc_api.FloatingIp(fip_name, fip_pool_obj)
        fip_obj.uuid = fip_name

        proj_id = self._project_id_neutron_to_vnc(fip_q['tenant_id'])
        proj_obj = self._project_read(proj_id=proj_id)
        fip_obj.set_project(proj_obj)
        return fip_obj
コード例 #2
0
    def handle_create(self):
        parent_obj = None
        if parent_obj is None and self.properties.get(self.FLOATING_IP_POOL):
            try:
                parent_obj = self.vnc_lib().floating_ip_pool_read(
                    id=self.properties.get(self.FLOATING_IP_POOL))
            except vnc_api.NoIdError:
                parent_obj = self.vnc_lib().floating_ip_pool_read(
                    fq_name_str=self.properties.get(self.FLOATING_IP_POOL))
            except:
                parent_obj = None

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

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

        if self.properties.get(self.FLOATING_IP_ADDRESS_FAMILY) is not None:
            obj_0.set_floating_ip_address_family(
                self.properties.get(self.FLOATING_IP_ADDRESS_FAMILY))
        if self.properties.get(self.FLOATING_IP_IS_VIRTUAL_IP) is not None:
            obj_0.set_floating_ip_is_virtual_ip(
                self.properties.get(self.FLOATING_IP_IS_VIRTUAL_IP))
        if self.properties.get(self.FLOATING_IP_ADDRESS) is not None:
            obj_0.set_floating_ip_address(
                self.properties.get(self.FLOATING_IP_ADDRESS))
        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_FIXED_IP_ADDRESS) is not None:
            obj_0.set_floating_ip_fixed_ip_address(
                self.properties.get(self.FLOATING_IP_FIXED_IP_ADDRESS))

        # reference to project_refs
        if self.properties.get(self.PROJECT_REFS):
            for index_0 in range(len(self.properties.get(self.PROJECT_REFS))):
                try:
                    ref_obj = self.vnc_lib().project_read(
                        id=self.properties.get(self.PROJECT_REFS)[index_0])
                except vnc_api.NoIdError:
                    ref_obj = self.vnc_lib().project_read(
                        fq_name_str=self.properties.get(
                            self.PROJECT_REFS)[index_0])
                obj_0.add_project(ref_obj)

        # reference to virtual_machine_interface_refs
        if self.properties.get(self.VIRTUAL_MACHINE_INTERFACE_REFS):
            for index_0 in range(
                    len(
                        self.properties.get(
                            self.VIRTUAL_MACHINE_INTERFACE_REFS))):
                try:
                    ref_obj = self.vnc_lib().virtual_machine_interface_read(
                        id=self.properties.get(
                            self.VIRTUAL_MACHINE_INTERFACE_REFS)[index_0])
                except vnc_api.NoIdError:
                    ref_obj = self.vnc_lib().virtual_machine_interface_read(
                        fq_name_str=self.properties.get(
                            self.VIRTUAL_MACHINE_INTERFACE_REFS)[index_0])
                obj_0.add_virtual_machine_interface(ref_obj)

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

        self.resource_id_set(obj_uuid)