def _create_target(self): tenant_id = "tenant1" net_name = "network1" self.vif_id = "vif1" net = db.network_create(tenant_id, net_name) self.port = db.port_create(net.uuid) db.port_set_attachment(self.port.uuid, net.uuid, self.vif_id)
def plug_interface(self, tenant_id, net_id, port_id, remote_interface_id): """ Attaches a remote interface to the specified port on the specified Virtual Network. :returns: None :raises: exception.NetworkNotFound :raises: exception.PortNotFound :raises: exception.AlreadyAttached (? should the network automatically unplug/replug) """ LOG.debug("QuantumRestProxy: plug_interface() called") port = self.get_port(tenant_id, net_id, port_id) self.validate_attachment(tenant_id, net_id, port_id, remote_interface_id) if port['interface_id']: raise exc.PortInUse(net_id=net_id, port_id=port_id, att_id=port['interface_id']) # Update DB db.port_set_attachment(port_id, net_id, remote_interface_id) # update attachment on network controller try: net_name = self.get_network(tenant_id, net_id).name gateway = self.nova.get_gateway(net_id) mac = self.nova.get_mac(remote_interface_id) if gateway is not None: resource = '/tenants/%s/networks/%s' % ( tenant_id, net_id) data = { "network": { "id": net_id, "gateway": gateway, "name": net_name, } } ret = self.servers.put(resource, data) if not self.servers.action_success(ret): raise RemoteRestError(ret[2]) if mac is not None: resource = '/tenants/%s/networks/%s/ports/%s/attachment' % ( tenant_id, net_id, port_id) data = {"attachment": { "id": remote_interface_id, "mac": mac, }} ret = self.servers.put(resource, data) if not self.servers.action_success(ret): raise RemoteRestError(ret[2]) except RemoteRestError as e: LOG.error( 'QuantumRestProxy: Unable to update remote network: %s' % e.message) # undo the connect db.port_unset_attachment(port_id, net_id) raise
def unplug_interface(self, tenant_id, net_id, port_id): db.validate_port_ownership(tenant_id, net_id, port_id) db.port_set_attachment(port_id, net_id, "") db.port_update(port_id, net_id, op_status=OperationalStatus.DOWN) #unplug in port_properties vm_id = None neuca_db.update_port_properties_iface(port_id, vm_id, None)
def plug_interface(self, tenant_id, net_id, port_id, remote_interface_id): """ Attaches a remote interface to the specified port on the specified Virtual Network. """ LOG.debug("FakePlugin.plug_interface() called") port = self._get_port(tenant_id, net_id, port_id) # Validate attachment self._validate_attachment(tenant_id, net_id, port_id, remote_interface_id) if port["interface_id"]: raise exc.PortInUse(net_id=net_id, port_id=port_id, att_id=port["interface_id"]) db.port_set_attachment(port_id, net_id, remote_interface_id)
def plug_interface(self, tenant_id, net_id, port_id, remote_interface_id): """ Attaches a remote interface to the specified port on the specified Virtual Network. """ LOG.debug("LinuxBridgePlugin.plug_interface() called") network = db.network_get(net_id) port = db.port_get(port_id, net_id) attachment_id = port[const.INTERFACEID] if attachment_id: raise exc.PortInUse(port_id=port_id, net_id=net_id, att_id=attachment_id) db.port_set_attachment(port_id, net_id, remote_interface_id)
def plug_interface(self, tenant_id, net_id, port_id, remote_interface_id): """ Attaches a remote interface to the specified port on the specified Virtual Network. """ LOG.debug("FakePlugin.plug_interface() called") port = self._get_port(tenant_id, net_id, port_id) # Validate attachment self._validate_attachment(tenant_id, net_id, port_id, remote_interface_id) if port['interface_id']: raise exc.PortInUse(net_id=net_id, port_id=port_id, att_id=port['interface_id']) db.port_set_attachment(port_id, net_id, remote_interface_id)
def plug_interface(self, tenant_id, net_id, port_id, remote_interface_id): """ Attaches a remote interface to the specified port on the specified Virtual Network. """ LOG.debug("LinuxBridgePlugin.plug_interface() called") db.validate_port_ownership(tenant_id, net_id, port_id) port = db.port_get(port_id, net_id) attachment_id = port[const.INTERFACEID] if attachment_id: raise exc.PortInUse(port_id=port_id, net_id=net_id, att_id=attachment_id) db.port_set_attachment(port_id, net_id, remote_interface_id)
def test_unplug_iface(self): network_id = None port_id = None try: # Load some data into the datbase net = db.network_create(self.tenant_id, self.network_name_1) network_id = net['uuid'] port = db.port_create(net['uuid']) port_id = port['uuid'] db.port_set_attachment(port_id, network_id, "test_iface_id") cli.unplug_iface(self.client, self.tenant_id, network_id, port_id) except: LOG.exception("Exception caught: %s", sys.exc_info()) self.fail("test_plug_iface failed due to an exception") LOG.debug("Operation completed. Verifying result") LOG.debug(self.fake_stdout.content) self._verify_unplug_iface(network_id, port_id)
def TestRuijieVlanUnsetting(): db.clear_db() net = db.network_create("miaosf", "net1") port = db.port_create(net.uuid) db.port_set_attachment(port.uuid, net.uuid, "intf_id") ruijie_db.add_ruijie_switch_eth_binding("192.168.21.35", "0050.56bc.0003", "GigabitEthernet 3/0/20"); ruijie_db.add_ruijie_vm_eth_binding("intf_id", "0050.56bc.0003"); ovs_db.add_vlan_binding(200, net.uuid) ruijie_vlan.set_ruijie_vlan("intf_id", net.uuid) binding = ruijie_db.get_ruijie_vlan_binding("192.168.21.35", "GigabitEthernet 3/0/20", 200) if binding == []: assert 0 ruijie_vlan.unset_ruijie_vlan(net.uuid, port.uuid) binding = ruijie_db.get_ruijie_vlan_binding("192.168.21.35", "GigabitEthernet 3/0/20", 200) if binding != []: assert 0
def plug_interface(self, tenant_id, net_id, port_id, remote_iface_id): db.validate_port_ownership(tenant_id, net_id, port_id) db.port_set_attachment(port_id, net_id, remote_iface_id) iface_properties = remote_iface_id.split('.') LOG.debug("PRUTH: len(iface_properties) = %d" % (len(iface_properties))) if len(iface_properties) >= 2 and tenant_id == self.config.get("NEUCA", "neuca_tenant_id"): # vm_id.vm_iface vm_id = iface_properties[0] vm_mac = iface_properties[1] #vm_mac = str(quantum.common.utils.generate_mac()) else: LOG.debug("PRUTH: not enough iface properites or not neuca: len(iface_properties) = %d, %s" % (len(iface_properties),remote_iface_id)) vm_id = None vm_mac = None neuca_db.update_port_properties_iface(port_id, vm_id, vm_mac)
def test_show_port_with_attach(self): network_id = None port_id = None iface_id = "flavor crystals" try: # Pre-populate data for testing using db api net = db.network_create(self.tenant_id, self.network_name_1) network_id = net['uuid'] port = db.port_create(network_id) port_id = port['uuid'] db.port_set_attachment(port_id, network_id, iface_id) cli.show_port(self.client, self.tenant_id, network_id, port_id) except: LOG.exception("Exception caught: %s", sys.exc_info()) self.fail("test_show_port_with_attach failed due to an exception") LOG.debug("Operation completed. Verifying result") LOG.debug(self.fake_stdout.content) self._verify_show_port(network_id, port_id)
def test_show_network_details(self): iface_id = "flavor crystals" try: # Load some data into the datbase net = db.network_create(self.tenant_id, self.network_name_1) network_id = net['uuid'] port = db.port_create(network_id) port_id = port['uuid'] db.port_set_attachment(port_id, network_id, iface_id) port = db.port_create(network_id) cli.show_net_detail(self.client, self.tenant_id, network_id, self.version) except: LOG.exception("Exception caught: %s", sys.exc_info()) self.fail("test_show_network_details failed due to an exception") LOG.debug("Operation completed. Verifying result") LOG.debug(self.fake_stdout.content) self._verify_show_network_details()
def plug_interface(self, net_id, port_id, int_id): """Plug interface to a port.""" try: port = db.port_set_attachment(port_id, net_id, int_id) LOG.debug("Attached interface to port %s", port.uuid) port_dict = {} port_dict["id"] = str(port.uuid) port_dict["net-id"] = str(port.network_id) port_dict["attachment"] = port.interface_id port_dict["state"] = port.state return port_dict except Exception as exc: LOG.error("Failed to plug interface: %s", str(exc))
def plug_interface(self, net_id, port_id, int_id): """Plug interface to a port""" try: port = db.port_set_attachment(net_id, port_id, int_id) LOG.debug("Attached interface to port %s" % port.uuid) port_dict = {} port_dict["port-id"] = str(port.uuid) port_dict["net-id"] = str(port.network_id) port_dict["int-id"] = port.interface_id port_dict["state"] = port.state return port_dict except Exception, exc: raise Exception("Failed to plug interface: %s" % str(exc))
def plug_interface(self, tenant_id, network_id, port_id, interface_id): """ Attaches a remote interface to the specified port on the specified Virtual Network. """ LOG.debug("plug_interface() called") port = self._get_port(tenant_id, network_id, port_id) # Validate attachment if port.interface_id: raise exc.PortInUse(net_id=network_id, port_id=port_id, att_id=port.interface_id) p = dbe.get_plugged_port(interface_id) if p: raise exc.AlreadyAttached(net_id=network_id, port_id=port_id, att_id=interface_id, att_port_id=p.uuid) db.port_set_attachment(port_id, network_id, interface_id) if self._port_attachable(port): self._attach(tenant_id, network_id, port_id, interface_id)
def unplug_interface(self, tenant_id, net_id, port_id): db.validate_port_ownership(tenant_id, net_id, port_id) db.port_set_attachment(port_id, net_id, "") db.port_update(port_id, net_id, op_status=OperationalStatus.DOWN)
def plug_interface(self, tenant_id, net_id, port_id, remote_iface_id): db.validate_port_ownership(tenant_id, net_id, port_id) db.port_set_attachment(port_id, net_id, remote_iface_id)
def plug_interface(self, tenant_id, net_id, port_id, remote_iface_id): db.port_set_attachment(port_id, net_id, remote_iface_id)
def unplug_interface(self, tenant_id, net_id, port_id): db.port_set_attachment(port_id, net_id, "")