-
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.
- Loading branch information
Showing
22 changed files
with
789 additions
and
65 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
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,48 @@ | ||
# -*- 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.occi.core import collection | ||
from ooi.occi.infrastructure import storage | ||
from ooi.openstack import helpers | ||
|
||
|
||
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-volumes" % tenant_id) | ||
response = req.get_response(self.app) | ||
volumes = self.get_from_response(response, "volumes", []) | ||
occi_storage_resources = [] | ||
if volumes: | ||
for v in volumes: | ||
s = storage.StorageResource(title=v["displayName"], id=v["id"]) | ||
occi_storage_resources.append(s) | ||
|
||
return collection.Collection(resources=occi_storage_resources) | ||
|
||
def show(self, id, req): | ||
tenant_id = req.environ["keystone.token_auth"].user.project_id | ||
|
||
# get info from server | ||
req = self._get_req(req, path="/%s/os-volumes/%s" % (tenant_id, id)) | ||
response = req.get_response(self.app) | ||
v = self.get_from_response(response, "volume", {}) | ||
|
||
state = helpers.vol_state(v["status"]) | ||
st = storage.StorageResource(title=v["displayName"], id=v["id"], | ||
size=v["size"], state=state) | ||
return [st] |
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
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,67 @@ | ||
# -*- 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 resource | ||
from ooi.occi import helpers | ||
|
||
online = action.Action(helpers.build_scheme('infrastructure/storage/action'), | ||
"online", "online storage instance") | ||
|
||
offline = action.Action(helpers.build_scheme('infrastructure/storage/action'), | ||
"offline", "offline storage instance") | ||
|
||
backup = action.Action(helpers.build_scheme('infrastructure/storage/action'), | ||
"backup", "backup storage instance") | ||
|
||
snapshot = action.Action(helpers.build_scheme('infrastructure/storage/action'), | ||
"snapshot", "snapshot storage instance") | ||
|
||
resize = action.Action(helpers.build_scheme('infrastructure/storage/action'), | ||
"resize", "resize storage instance") | ||
|
||
|
||
class StorageResource(resource.Resource): | ||
attributes = attr.AttributeCollection(["occi.storage.size", | ||
"occi.storage.state"]) | ||
actions = (online, offline, backup, snapshot, resize) | ||
kind = kind.Kind(helpers.build_scheme('infrastructure'), 'storage', | ||
'storage resource', attributes, '/storage/', | ||
actions=actions, | ||
related=[resource.Resource.kind]) | ||
|
||
def __init__(self, title, summary=None, id=None, size=None, state=None): | ||
mixins = [] | ||
super(StorageResource, self).__init__(title, mixins, summary=summary, | ||
id=id) | ||
self.attributes["occi.storage.size"] = attr.MutableAttribute( | ||
"occi.storage.size", size) | ||
self.attributes["occi.storage.state"] = attr.InmutableAttribute( | ||
"occi.storage.state", state) | ||
|
||
@property | ||
def size(self): | ||
return self.attributes["occi.storage.size"].value | ||
|
||
@size.setter | ||
def size(self, value): | ||
self.attributes["occi.storage.size"].value = value | ||
|
||
@property | ||
def state(self): | ||
return self.attributes["occi.storage.state"].value |
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,63 @@ | ||
# -*- 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 import helpers | ||
|
||
|
||
class StorageLink(link.Link): | ||
attributes = attr.AttributeCollection(["occi.storagelink.deviceid", | ||
"occi.storagelink.mountpoint", | ||
"occi.storagelink.state"]) | ||
kind = kind.Kind(helpers.build_scheme('infrastructure'), 'storagelink', | ||
'storage link resource', attributes, '/storagelink/', | ||
related=[link.Link.kind]) | ||
|
||
def __init__(self, source, target, deviceid=None, mountpoint=None, | ||
state=None): | ||
|
||
# TODO(enolfc): is this a valid link id? | ||
link_id = '_'.join([source.id, target.id]) | ||
super(StorageLink, self).__init__(None, [], source, target, link_id) | ||
|
||
self.attributes["occi.storagelink.deviceid"] = attr.MutableAttribute( | ||
"occi.storagelink.deviceid", deviceid) | ||
self.attributes["occi.storagelink.mountpoint"] = attr.MutableAttribute( | ||
"occi.storagelink.mountpoint", mountpoint) | ||
self.attributes["occi.storagelink.state"] = attr.InmutableAttribute( | ||
"occi.storagelink.state", state) | ||
|
||
@property | ||
def deviceid(self): | ||
return self.attributes["occi.storagelink.deviceid"].value | ||
|
||
@deviceid.setter | ||
def deviceid(self, value): | ||
self.attributes["occi.storagelink.deviceid"].value = value | ||
|
||
@property | ||
def mountpoint(self): | ||
return self.attributes["occi.storagelink.mountpoint"].value | ||
|
||
@mountpoint.setter | ||
def mountpoint(self, value): | ||
self.attributes["occi.storagelink.mountpoint"].value = value | ||
|
||
@property | ||
def state(self): | ||
return self.attributes["occi.storagelink.state"].value |
Oops, something went wrong.