self._resource_name = 'network'
super(Controller, self).__init__()
- def index(self, req, tenant_id):
+ def index(self, request, tenant_id):
""" Returns a list of network ids """
#TODO: this should be for a given tenant!!!
- return self._items(req, tenant_id, net_detail=False)
- return self._items(request, tenant_id, is_detail=False)
++ return self._items(request, tenant_id, net_detail=False)
- def _items(self, request, tenant_id, is_detail):
+ def _item(self, req, tenant_id, network_id,
+ net_details, port_details):
+ network = self.network_manager.get_network_details(
+ tenant_id, network_id)
+ builder = networks_view.get_view_builder(req)
+ result = builder.build(network, net_details, port_details)
+ return dict(networks=result)
+
+ def _items(self, req, tenant_id, net_details, port_details):
""" Returns a list of networks. """
networks = self.network_manager.get_all_networks(tenant_id)
- builder = networks_view.get_view_builder(request)
- result = [builder.build(network, is_detail)['network']
+ builder = networks_view.get_view_builder(req)
+ result = [builder.build(network, net_details, port_details)['network']
for network in networks]
return dict(networks=result)
- def show(self, req, tenant_id, id):
+ def show(self, request, tenant_id, id):
""" Returns network details for the given network id """
try:
- return self._item(req, tenant_id, id,
- network = self.network_manager.get_network_details(
- tenant_id, id)
- builder = networks_view.get_view_builder(request)
- #build response with details
- result = builder.build(network, True)
- return dict(networks=result)
++ return self._item(request, tenant_id, id,
+ net_details=True, port_details=False)
+ except exception.NetworkNotFound as e:
+ return faults.Fault(faults.NetworkNotFound(e))
+
- def detail(self, req, **kwargs):
++ def detail(self, request, **kwargs):
+ tenant_id = kwargs.get('tenant_id')
+ network_id = kwargs.get('id')
+ try:
+ if network_id:
- return self._item(req, tenant_id, network_id,
++ return self._item(request, tenant_id, network_id,
+ net_details=True, port_details=True)
+ else:
+ #do like show but with detaik
- return self._items(req, tenant_id,
++ return self._items(request, tenant_id,
+ net_details=True, port_details=False)
except exception.NetworkNotFound as e:
return faults.Fault(faults.NetworkNotFound(e))
_serialization_metadata = {
"application/xml": {
"attributes": {
- "port": ["id", "state"],
- },
- },
- }
+ "port": ["id", "state"], }, }, }
+
+
def __init__(self, plugin_conf_file=None):
self._resource_name = 'port'
super(Controller, self).__init__()
except exc.HTTPError as e:
return faults.Fault(e)
try:
-- port = self.network_manager.update_port(tenant_id, network_id, id,
- req_params['port-state'])
- builder = ports_view.get_view_builder(req)
- request_params['port-state'])
++ port = self.network_manager.\
++ update_port(tenant_id, network_id, id,
++ request_params['port-state'])
+ builder = ports_view.get_view_builder(request)
result = builder.build(port, True)
return dict(ports=result)
except exception.NetworkNotFound as e:
except exception.PortNotFound as e:
return faults.Fault(faults.PortNotFound(e))
- def attach_resource(self, req, tenant_id, network_id, id):
- #TODO - Complete implementation of these APIs
++
+ def attach_resource(self, request, tenant_id, network_id, id):
+ content_type = request.best_match_content_type()
+ print "Content type:%s" % content_type
try:
- req_params = \
- self._parse_request_params(req,
+ request_params = \
+ self._parse_request_params(request,
self._attachment_ops_param_list)
except exc.HTTPError as e:
return faults.Fault(e)
except exception.AlreadyAttached as e:
return faults.Fault(faults.AlreadyAttached(e))
- def detach_resource(self, req, tenant_id, network_id, id):
- #TODO - Complete implementation of these APIs
+ def detach_resource(self, request, tenant_id, network_id, id):
try:
self.network_manager.unplug_interface(tenant_id,
network_id, id)
node = self._to_xml_node(doc, metadata, k, v)
result.appendChild(node)
else:
-- # Type is atom
- LOG.debug("TYPE IS ATOM:%s", data)
++ # Type is atom.
node = doc.createTextNode(str(data))
result.appendChild(node)
return result
"""
- Quantum's Manager class is responsible for parsing a config file
- and instantiating the correct plugin that concretely implement
- quantum_plugin_base class
-
+ Quantum's Manager class is responsible for parsing a config file and
+ instantiating the correct plugin that concretely implement quantum_plugin_base
+ class.
-
The caller should make sure that QuantumManager is a singleton.
"""
import gettext
class QuantumManager(object):
- def __init__(self, config=CONFIG_FILE):
- self.configuration_file = CONFIG_FILE
- plugin_location = utils.getPluginFromConfig(CONFIG_FILE)
- print "PLUGIN LOCATION:%s" % plugin_location
+
- print "PLUGIN LOCATION:%s" % plugin_location
+ def __init__(self, config=None):
+ if config == None:
+ self.configuration_file = find_config(
+ os.path.abspath(os.path.dirname(__file__)))
+ else:
+ self.configuration_file = config
+ plugin_location = utils.getPluginFromConfig(self.configuration_file)
plugin_klass = utils.import_class(plugin_location)
if not issubclass(plugin_klass, QuantumPluginBase):
raise Exception("Configured Quantum plug-in " \
retrieved a list of all the remote vifs that
are attached to the network
"""
-- print("get_network_details() called\n")
- vifs_on_net = ["/tenant1/networks/net_id/portid/vif2.0",
- "/tenant1/networks/10/121/vif1.1"]
+ vifs_on_net = ["/tenant1/networks/net_id/portid/vif2.0"]
return vifs_on_net
def rename_network(self, tenant_id, net_id, new_name):
"""
print("unplug_interface() called\n")
- def get_interface_details(self, tenant_id, net_id, port_id):
- """
- Retrieves the remote interface that is attached at this
- particular port.
- """
- print("get_interface_details() called\n")
- #returns the remote interface UUID
- return "/tenant1/networks/net_id/portid/vif2.0"
-
- def get_all_attached_interfaces(self, tenant_id, net_id):
- """
- Retrieves all remote interfaces that are attached to
- a particular Virtual Network.
- """
- print("get_all_attached_interfaces() called\n")
- # returns a list of all attached remote interfaces
- vifs_on_net = ["/tenant1/networks/net_id/portid/vif2.0",
- "/tenant1/networks/10/121/vif1.1"]
- return vifs_on_net
-
--
class FakePlugin(object):
"""
FakePlugin is a demo plugin that provides
#static data for networks and ports
_port_dict_1 = {
1: {'port-id': 1,
- 'port-state': 'DOWN',
- 'attachment': None},
+ 'port-state': 'DOWN',
+ 'attachment': None},
2: {'port-id': 2,
- 'port-state': 'UP',
- 'attachment': None}}
+ 'port-state': 'UP',
- 'attachment': None}
- }
++ 'attachment': None}}
_port_dict_2 = {
1: {'port-id': 1,
- 'port-state': 'UP',
- 'attachment': 'SomeFormOfVIFID'},
+ 'port-state': 'UP',
+ 'attachment': 'SomeFormOfVIFID'},
2: {'port-id': 2,
- 'port-state': 'DOWN',
- 'attachment': None}}
+ 'port-state': 'DOWN',
- 'attachment': None}
- }
++ 'attachment': None}}
_networks = {'001':
{
'net-id': '001',
str(FakePlugin._net_counter)
print new_net_id
new_net_dict = {'net-id': new_net_id,
- 'net-name': net_name,
- 'net-ports': {}}
+ 'net-name': net_name,
+ 'net-ports': {}}
++
FakePlugin._networks[new_net_id] = new_net_dict
# return network_id of the created network
return new_net_dict
# TODO(salvatore-orlando):
# Should unplug on port without attachment raise an Error?
port['attachment'] = None
- # TODO - neeed to update methods from this point onwards
+
+ def get_all_attached_interfaces(self, tenant_id, net_id):
+ """
+ Retrieves all remote interfaces that are attached to
+ a particular Virtual Network.
+ """
+ print("get_all_attached_interfaces() called\n")
+ # returns a list of all attached remote interfaces
+ vifs_on_net = ["/tenant1/networks/net_id/portid/vif2.0",
+ "/tenant1/networks/10/121/vif1.1"]
+ return vifs_on_net