Exemple #1
0
    def deallocate_for_instance(self, context, **kwargs):
        """Called when a VM is terminated.  Loop through each virtual
           interface in the Nova DB and remove the Quantum port and
           clear the IP allocation using the IPAM.  Finally, remove
           the virtual interfaces from the Nova DB.
        """
        instance_id = kwargs.get('instance_id')
        project_id = kwargs.pop('project_id', None)

        admin_context = context.elevated()
        vifs = db.virtual_interface_get_by_instance(admin_context,
                                                    instance_id)

        for vif in vifs:
            network = db.network_get(admin_context, vif['network_id'])

            self.deallocate_port(vif['uuid'], network['uuid'], project_id,
                                 instance_id)

            ipam_tenant_id = self.deallocate_ip_address(context,
                                network['uuid'], project_id, vif, instance_id)

            if FLAGS.quantum_use_dhcp:
                self.update_dhcp(context, ipam_tenant_id, network,
                                 vif, project_id)

            db.virtual_interface_delete(admin_context, vif['id'])
Exemple #2
0
    def deallocate_for_instance(self, context, **kwargs):
        """Called when a VM is terminated.  Loop through each virtual
           interface in the Nova DB and remove the Quantum port and
           clear the IP allocation using the IPAM.  Finally, remove
           the virtual interfaces from the Nova DB.
        """
        instance_id = kwargs.get('instance_id')
        project_id = kwargs.pop('project_id', None)

        admin_context = context.elevated()
        vifs = db.virtual_interface_get_by_instance(admin_context,
                                                    instance_id)

        for vif in vifs:
            network = db.network_get(admin_context, vif['network_id'])

            self.deallocate_port(vif['uuid'], network['uuid'], project_id,
                                 instance_id)

            ipam_tenant_id = self.deallocate_ip_address(context,
                                network['uuid'], project_id, vif, instance_id)

            if FLAGS.quantum_use_dhcp:
                self.update_dhcp(context, ipam_tenant_id, network,
                                 vif, project_id)

            db.virtual_interface_delete(admin_context, vif['id'])
Exemple #3
0
 def delete(self, context):
     """
     PF9 function
     :param context:
     :return:
     """
     db.virtual_interface_delete(context, self.id)
Exemple #4
0
    def deallocate_for_instance(self, context, **kwargs):
        """Called when a VM is terminated.  Loop through each virtual
           interface in the Nova DB and remove the Quantum port and
           clear the IP allocation using the IPAM.  Finally, remove
           the virtual interfaces from the Nova DB.
        """
        instance_id = kwargs.get("instance_id")
        project_id = kwargs.pop("project_id", None)

        admin_context = context.elevated()
        vifs = db.virtual_interface_get_by_instance(admin_context, instance_id)
        for vif_ref in vifs:
            interface_id = vif_ref["uuid"]
            q_tenant_id = project_id

            network_ref = db.network_get(admin_context, vif_ref["network_id"])
            net_id = network_ref["uuid"]

            # port deallocate block
            try:
                port_id = None
                port_id = self.q_conn.get_port_by_attachment(q_tenant_id, net_id, interface_id)
                if not port_id:
                    q_tenant_id = FLAGS.quantum_default_tenant_id
                    port_id = self.q_conn.get_port_by_attachment(q_tenant_id, net_id, interface_id)

                if not port_id:
                    LOG.error("Unable to find port with attachment: %s" % (interface_id))
                else:
                    self.q_conn.detach_and_delete_port(q_tenant_id, net_id, port_id)
            except:
                # except anything so the rest of deallocate can succeed
                msg = _("port deallocation failed for instance: " "|%(instance_id)s|, port_id: |%(port_id)s|")
                LOG.critical(msg % locals())

            # ipam deallocation block
            try:
                ipam_tenant_id = self.ipam.get_tenant_id_by_net_id(context, net_id, vif_ref["uuid"], project_id)

                self.ipam.deallocate_ips_by_vif(context, ipam_tenant_id, net_id, vif_ref)
                db.virtual_interface_delete(admin_context, vif_ref["id"])

                # If DHCP is enabled on this network then we need to update the
                # leases and restart the server.
                if FLAGS.quantum_use_dhcp:
                    self.update_dhcp(context, ipam_tenant_id, network_ref, vif_ref, project_id)
            except:
                # except anything so the rest of deallocate can succeed
                vif_uuid = vif_ref["uuid"]
                msg = _("ipam deallocation failed for instance: " "|%(instance_id)s|, vif_uuid: |%(vif_uuid)s|")
                LOG.critical(msg % locals())
Exemple #5
0
    def deallocate_for_instance(self, context, **kwargs):
        """Called when a VM is terminated.  Loop through each virtual
           interface in the Nova DB and remove the Quantum port and
           clear the IP allocation using the IPAM.  Finally, remove
           the virtual interfaces from the Nova DB.
        """
        instance_id = kwargs.get('instance_id')
        project_id = kwargs.pop('project_id', None)

        admin_context = context.elevated()
        vifs = db.virtual_interface_get_by_instance(admin_context, instance_id)

        for vif in vifs:
            network = db.network_get(admin_context, vif['network_id'])

            self.deallocate_port(vif['uuid'], network['uuid'], project_id,
                                 instance_id)

            ipam_tenant_id = self.deallocate_ip_address(
                context, network['uuid'], project_id, vif, instance_id)

            if FLAGS.quantum_use_dhcp:
                if network['host'] == self.host:
                    self.update_dhcp(context, ipam_tenant_id, network, vif,
                                     project_id)
                else:
                    topic = self.db.queue_get_for(context, FLAGS.network_topic,
                                                  network['host'])
                    rpc.call(
                        context, topic, {
                            'method': 'update_dhcp',
                            'args': {
                                'ipam_tenant_id': ipam_tenant_id,
                                'network_ref': network,
                                'vif_ref': vif,
                                'project_id': network['project_id']
                            }
                        })

            db.virtual_interface_delete(admin_context, vif['id'])
Exemple #6
0
    def deallocate_for_instance(self, context, **kwargs):
        """Called when a VM is terminated.  Loop through each virtual
           interface in the Nova DB and remove the Quantum port and
           clear the IP allocation using the IPAM.  Finally, remove
           the virtual interfaces from the Nova DB.
        """
        instance_id = kwargs.get("instance_id")
        project_id = kwargs.pop("project_id", None)

        admin_context = context.elevated()
        vifs = db.virtual_interface_get_by_instance(admin_context, instance_id)

        for vif in vifs:
            network = db.network_get(admin_context, vif["network_id"])

            self.deallocate_port(vif["uuid"], network["uuid"], project_id, instance_id)

            ipam_tenant_id = self.deallocate_ip_address(context, network["uuid"], project_id, vif, instance_id)

            if FLAGS.quantum_use_dhcp:
                if network["host"] == self.host:
                    self.update_dhcp(context, ipam_tenant_id, network, vif, project_id)
                else:
                    topic = self.db.queue_get_for(context, FLAGS.network_topic, network["host"])
                    rpc.call(
                        context,
                        topic,
                        {
                            "method": "update_dhcp",
                            "args": {
                                "ipam_tenant_id": ipam_tenant_id,
                                "network_ref": network,
                                "vif_ref": vif,
                                "project_id": network["project_id"],
                            },
                        },
                    )

            db.virtual_interface_delete(admin_context, vif["id"])
Exemple #7
0
    def deallocate_for_instance(self, context, **kwargs):
        """Called when a VM is terminated.  Loop through each virtual
           interface in the Nova DB and remove the Quantum port and
           clear the IP allocation using the IPAM.  Finally, remove
           the virtual interfaces from the Nova DB.
        """
        instance_id = kwargs.get('instance_id')
        project_id = kwargs.pop('project_id', None)

        admin_context = context.elevated()
        instance = db.instance_get(context, instance_id)
        vifs = db.virtual_interface_get_by_instance(admin_context,
                                                    instance['uuid'])

        for vif in vifs:
            network = db.network_get(admin_context, vif['network_id'])

            self.deallocate_port(vif['uuid'], network['uuid'], project_id,
                                 instance_id)

            ipam_tenant_id = self.deallocate_ip_address(context,
                                network['uuid'], project_id, vif, instance_id)

            if FLAGS.quantum_use_dhcp:
                if network['host'] == self.host:
                    self.update_dhcp(context, ipam_tenant_id, network,
                                 vif, project_id)
                else:
                    topic = rpc.queue_get_for(context,
                                FLAGS.network_topic, network['host'])
                    rpc.call(context, topic, {'method': 'update_dhcp',
                        'args': {'ipam_tenant_id': ipam_tenant_id,
                        'network_ref': network,
                        'vif_ref': vif,
                        'project_id': network['project_id']}})

            db.virtual_interface_delete(admin_context, vif['id'])
 def destroy(self):
     db.virtual_interface_delete(self._context, self.id)