-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added OCCI infrastructure network resource, mixins and links. New network controller and add links in compute. Some tests added.
- Loading branch information
Showing
11 changed files
with
401 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# -*- 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. | ||
|
||
import webob.exc | ||
|
||
from ooi.api import base | ||
from ooi.occi.core import collection | ||
from ooi.occi.infrastructure import network | ||
|
||
FLOATING_PREFIX = "floating" | ||
|
||
|
||
def _build_network(name, prefix=None): | ||
if prefix: | ||
network_id = '/'.join([prefix, name]) | ||
else: | ||
network_id = name | ||
return network.NetworkResource(title=name, | ||
summary="A OpenStack IP Pool", | ||
id=network_id, | ||
state="active", | ||
mixins=[network.ip_network]) | ||
|
||
|
||
class NetworkController(base.Controller): | ||
def index(self, req): | ||
occi_network_resources = [] | ||
occi_network_resources.append(_build_network("fixed")) | ||
|
||
tenant_id = req.environ["keystone.token_auth"].user.project_id | ||
|
||
req = self._get_req(req, path="/%s/os-floating-ip-pools" % tenant_id) | ||
response = req.get_response(self.app) | ||
pools = self.get_from_response(response, "floating_ip_pools", []) | ||
|
||
for p in pools: | ||
occi_network_resources.append(_build_network(p["name"], | ||
FLOATING_PREFIX)) | ||
|
||
return collection.Collection(resources=occi_network_resources) | ||
|
||
def show(self, id, req): | ||
if id != "fixed": | ||
raise webob.exc.HTTPNotFound() | ||
return _build_network("fixed") | ||
|
||
|
||
class PoolController(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-ip-pools" % tenant_id) | ||
response = req.get_response(self.app) | ||
pools = self.get_from_response(response, "floating_ip_pools", []) | ||
|
||
occi_network_resources = [] | ||
for p in pools: | ||
occi_network_resources.append(_build_network(p["name"], | ||
FLOATING_PREFIX)) | ||
|
||
return collection.Collection(resources=occi_network_resources) | ||
|
||
def show(self, req, id): | ||
tenant_id = req.environ["keystone.token_auth"].user.project_id | ||
|
||
# get info from server | ||
req = self._get_req(req, path="/%s/os-floating-ip-pools" % tenant_id) | ||
response = req.get_response(self.app) | ||
|
||
pools = self.get_from_response(response, "floating_ip_pools", []) | ||
for p in pools: | ||
if p['name'] == id: | ||
return [_build_network(p["name"], FLOATING_PREFIX)] | ||
raise webob.exc.HTTPNotFound() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# -*- 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.occi.core import action | ||
from ooi.occi.core import attribute as attr | ||
from ooi.occi.core import kind | ||
from ooi.occi.core import mixin | ||
from ooi.occi.core import resource | ||
from ooi.occi import helpers | ||
|
||
up = action.Action(helpers.build_scheme('infrastructure/network/action'), | ||
"up", "up network instance") | ||
|
||
down = action.Action(helpers.build_scheme('infrastructure/network/action'), | ||
"down", "down network instance") | ||
|
||
|
||
class NetworkResource(resource.Resource): | ||
attributes = attr.AttributeCollection(["occi.network.vlan", | ||
"occi.network.label", | ||
"occi.network.state"]) | ||
actions = (up, down) | ||
kind = kind.Kind(helpers.build_scheme('infrastructure'), 'network', | ||
'network resource', attributes, '/network/', | ||
actions=actions, | ||
related=[resource.Resource.kind]) | ||
|
||
def __init__(self, title, summary=None, id=None, vlan=None, label=None, | ||
state=None, mixins=[]): | ||
super(NetworkResource, self).__init__(title, mixins, summary=summary, | ||
id=id) | ||
self.attributes["occi.network.vlan"] = attr.MutableAttribute( | ||
"occi.network.vlan", vlan) | ||
self.attributes["occi.network.label"] = attr.MutableAttribute( | ||
"occi.network.label", label) | ||
self.attributes["occi.network.state"] = attr.InmutableAttribute( | ||
"occi.network.state", state) | ||
|
||
@property | ||
def vlan(self): | ||
return self.attributes["occi.network.vlan"].value | ||
|
||
@vlan.setter | ||
def vlan(self, value): | ||
self.attributes["occi.network.vlan"].value = value | ||
|
||
@property | ||
def label(self): | ||
return self.attributes["occi.network.label"].value | ||
|
||
@label.setter | ||
def label(self, value): | ||
self.attributes["occi.network.label"].value = value | ||
|
||
@property | ||
def state(self): | ||
return self.attributes["occi.network.state"].value | ||
|
||
|
||
ip_network = mixin.Mixin(helpers.build_scheme("infrastructure/network"), | ||
"ipnetwork", "IP Networking Mixin", | ||
attributes=attr.AttributeCollection([ | ||
"occi.network.address", | ||
"occi.network.gateway", | ||
"occi.network.allocation"])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# -*- 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.occi.core import attribute as attr | ||
from ooi.occi.core import kind | ||
from ooi.occi.core import link | ||
from ooi.occi.core import mixin | ||
from ooi.occi import helpers | ||
|
||
|
||
class NetworkInterface(link.Link): | ||
attributes = attr.AttributeCollection(["occi.networkinterface.interface", | ||
"occi.networkinterface.mac", | ||
"occi.networkinterface.state"]) | ||
kind = kind.Kind(helpers.build_scheme('infrastructure'), | ||
'networkinterface', 'network link resource', | ||
attributes, '/networklink/', | ||
related=[link.Link.kind]) | ||
|
||
def __init__(self, mixins, source, target, id=None, interface=None, | ||
mac=None, state=None): | ||
|
||
super(NetworkInterface, self).__init__(None, mixins, source, | ||
target, id) | ||
|
||
self.attributes["occi.networkinterface.interface"] = ( | ||
attr.InmutableAttribute("occi.networkinterface.interface", | ||
interface)) | ||
self.attributes["occi.networkinterface.mac"] = attr.MutableAttribute( | ||
"occi.networkinterface.mac", mac) | ||
self.attributes["occi.networkinterface.state"] = ( | ||
attr.InmutableAttribute("occi.networkinterface.state", state)) | ||
|
||
@property | ||
def interface(self): | ||
return self.attributes["occi.networkinterface.interface"].value | ||
|
||
@property | ||
def mac(self): | ||
return self.attributes["occi.networkinterface.mac"].value | ||
|
||
@mac.setter | ||
def mac(self, value): | ||
self.attributes["occi.networkinterface.mac"].value = value | ||
|
||
@property | ||
def state(self): | ||
return self.attributes["occi.networkinterface.state"].value | ||
|
||
ip_network_interface = mixin.Mixin( | ||
helpers.build_scheme("infrastructure/networkinterface"), | ||
"ipnetworkinterface", "IP Network interface Mixin", | ||
attributes=attr.AttributeCollection([ | ||
"occi.networkinterface.address", | ||
"occi.networkinterface.gateway", | ||
"occi.networkinterface.allocation"])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# -*- 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.occi.core import attribute as attr | ||
from ooi.occi.infrastructure import network_link | ||
|
||
|
||
class OSNetworkInterface(network_link.NetworkInterface): | ||
attributes = attr.AttributeCollection(["occi.networkinterface.address", | ||
"occi.networkinterface.gateway", | ||
"occi.networkinterface.allocation"]) | ||
|
||
def __init__(self, source, target, mac, address): | ||
link_id = '_'.join([source.id, address]) | ||
mixins = [network_link.ip_network_interface] | ||
super(OSNetworkInterface, self).__init__(mixins, source, target, | ||
link_id, "eth0", mac, | ||
"active") | ||
self.attributes["occi.networkinterface.address"] = ( | ||
attr.MutableAttribute("occi.networkinterface.address", address)) | ||
self.attributes["occi.networkinterface.gateway"] = ( | ||
attr.MutableAttribute("occi.networkinterface.gateway", None)) | ||
self.attributes["occi.networkinterface.allocation"] = ( | ||
attr.MutableAttribute("occi.networkinterface.allocation", | ||
"dynamic")) |
Oops, something went wrong.