Skip to content

Commit

Permalink
Network links.
Browse files Browse the repository at this point in the history
  • Loading branch information
enolfc committed Apr 17, 2015
1 parent 4147ccc commit 91eacfa
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
44 changes: 44 additions & 0 deletions ooi/api/network_link.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-

# Copyright 2015 Spanish National Research Council
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.


from ooi.api import base
from ooi.api import network as network_api
from ooi.occi.core import collection
from ooi.occi.infrastructure import compute
from ooi.occi.infrastructure import network
# from ooi.occi.infrastructure import network_link
from ooi.openstack import network as os_network


class Controller(base.Controller):
def index(self, req):
tenant_id = req.environ["keystone.token_auth"].user.project_id
req = self._get_req(req, path="/%s/os-floating-ips" % tenant_id)
response = req.get_response(self.app)
floating_ips = self.get_from_response(response, "floating_ips", [])
occi_link_resources = []
for ip in floating_ips:
if ip["instance_id"]:
net_id = "%s/%s" % (network_api.FLOATING_PREFIX, ip["pool"])
n = network.NetworkResource(title="network", id=net_id)
c = compute.ComputeResource(title="Compute",
id=ip["instance_id"])
# TODO(enolfc): get the MAC?
iface = os_network.OSNetworkInterface(c, n, "mac", ip["ip"])
occi_link_resources.append(iface)

return collection.Collection(resources=occi_link_resources)
13 changes: 13 additions & 0 deletions ooi/wsgi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import ooi
import ooi.api.compute
import ooi.api.network
import ooi.api.network_link
from ooi.api import query
import ooi.api.storage
import ooi.api.storage_link
Expand Down Expand Up @@ -208,6 +209,18 @@ def index(self, *args, **kwargs):
action="general_index",
conditions=dict(method=["GET"]))

self.resources["networklink"] = self._create_resource(
ooi.api.network_link.Controller)
self.mapper.resource("networkinterface", "networklink",
controller=self.resources["networklink"])
# OCCI states that paths must end with a "/" when operating on pahts,
# that are not location pahts or resource instances, so we should add
# this rule manually
self.mapper.connect("networkinterface", "/networklink/",
controller=self.resources["networklink"],
action="index",
conditions=dict(method=["GET"]))

@webob.dec.wsgify(RequestClass=Request)
def __call__(self, req):
response = self.process_request(req)
Expand Down

0 comments on commit 91eacfa

Please sign in to comment.