code pep8 style updates
This commit is contained in:
parent
949032490f
commit
b666e7375e
|
@ -80,7 +80,8 @@ class NetworkInterfaceBackend(backend.KindBackend):
|
|||
# TODO: add all network info!
|
||||
if link.target.identifier == '/network/public':
|
||||
# public means floating IP in OS!
|
||||
address = net.add_floating_ip_to_vm(link.source.attributes['occi.core.id'],
|
||||
address = net.add_floating_ip_to_vm(link.source.attributes[
|
||||
'occi.core.id'],
|
||||
extras['nova_ctx'])
|
||||
link.attributes['occi.networkinterface.address'] = address
|
||||
else:
|
||||
|
@ -101,4 +102,3 @@ class NetworkInterfaceBackend(backend.KindBackend):
|
|||
net.remove_floating_ip(link.source.attributes['occi.core.id'],
|
||||
link.attributes['occi.networkinterface.address'],
|
||||
extras['nova_ctx'])
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ from occi_os_api.extensions import os_addon
|
|||
from occi_os_api.nova_glue import vm
|
||||
from occi_os_api.nova_glue import security
|
||||
|
||||
|
||||
class OsComputeBackend(backend.MixinBackend, backend.ActionBackend):
|
||||
"""
|
||||
The OpenStackCompute backend.
|
||||
|
@ -39,10 +40,7 @@ class OsComputeBackend(backend.MixinBackend, backend.ActionBackend):
|
|||
Add OpenStack related actions.
|
||||
"""
|
||||
if 'occi.compute.state' in entity.attributes and entity.attributes[
|
||||
'occi.compute' \
|
||||
'.state'] ==' \
|
||||
' ' \
|
||||
''active':
|
||||
'occi.compute.state'] == 'active':
|
||||
entity.actions.append(os_addon.OS_CREATE_IMAGE)
|
||||
entity.actions.append(os_addon.OS_CHG_PWD)
|
||||
|
||||
|
|
|
@ -242,4 +242,3 @@ class StorageLinkBackend(backend.KindBackend):
|
|||
"""
|
||||
volume_id = get_vol_to_attach(link)
|
||||
vm.detach_volume(volume_id, extras['nova_ctx'])
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ def get_adapter_info(uid, context):
|
|||
"""
|
||||
vm_instance = vm.get_vm(uid, context)
|
||||
|
||||
result = {'public':[], 'admin':[]}
|
||||
result = {'public': [], 'admin': []}
|
||||
try:
|
||||
net_info = NETWORK_API.get_instance_nw_info(context, vm_instance)[0]
|
||||
except IndexError:
|
||||
|
@ -58,13 +58,13 @@ def get_adapter_info(uid, context):
|
|||
|
||||
tmp = net_info['network']['subnets'][0]['ips'][0]
|
||||
for item in tmp['floating_ips']:
|
||||
result['public'].append({'interface':'eth0',
|
||||
'mac':'aa:bb:cc:dd:ee:ff',
|
||||
result['public'].append({'interface': 'eth0',
|
||||
'mac': 'aa:bb:cc:dd:ee:ff',
|
||||
'state': 'active',
|
||||
'address': item['address'],
|
||||
'gateway': '0.0.0.0',
|
||||
'allocation': 'static'})
|
||||
result['admin'].append({'interface':'eth0',
|
||||
result['admin'].append({'interface': 'eth0',
|
||||
'mac': mac,
|
||||
'state': 'active',
|
||||
'address': tmp['address'],
|
||||
|
|
|
@ -97,12 +97,14 @@ def snapshot_storage_instance(uid, name, description, context):
|
|||
instance = get_storage(uid, context)
|
||||
VOLUME_API.create_snapshot(context, instance, name, description)
|
||||
|
||||
|
||||
def get_image(uid, context):
|
||||
"""
|
||||
Return details on an image.
|
||||
"""
|
||||
return IMAGE_API.show(context, uid)
|
||||
|
||||
|
||||
def get_image_architecture(uid, context):
|
||||
"""
|
||||
Extract architecture from either:
|
||||
|
@ -145,6 +147,7 @@ def get_storage(uid, context):
|
|||
raise exceptions.HTTPError(404, 'Volume not found!')
|
||||
return instance
|
||||
|
||||
|
||||
def get_storages(context):
|
||||
"""
|
||||
Retrieve all storage entities from user.
|
||||
|
|
|
@ -173,7 +173,7 @@ def resize_vm(uid, flavor_name, context):
|
|||
**kwargs)
|
||||
ready = False
|
||||
i = 0
|
||||
while i < 15:
|
||||
while not ready or i < 15:
|
||||
i += 1
|
||||
state = get_vm(uid, context)['vm_state']
|
||||
if state == 'resized':
|
||||
|
@ -398,6 +398,7 @@ def get_vm(uid, context):
|
|||
raise exceptions.HTTPError(404, 'VM not found!')
|
||||
return instance
|
||||
|
||||
|
||||
def get_vms(context):
|
||||
"""
|
||||
Retrieve all VMs in a given context.
|
||||
|
@ -406,6 +407,7 @@ def get_vms(context):
|
|||
tmp = COMPUTE_API.get_all(context, search_opts=opts)
|
||||
return tmp
|
||||
|
||||
|
||||
def get_occi_state(uid, context):
|
||||
"""
|
||||
See nova/compute/vm_states.py nova/compute/task_states.py
|
||||
|
|
|
@ -20,8 +20,10 @@
|
|||
OCCI registry
|
||||
"""
|
||||
|
||||
#R0201:method could be func.E1002:old style obj
|
||||
#pylint: disable=R0201,E1002
|
||||
#R0201:method could be func.E1002:old style obj,R0914-R0912:# of branches
|
||||
#E1121:# positional args.
|
||||
#pylint: disable=R0201,E1002,R0914,R0912,E1121
|
||||
|
||||
import uuid
|
||||
|
||||
from occi import registry as occi_registry
|
||||
|
@ -47,6 +49,11 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
|
|||
def __init__(self):
|
||||
super(OCCIRegistry, self).__init__()
|
||||
self.cache = {}
|
||||
self.adm_net = core_model.Resource('/network/admin',
|
||||
infrastructure.NETWORK, [infrastructure.IPNETWORK])
|
||||
self.pub_net = core_model.Resource('/network/public',
|
||||
infrastructure.NETWORK, [infrastructure.IPNETWORK])
|
||||
|
||||
self._setup_network()
|
||||
|
||||
def get_extras(self, extras):
|
||||
|
@ -127,7 +134,7 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
|
|||
# I have seen it - need to update or delete if gone in OS!
|
||||
# I have already seen it
|
||||
cached_item = self.cache[(key, context.user_id)]
|
||||
if not iden in vm_res_ids and cached_item.kind ==\
|
||||
if not iden in vm_res_ids and cached_item.kind == \
|
||||
infrastructure.COMPUTE:
|
||||
# it was delete in OS -> remove links, cache + KeyError!
|
||||
# can delete it because it was my item!
|
||||
|
@ -135,7 +142,7 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
|
|||
self.cache.pop((link.identifier, repr(extras)))
|
||||
self.cache.pop((key, repr(extras)))
|
||||
raise KeyError
|
||||
if not iden in stor_res_ids and cached_item.kind ==\
|
||||
if not iden in stor_res_ids and cached_item.kind == \
|
||||
infrastructure.STORAGE:
|
||||
# it was delete in OS -> remove from cache + KeyError!
|
||||
# can delete it because it was my item!
|
||||
|
@ -158,9 +165,9 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
|
|||
# construct it.
|
||||
if iden in vm_res_ids:
|
||||
# create new & add to cache!
|
||||
result = self._construct_occi_compute(iden, vms, extras)[0]
|
||||
result = self._construct_occi_compute(iden, extras)[0]
|
||||
elif iden in stor_res_ids:
|
||||
result = self._construct_occi_storage(iden, stors, extras)[0]
|
||||
result = self._construct_occi_storage(iden, extras)[0]
|
||||
else:
|
||||
# doesn't exist!
|
||||
raise KeyError
|
||||
|
@ -210,23 +217,27 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
|
|||
if item.extras is None:
|
||||
# add to result set
|
||||
result.append(item)
|
||||
elif item_id in vm_res_ids and item.kind == infrastructure.COMPUTE:
|
||||
elif item_id in vm_res_ids and item.kind == \
|
||||
infrastructure.COMPUTE:
|
||||
# check & update (take links, mixins from cache)
|
||||
# add compute and it's links to result
|
||||
self._update_occi_compute(item, extras)
|
||||
result.append(item)
|
||||
result.extend(item.links)
|
||||
elif item_id in stor_res_ids and item.kind == infrastructure.STORAGE:
|
||||
elif item_id in stor_res_ids and item.kind == \
|
||||
infrastructure.STORAGE:
|
||||
# check & update (take links, mixins from cache)
|
||||
# add compute and it's links to result
|
||||
self._update_occi_storage(item, extras)
|
||||
result.append(item)
|
||||
elif item_id not in vm_res_ids and item.kind == infrastructure.COMPUTE:
|
||||
elif item_id not in vm_res_ids and item.kind == \
|
||||
infrastructure.COMPUTE:
|
||||
# remove item and it's links from cache!
|
||||
for link in item.links:
|
||||
self.cache.pop((link.identifier, item.extras['user_id']))
|
||||
self.cache.pop((item.identifier, item.extras['user_id']))
|
||||
elif item_id not in stor_res_ids and item.kind == infrastructure.STORAGE:
|
||||
elif item_id not in stor_res_ids and item.kind == \
|
||||
infrastructure.STORAGE:
|
||||
# remove item
|
||||
self.cache.pop((item.identifier, item.extras['user_id']))
|
||||
for item in vms:
|
||||
|
@ -236,8 +247,7 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
|
|||
else:
|
||||
# construct (with links and mixins and add to cache!
|
||||
# add compute and it's linke to result
|
||||
ent_list = self._construct_occi_compute(item['uuid'], vms,
|
||||
extras)
|
||||
ent_list = self._construct_occi_compute(item['uuid'], extras)
|
||||
result.extend(ent_list)
|
||||
for item in stors:
|
||||
if (infrastructure.STORAGE.location + item['id'],
|
||||
|
@ -246,8 +256,7 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
|
|||
else:
|
||||
# construct (with links and mixins and add to cache!
|
||||
# add compute and it's linke to result
|
||||
ent_list = self._construct_occi_storage(item['id'], stors,
|
||||
extras)
|
||||
ent_list = self._construct_occi_storage(item['id'], extras)
|
||||
result.extend(ent_list)
|
||||
|
||||
return result
|
||||
|
@ -255,11 +264,14 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
|
|||
# Not part of parent
|
||||
|
||||
def _update_occi_compute(self, entity, extras):
|
||||
"""
|
||||
Update an occi compute resource instance.
|
||||
"""
|
||||
# TODO: implement update of mixins and links (remove old mixins and
|
||||
# links)!
|
||||
return entity
|
||||
|
||||
def _construct_occi_compute(self, identifier, vms, extras):
|
||||
def _construct_occi_compute(self, identifier, extras):
|
||||
"""
|
||||
Construct a OCCI compute instance.
|
||||
|
||||
|
@ -307,10 +319,13 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
|
|||
return result
|
||||
|
||||
def _update_occi_storage(self, entity, extras):
|
||||
"""
|
||||
Update a storage resource instance.
|
||||
"""
|
||||
# TODO: is there sth to do here??
|
||||
return entity
|
||||
|
||||
def _construct_occi_storage(self, identifier, stors, extras):
|
||||
def _construct_occi_storage(self, identifier, extras):
|
||||
"""
|
||||
Construct a OCCI storage instance.
|
||||
|
||||
|
@ -351,8 +366,6 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
|
|||
Add a public and an admin network interface.
|
||||
"""
|
||||
# TODO: read from openstack!
|
||||
self.pub_net = core_model.Resource('/network/public',
|
||||
infrastructure.NETWORK, [infrastructure.IPNETWORK])
|
||||
self.pub_net.attributes = {'occi.network.vlan': 'external',
|
||||
'occi.network.label': 'default',
|
||||
'occi.network.state': 'active',
|
||||
|
@ -363,12 +376,11 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
|
|||
'.0.1',
|
||||
'occi.networkinterface.allocation':
|
||||
'static'}
|
||||
self.adm_net = core_model.Resource('/network/admin',
|
||||
infrastructure.NETWORK, [infrastructure.IPNETWORK])
|
||||
self.adm_net.attributes = {'occi.network.vlan': 'admin',
|
||||
'occi.network.label': 'default',
|
||||
'occi.network.state': 'active',
|
||||
'occi.networkinterface.address': '10.0.0.0/24',
|
||||
'occi.networkinterface.address': '10.0.0'
|
||||
'.0/24',
|
||||
'occi.networkinterface.gateway': '10.0.0'
|
||||
'.1',
|
||||
'occi.networkinterface.allocation':
|
||||
|
|
|
@ -27,11 +27,9 @@ import logging
|
|||
|
||||
from nova import flags
|
||||
from nova import wsgi
|
||||
from nova import context
|
||||
from nova import db
|
||||
from nova.image import glance
|
||||
from nova.compute import instance_types
|
||||
from nova.network import api
|
||||
from nova.openstack.common import cfg
|
||||
|
||||
from occi_os_api import registry
|
||||
|
@ -208,7 +206,7 @@ class OCCIApplication(occi_wsgi.Application, wsgi.Application):
|
|||
try:
|
||||
self.registry.get_backend(resource_template, extras)
|
||||
except AttributeError:
|
||||
msg = 'Registering an OpenStack flavour/instance type: %s' %\
|
||||
msg = 'Registering an OpenStack flavour/instance type: %s' % \
|
||||
str(resource_template)
|
||||
LOG.debug(msg)
|
||||
self.register_backend(resource_template, MIXIN_BACKEND)
|
||||
|
|
|
@ -5,7 +5,6 @@ mkdir -p build/html
|
|||
|
||||
echo '\n PyLint report \n****************************************\n'
|
||||
|
||||
#pylint -d I0011 -i y -f html occi_os_api tests >> build/html/lint.html
|
||||
pylint -d W0511,I0011,E1101,E0611,F0401 -i y --report no **/*.py
|
||||
|
||||
echo '\n Unittest coverage \n****************************************\n'
|
||||
|
@ -14,14 +13,15 @@ nc -z localhost 8787
|
|||
if [ "$?" -ne 0 ]; then
|
||||
echo "Unable to connect to OCCI endpoint localhost 8787 - will not run
|
||||
system test."
|
||||
nosetests --with-coverage --cover-erase --cover-package=occi_os_api --exclude=system
|
||||
else
|
||||
echo "Please make sure that the following line is available in nova.conf:"
|
||||
echo "allow_resize_to_same_host=True libvirt_inject_password=True enabled_apis=ec2,occiapi,osapi_compute,osapi_volume,metadata )"
|
||||
|
||||
source ../devstack/openrc
|
||||
nova-manage flavor create --name=itsy --cpu=1 --memory=128 --flavor=98 --root_gb=1 --ephemeral_gb=1
|
||||
nova-manage flavor create --name=bitsy --cpu=1 --memory=256 --flavor=99 --root_gb=1 --ephemeral_gb=1
|
||||
nosetests --with-coverage --cover-html --cover-html-dir=build/html/ --cover-erase --cover-package=occi_os_api
|
||||
nova-manage flavor create --name=itsy --cpu=1 --memory=32 --flavor=98 --root_gb=1 --ephemeral_gb=1
|
||||
nova-manage flavor create --name=bitsy --cpu=1 --memory=64 --flavor=99 --root_gb=1 --ephemeral_gb=1
|
||||
nosetests --with-coverage --cover-erase --cover-package=occi_os_api
|
||||
fi
|
||||
|
||||
echo '\n Code style \n****************************************\n'
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
__author__ = 'tmetsch'
|
Loading…
Reference in New Issue