def detail_net(manager, *args):
tid, nid = args
- network = manager.get_network_details(tid, nid)
- network_id = network["net-id"]
- network_name = network["net-name"]
- print "\tNetwork id:%s\n\tNetwork name:%s\n" % (network_id, network_name)
+ iface_list = manager.get_all_attached_interfaces(tid, nid)
+ print "Remote Interfaces on Virtual Network:%s\n" % nid
+ for iface in iface_list:
+ print "\tRemote interface:%s" % iface
+
def api_detail_net(client, *args):
tid, nid = args
- res = client.do_request(tid, 'GET', "/networks/" + nid + "." + FORMAT)
+ res = client.do_request(tid, 'GET',
+ "/networks/%s/ports.%s" % (nid, FORMAT))
output = res.read()
+ if res.status != 200:
+ LOG.error("Failed to list ports: %s" % output)
+ return
rd = simplejson.loads(output)
LOG.debug(rd)
- network_id = rd["networks"]["network"]["id"]
- network_name = rd["networks"]["network"]["name"]
- print "\tNetwork id:%s\n\tNetwork name:%s\n" % (network_id, network_name)
+ print "Remote Interfaces on Virtual Network:%s\n" % nid
+ for port in rd["ports"]:
+ pid = port["id"]
+ res = client.do_request(tid, 'GET',
+ "/networks/%s/ports/%s/attachment.%s" % (nid, pid, FORMAT))
+ output = res.read()
+ rd = simplejson.loads(output)
+ LOG.debug(rd)
+ remote_iface = rd["attachment"]
+ print "\tRemote interface:%s" % remote_iface
def rename_net(manager, *args):
tid, nid, name = args
return
print "Unplugged interface from port:%s on network:%s" % (pid, nid)
-def detail_iface(manager, *args):
- tid, nid, pid = args
- remote_iface = manager.get_interface_details(tid, nid, pid)
- print "Remote interface on Virtual Port:%s " \
- "Virtual Network:%s is %s" % (pid, nid, remote_iface)
-
-def api_detail_iface(manager, *args):
- tid, nid, pid = args
- res = client.do_request(tid, 'GET',
- "/networks/%s/ports/%s/attachment.%s" % (nid, pid, FORMAT))
- output = res.read()
- rd = simplejson.loads(output)
- LOG.debug(rd)
- remote_iface = rd["attachment"]
- print "Remote interface on Virtual Port:%s " \
- "Virtual Network:%s is %s" % (pid, nid, remote_iface)
-
-def list_iface(manager, *args):
- tid, nid = args
- iface_list = manager.get_all_attached_interfaces(tid, nid)
- print "Remote Interfaces on Virtual Network:%s\n" % nid
- for iface in iface_list:
- print "\tRemote interface:%s" % iface
-
-# TODO(bgh): I'm not sure how the api maps to manager.get_all_interfaces so
-# I'm just doing this the manual way for now.
-def api_list_iface(client, *args):
- tid, nid = args
- res = client.do_request(tid, 'GET',
- "/networks/%s/ports.%s" % (nid, FORMAT))
- output = res.read()
- if res.status != 200:
- LOG.error("Failed to list ports: %s" % output)
- return
- rd = simplejson.loads(output)
- LOG.debug(rd)
- print "Remote Interfaces on Virtual Network:%s\n" % nid
- for port in rd["ports"]:
- pid = port["id"]
- res = client.do_request(tid, 'GET',
- "/networks/%s/ports/%s/attachment.%s" % (nid, pid, FORMAT))
- output = res.read()
- rd = simplejson.loads(output)
- LOG.debug(rd)
- remote_iface = rd["attachment"]
- print "\tRemote interface:%s" % remote_iface
-
commands = {
"list_nets": {
"func": list_nets,
"api_func": api_unplug_iface,
"args": ["tenant-id", "net-id", "port-id"]
},
- "detail_iface": {
- "func": detail_iface,
- "api_func": api_detail_iface,
- "args": ["tenant-id", "net-id", "port-id"]
- },
- "list_iface": {
- "func": list_iface,
- "api_func": api_list_iface,
- "args": ["tenant-id", "net-id"]
- },
}
def help():
return d
def get_network_details(self, tenant_id, net_id):
- network = db.network_get(net_id)
- d = {}
- d["net-id"] = str(network.uuid)
- d["net-name"] = network.name
- d["net-ports"] = self.get_all_ports(tenant_id, net_id)
- return d
+ ports = db.port_list(net_id)
+ ifaces = []
+ for p in ports:
+ ifaces.append(p.interface_id)
+ return ifaces
def rename_network(self, tenant_id, net_id, new_name):
try:
"net-id": port.network_id, "port-state": "UP"}
return rv
- def get_all_attached_interfaces(self, tenant_id, net_id):
- ports = db.port_list(net_id)
- ifaces = []
- for p in ports:
- ifaces.append(p.interface_id)
- return ifaces
-
def plug_interface(self, tenant_id, net_id, port_id, remote_iface_id):
db.port_set_attachment(port_id, remote_iface_id)
ovs_db.update_network_binding(net_id, remote_iface_id)