Fix term names according to specification.
Since now the images, flavor and secgroups categories and links are based on the ID, we have to adapt all the code to reflect this change. Closes #38
This commit is contained in:
parent
da1a1b3ac6
commit
567eeb85f8
|
@ -118,8 +118,8 @@ class ComputeBackend(KindBackend, ActionBackend):
|
|||
|
||||
mixin = new.mixins[0]
|
||||
if isinstance(mixin, os_mixins.ResourceTemplate):
|
||||
flavor_name = mixin.term
|
||||
vm.resize_vm(uid, flavor_name, context)
|
||||
flavor_id = mixin.term
|
||||
vm.resize_vm(uid, flavor_id, context)
|
||||
old.attributes['occi.compute.state'] = 'inactive'
|
||||
# now update the mixin info
|
||||
old.mixins.append(mixin)
|
||||
|
|
|
@ -108,7 +108,6 @@ class SecurityGroupBackend(backend.UserDefinedMixinBackend):
|
|||
"""
|
||||
context = extras['nova_ctx']
|
||||
security_group = security.retrieve_group(category.term,
|
||||
extras['nova_ctx'].project_id,
|
||||
extras['nova_ctx'])
|
||||
security.remove_group(security_group.id, context)
|
||||
|
||||
|
@ -127,8 +126,7 @@ class SecurityRuleBackend(backend.KindBackend):
|
|||
sec_mixin = get_sec_mixin(entity)
|
||||
context = extras['nova_ctx']
|
||||
security_group = security.retrieve_group(sec_mixin.term,
|
||||
extras['nova_ctx']
|
||||
.project_id, context)
|
||||
context)
|
||||
sg_rule = make_sec_rule(entity, security_group['id'])
|
||||
|
||||
if security_group_rule_exists(security_group, sg_rule):
|
||||
|
|
|
@ -73,18 +73,16 @@ def remove_group(group_id, context):
|
|||
raise AttributeError(error)
|
||||
|
||||
|
||||
def retrieve_group(mixin_term, project_id, context):
|
||||
def retrieve_group(mixin_term, context):
|
||||
"""
|
||||
Retrieve the security group associated with the security mixin.
|
||||
|
||||
mixin_term -- The term of the mixin representing the group.
|
||||
project_id -- The project id.
|
||||
context -- The os context.
|
||||
"""
|
||||
try:
|
||||
sec_group = db.security_group_get_by_name(context,
|
||||
project_id,
|
||||
mixin_term)
|
||||
sec_group = db.security_group_get(context,
|
||||
mixin_term)
|
||||
except Exception:
|
||||
# ensure that an OpenStack sec group matches the mixin
|
||||
# if not, create one.
|
||||
|
|
|
@ -37,6 +37,7 @@ from occi.extensions import infrastructure
|
|||
|
||||
from occi_os_api.extensions import os_mixins
|
||||
from occi_os_api.extensions import os_addon
|
||||
from occi_os_api.nova_glue import security
|
||||
|
||||
import logging
|
||||
|
||||
|
@ -94,14 +95,15 @@ def create_vm(entity, context):
|
|||
# Look for security group. If the group is non-existant, the
|
||||
# call to create will fail.
|
||||
if os_addon.SEC_GROUP in mixin.related:
|
||||
sg_names.append(mixin.term)
|
||||
secgroup = security.retrieve_group(mixin.term, context)
|
||||
sg_names.append(secgroup["name"])
|
||||
|
||||
if not os_template:
|
||||
raise AttributeError('Please provide a valid OS Template.')
|
||||
|
||||
if resource_template:
|
||||
inst_type = compute.instance_types.\
|
||||
get_instance_type_by_name(resource_template.term)
|
||||
get_instance_type_by_flavor_id(resource_template.term)
|
||||
else:
|
||||
inst_type = compute.instance_types.get_default_instance_type()
|
||||
msg = ('No resource template was found in the request. '
|
||||
|
@ -162,7 +164,7 @@ def rebuild_vm(uid, image_href, context):
|
|||
raise AttributeError('Cannot find image for rebuild')
|
||||
|
||||
|
||||
def resize_vm(uid, flavor_name, context):
|
||||
def resize_vm(uid, flavor_id, context):
|
||||
"""
|
||||
Resizes a VM up or down
|
||||
|
||||
|
@ -170,13 +172,13 @@ def resize_vm(uid, flavor_name, context):
|
|||
http://wiki.openstack.org/HypervisorSupportMatrix
|
||||
|
||||
uid -- id of the instance
|
||||
flavor_name -- image reference.
|
||||
flavor_id -- image reference.
|
||||
context -- the os context
|
||||
"""
|
||||
instance = get_vm(uid, context)
|
||||
kwargs = {}
|
||||
try:
|
||||
flavor = instance_types.get_instance_type_by_name(flavor_name)
|
||||
flavor = instance_types.get_instance_type_by_flavor_id(flavor_id)
|
||||
COMPUTE_API.resize(context, instance, flavor_id=flavor['flavorid'],
|
||||
**kwargs)
|
||||
ready = False
|
||||
|
|
|
@ -297,13 +297,13 @@ class OCCIRegistry(occi_registry.NonePersistentRegistry):
|
|||
result.append(entity)
|
||||
|
||||
# 2. os and res templates
|
||||
flavor_name = instance['instance_type'].name
|
||||
res_tmp = self.get_category('/' + flavor_name + '/', extras)
|
||||
flavor_id = instance['instance_type'].flavorid
|
||||
res_tmp = self.get_category('/' + flavor_id + '/', extras)
|
||||
entity.mixins.append(res_tmp)
|
||||
|
||||
os_id = instance['image_ref']
|
||||
image_name = storage.get_image(os_id, context)['name']
|
||||
os_tmp = self.get_category('/' + image_name + '/', extras)
|
||||
image_id = storage.get_image(os_id, context)['id']
|
||||
os_tmp = self.get_category('/' + image_id + '/', extras)
|
||||
entity.mixins.append(os_tmp)
|
||||
|
||||
# 3. network links & get links from cache!
|
||||
|
|
|
@ -176,14 +176,14 @@ class OCCIApplication(occi_wsgi.Application, wsgi.Application):
|
|||
continue
|
||||
|
||||
os_template = os_mixins.OsTemplate(
|
||||
term=self._transformTerm(img['name']),
|
||||
term=img['id'],
|
||||
scheme=template_schema,
|
||||
os_id=img['id'],
|
||||
related=[infrastructure.OS_TEMPLATE],
|
||||
attributes=None,
|
||||
title='This is an OS ' + img['name'] + \
|
||||
' VM image',
|
||||
location='/' + quote(img['name']) + '/')
|
||||
location='/' + quote(img['id']) + '/')
|
||||
|
||||
try:
|
||||
self.registry.get_backend(os_template, extras)
|
||||
|
@ -199,13 +199,13 @@ class OCCIApplication(occi_wsgi.Application, wsgi.Application):
|
|||
template_schema = 'http://schemas.openstack.org/template/resource#'
|
||||
os_flavours = instance_types.get_all_types()
|
||||
|
||||
for itype in os_flavours:
|
||||
for itype in os_flavours.values():
|
||||
resource_template = os_mixins.ResourceTemplate(
|
||||
term=self._transformTerm(itype),
|
||||
term=itype["flavorid"],
|
||||
scheme=template_schema,
|
||||
related=[infrastructure.RESOURCE_TEMPLATE],
|
||||
title='This is an openstack ' + itype + ' flavor.',
|
||||
location='/' + quote(itype) + '/')
|
||||
title='This is an openstack ' + itype["name"] + ' flavor.',
|
||||
location='/' + quote(itype["flavorid"]) + '/')
|
||||
|
||||
try:
|
||||
self.registry.get_backend(resource_template, extras)
|
||||
|
@ -236,19 +236,13 @@ class OCCIApplication(occi_wsgi.Application, wsgi.Application):
|
|||
for group in groups:
|
||||
if group['name'] not in excld_grps:
|
||||
sec_mix = os_mixins.UserSecurityGroupMixin(
|
||||
term=self._transformTerm(group['name']),
|
||||
term=str(group["id"]), # NOTE(aloga): group.id is a long
|
||||
scheme=sec_grp,
|
||||
related=[os_addon.SEC_GROUP],
|
||||
attributes=None,
|
||||
title=group['name'],
|
||||
location='/security/' + quote(group['name']) + '/')
|
||||
location='/security/' + quote(str(group['id'])) + '/')
|
||||
try:
|
||||
self.registry.get_backend(sec_mix, extras)
|
||||
except AttributeError:
|
||||
self.register_backend(sec_mix, MIXIN_BACKEND)
|
||||
|
||||
def _transformTerm(self, term):
|
||||
"""
|
||||
Transform a term to be compliant with the spec.
|
||||
"""
|
||||
return term.strip().replace(' ', '_').replace('(', '_').replace(')', '_').replace('.', '_').lower()
|
||||
|
|
Loading…
Reference in New Issue