Skip to content

Commit

Permalink
Raise a better exception when openstack vm_type is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
nuwang committed Apr 20, 2019
1 parent 5f5b2be commit 2d6176f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions cloudbridge/providers/openstack/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
from cloudbridge.base.services import BaseVMFirewallService
from cloudbridge.base.services import BaseVMTypeService
from cloudbridge.base.services import BaseVolumeService
from cloudbridge.interfaces.exceptions \
import CloudBridgeBaseException
from cloudbridge.interfaces.exceptions \
import DuplicateResourceException
from cloudbridge.interfaces.exceptions import InvalidParamException
Expand Down Expand Up @@ -764,10 +766,14 @@ def create(self, label, image, vm_type, subnet,
launch_config=None, **kwargs):
OpenStackInstance.assert_valid_resource_label(label)
image_id = image.id if isinstance(image, MachineImage) else image
vm_size = vm_type.id if \
isinstance(vm_type, VMType) else \
self.provider.compute.vm_types.find(
name=vm_type)[0].id
if isinstance(vm_type, VMType):
vm_size = vm_type.id
else:
vm_type_obj = self.provider.compute.vm_types.find(name=vm_type)
if not vm_type_obj:
raise CloudBridgeBaseException(
"Could not find vm type with name {0}".format(vm_type))
vm_size = vm_type_obj[0].id
if isinstance(subnet, Subnet):
subnet_id = subnet.id
net_id = subnet.network_id
Expand Down

0 comments on commit 2d6176f

Please sign in to comment.