Merge branch 'bug/38'.
This commit is contained in:
commit
2d914987aa
|
@ -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,16 +297,16 @@ 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)
|
||||
if res_tmp:
|
||||
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']
|
||||
if os_tmp:
|
||||
entity.mixins.append(os_tmp)
|
||||
os_tmp = self.get_category('/' + image_id + '/', extras)
|
||||
entity.mixins.append(os_tmp)
|
||||
|
||||
# 3. network links & get links from cache!
|
||||
net_links = net.get_network_details(identifier, context)
|
||||
|
|
|
@ -183,7 +183,7 @@ class OCCIApplication(occi_wsgi.Application, wsgi.Application):
|
|||
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,9 +199,9 @@ 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.keys():
|
||||
for itype in os_flavours.values():
|
||||
resource_template = os_mixins.ResourceTemplate(
|
||||
term=itype,
|
||||
term=itype["flavorid"],
|
||||
scheme=template_schema,
|
||||
related=[infrastructure.RESOURCE_TEMPLATE],
|
||||
title='This is an openstack ' + itype["name"] + ' flavor.',
|
||||
|
@ -241,7 +241,7 @@ class OCCIApplication(occi_wsgi.Application, wsgi.Application):
|
|||
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:
|
||||
|
|
Loading…
Reference in New Issue