code pep8 style updates

This commit is contained in:
tmetsch
2012-10-17 13:01:48 +02:00
parent 949032490f
commit b666e7375e
10 changed files with 52 additions and 41 deletions

View File

@@ -80,7 +80,8 @@ class NetworkInterfaceBackend(backend.KindBackend):
# TODO: add all network info! # TODO: add all network info!
if link.target.identifier == '/network/public': if link.target.identifier == '/network/public':
# public means floating IP in OS! # 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']) extras['nova_ctx'])
link.attributes['occi.networkinterface.address'] = address link.attributes['occi.networkinterface.address'] = address
else: else:
@@ -101,4 +102,3 @@ class NetworkInterfaceBackend(backend.KindBackend):
net.remove_floating_ip(link.source.attributes['occi.core.id'], net.remove_floating_ip(link.source.attributes['occi.core.id'],
link.attributes['occi.networkinterface.address'], link.attributes['occi.networkinterface.address'],
extras['nova_ctx']) extras['nova_ctx'])

View File

@@ -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 vm
from occi_os_api.nova_glue import security from occi_os_api.nova_glue import security
class OsComputeBackend(backend.MixinBackend, backend.ActionBackend): class OsComputeBackend(backend.MixinBackend, backend.ActionBackend):
""" """
The OpenStackCompute backend. The OpenStackCompute backend.
@@ -39,10 +40,7 @@ class OsComputeBackend(backend.MixinBackend, backend.ActionBackend):
Add OpenStack related actions. Add OpenStack related actions.
""" """
if 'occi.compute.state' in entity.attributes and entity.attributes[ if 'occi.compute.state' in entity.attributes and entity.attributes[
'occi.compute' \ 'occi.compute.state'] == 'active':
'.state'] ==' \
' ' \
''active':
entity.actions.append(os_addon.OS_CREATE_IMAGE) entity.actions.append(os_addon.OS_CREATE_IMAGE)
entity.actions.append(os_addon.OS_CHG_PWD) entity.actions.append(os_addon.OS_CHG_PWD)

View File

@@ -242,4 +242,3 @@ class StorageLinkBackend(backend.KindBackend):
""" """
volume_id = get_vol_to_attach(link) volume_id = get_vol_to_attach(link)
vm.detach_volume(volume_id, extras['nova_ctx']) vm.detach_volume(volume_id, extras['nova_ctx'])

View File

@@ -97,12 +97,14 @@ def snapshot_storage_instance(uid, name, description, context):
instance = get_storage(uid, context) instance = get_storage(uid, context)
VOLUME_API.create_snapshot(context, instance, name, description) VOLUME_API.create_snapshot(context, instance, name, description)
def get_image(uid, context): def get_image(uid, context):
""" """
Return details on an image. Return details on an image.
""" """
return IMAGE_API.show(context, uid) return IMAGE_API.show(context, uid)
def get_image_architecture(uid, context): def get_image_architecture(uid, context):
""" """
Extract architecture from either: Extract architecture from either:
@@ -145,6 +147,7 @@ def get_storage(uid, context):
raise exceptions.HTTPError(404, 'Volume not found!') raise exceptions.HTTPError(404, 'Volume not found!')
return instance return instance
def get_storages(context): def get_storages(context):
""" """
Retrieve all storage entities from user. Retrieve all storage entities from user.

View File

@@ -173,7 +173,7 @@ def resize_vm(uid, flavor_name, context):
**kwargs) **kwargs)
ready = False ready = False
i = 0 i = 0
while i < 15: while not ready or i < 15:
i += 1 i += 1
state = get_vm(uid, context)['vm_state'] state = get_vm(uid, context)['vm_state']
if state == 'resized': if state == 'resized':
@@ -398,6 +398,7 @@ def get_vm(uid, context):
raise exceptions.HTTPError(404, 'VM not found!') raise exceptions.HTTPError(404, 'VM not found!')
return instance return instance
def get_vms(context): def get_vms(context):
""" """
Retrieve all VMs in a given 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) tmp = COMPUTE_API.get_all(context, search_opts=opts)
return tmp return tmp
def get_occi_state(uid, context): def get_occi_state(uid, context):
""" """
See nova/compute/vm_states.py nova/compute/task_states.py See nova/compute/vm_states.py nova/compute/task_states.py

View File

@@ -20,8 +20,10 @@
OCCI registry OCCI registry
""" """
#R0201:method could be func.E1002:old style obj #R0201:method could be func.E1002:old style obj,R0914-R0912:# of branches
#pylint: disable=R0201,E1002 #E1121:# positional args.
#pylint: disable=R0201,E1002,R0914,R0912,E1121
import uuid import uuid
from occi import registry as occi_registry from occi import registry as occi_registry
@@ -47,6 +49,11 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
def __init__(self): def __init__(self):
super(OCCIRegistry, self).__init__() super(OCCIRegistry, self).__init__()
self.cache = {} 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() self._setup_network()
def get_extras(self, extras): def get_extras(self, extras):
@@ -158,9 +165,9 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
# construct it. # construct it.
if iden in vm_res_ids: if iden in vm_res_ids:
# create new & add to cache! # 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: elif iden in stor_res_ids:
result = self._construct_occi_storage(iden, stors, extras)[0] result = self._construct_occi_storage(iden, extras)[0]
else: else:
# doesn't exist! # doesn't exist!
raise KeyError raise KeyError
@@ -210,23 +217,27 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
if item.extras is None: if item.extras is None:
# add to result set # add to result set
result.append(item) 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) # check & update (take links, mixins from cache)
# add compute and it's links to result # add compute and it's links to result
self._update_occi_compute(item, extras) self._update_occi_compute(item, extras)
result.append(item) result.append(item)
result.extend(item.links) 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) # check & update (take links, mixins from cache)
# add compute and it's links to result # add compute and it's links to result
self._update_occi_storage(item, extras) self._update_occi_storage(item, extras)
result.append(item) 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! # remove item and it's links from cache!
for link in item.links: for link in item.links:
self.cache.pop((link.identifier, item.extras['user_id'])) self.cache.pop((link.identifier, item.extras['user_id']))
self.cache.pop((item.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 # remove item
self.cache.pop((item.identifier, item.extras['user_id'])) self.cache.pop((item.identifier, item.extras['user_id']))
for item in vms: for item in vms:
@@ -236,8 +247,7 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
else: else:
# construct (with links and mixins and add to cache! # construct (with links and mixins and add to cache!
# add compute and it's linke to result # add compute and it's linke to result
ent_list = self._construct_occi_compute(item['uuid'], vms, ent_list = self._construct_occi_compute(item['uuid'], extras)
extras)
result.extend(ent_list) result.extend(ent_list)
for item in stors: for item in stors:
if (infrastructure.STORAGE.location + item['id'], if (infrastructure.STORAGE.location + item['id'],
@@ -246,8 +256,7 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
else: else:
# construct (with links and mixins and add to cache! # construct (with links and mixins and add to cache!
# add compute and it's linke to result # add compute and it's linke to result
ent_list = self._construct_occi_storage(item['id'], stors, ent_list = self._construct_occi_storage(item['id'], extras)
extras)
result.extend(ent_list) result.extend(ent_list)
return result return result
@@ -255,11 +264,14 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
# Not part of parent # Not part of parent
def _update_occi_compute(self, entity, extras): def _update_occi_compute(self, entity, extras):
"""
Update an occi compute resource instance.
"""
# TODO: implement update of mixins and links (remove old mixins and # TODO: implement update of mixins and links (remove old mixins and
# links)! # links)!
return entity return entity
def _construct_occi_compute(self, identifier, vms, extras): def _construct_occi_compute(self, identifier, extras):
""" """
Construct a OCCI compute instance. Construct a OCCI compute instance.
@@ -307,10 +319,13 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
return result return result
def _update_occi_storage(self, entity, extras): def _update_occi_storage(self, entity, extras):
"""
Update a storage resource instance.
"""
# TODO: is there sth to do here?? # TODO: is there sth to do here??
return entity return entity
def _construct_occi_storage(self, identifier, stors, extras): def _construct_occi_storage(self, identifier, extras):
""" """
Construct a OCCI storage instance. Construct a OCCI storage instance.
@@ -351,8 +366,6 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
Add a public and an admin network interface. Add a public and an admin network interface.
""" """
# TODO: read from openstack! # TODO: read from openstack!
self.pub_net = core_model.Resource('/network/public',
infrastructure.NETWORK, [infrastructure.IPNETWORK])
self.pub_net.attributes = {'occi.network.vlan': 'external', self.pub_net.attributes = {'occi.network.vlan': 'external',
'occi.network.label': 'default', 'occi.network.label': 'default',
'occi.network.state': 'active', 'occi.network.state': 'active',
@@ -363,12 +376,11 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
'.0.1', '.0.1',
'occi.networkinterface.allocation': 'occi.networkinterface.allocation':
'static'} 'static'}
self.adm_net = core_model.Resource('/network/admin',
infrastructure.NETWORK, [infrastructure.IPNETWORK])
self.adm_net.attributes = {'occi.network.vlan': 'admin', self.adm_net.attributes = {'occi.network.vlan': 'admin',
'occi.network.label': 'default', 'occi.network.label': 'default',
'occi.network.state': 'active', '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' 'occi.networkinterface.gateway': '10.0.0'
'.1', '.1',
'occi.networkinterface.allocation': 'occi.networkinterface.allocation':

View File

@@ -27,11 +27,9 @@ import logging
from nova import flags from nova import flags
from nova import wsgi from nova import wsgi
from nova import context
from nova import db from nova import db
from nova.image import glance from nova.image import glance
from nova.compute import instance_types from nova.compute import instance_types
from nova.network import api
from nova.openstack.common import cfg from nova.openstack.common import cfg
from occi_os_api import registry from occi_os_api import registry

View File

@@ -5,7 +5,6 @@ mkdir -p build/html
echo '\n PyLint report \n****************************************\n' 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 pylint -d W0511,I0011,E1101,E0611,F0401 -i y --report no **/*.py
echo '\n Unittest coverage \n****************************************\n' echo '\n Unittest coverage \n****************************************\n'
@@ -14,14 +13,15 @@ nc -z localhost 8787
if [ "$?" -ne 0 ]; then if [ "$?" -ne 0 ]; then
echo "Unable to connect to OCCI endpoint localhost 8787 - will not run echo "Unable to connect to OCCI endpoint localhost 8787 - will not run
system test." system test."
nosetests --with-coverage --cover-erase --cover-package=occi_os_api --exclude=system
else else
echo "Please make sure that the following line is available in nova.conf:" 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 )" echo "allow_resize_to_same_host=True libvirt_inject_password=True enabled_apis=ec2,occiapi,osapi_compute,osapi_volume,metadata )"
source ../devstack/openrc 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=itsy --cpu=1 --memory=32 --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 nova-manage flavor create --name=bitsy --cpu=1 --memory=64 --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 nosetests --with-coverage --cover-erase --cover-package=occi_os_api
fi fi
echo '\n Code style \n****************************************\n' echo '\n Code style \n****************************************\n'

View File

@@ -1 +0,0 @@
__author__ = 'tmetsch'