X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=rwlaunchpad%2Fplugins%2Frwresmgr%2Frift%2Ftasklets%2Frwresmgrtasklet%2Frwresmgr_core.py;h=ccdd631e14ebf0d196f8d5c0eeb673eaf0a09cf1;hb=cc9351abd1516546e8ed0875aa0a0503547d33d1;hp=d2897f877f2e2c570e76c4b905b409f31c1bbf8f;hpb=6f07e6f33f751ab4ffe624f6037f887b243bece2;p=osm%2FSO.git diff --git a/rwlaunchpad/plugins/rwresmgr/rift/tasklets/rwresmgrtasklet/rwresmgr_core.py b/rwlaunchpad/plugins/rwresmgr/rift/tasklets/rwresmgrtasklet/rwresmgr_core.py index d2897f87..ccdd631e 100644 --- a/rwlaunchpad/plugins/rwresmgr/rift/tasklets/rwresmgrtasklet/rwresmgr_core.py +++ b/rwlaunchpad/plugins/rwresmgr/rift/tasklets/rwresmgrtasklet/rwresmgr_core.py @@ -126,7 +126,12 @@ class ResourceMgrCALHandler(object): links = [vlink for vlink in rsp.virtual_link_info_list if vlink.name == req_params.name] if links: self._log.debug("Found existing virtual-network with matching name in cloud. Reusing the virtual-network with id: %s" %(links[0].virtual_link_id)) - return ('precreated', links[0].virtual_link_id) + if req_params.vim_network_name: + resource_type = 'precreated' + else: + # This is case of realloc + resource_type = 'dynamic' + return (resource_type, links[0].virtual_link_id) elif req_params.vim_network_name: self._log.error("Virtual-network-allocate operation failed for cloud account: %s Vim Network with name %s does not pre-exist", self._account.name, req_params.vim_network_name) @@ -183,6 +188,7 @@ class ResourceMgrCALHandler(object): def create_virtual_compute(self, req_params): #rc, rsp = self._rwcal.get_vdu_list(self._account) self._log.debug("Calling get_vdu_list API") + rc, rsp = yield from self._loop.run_in_executor(self._executor, self._rwcal.get_vdu_list, self._account) @@ -195,8 +201,9 @@ class ResourceMgrCALHandler(object): params = RwcalYang.VDUInitParams() params.from_dict(req_params.as_dict()) - image_checksum = req_params.image_checksum if req_params.has_field("image_checksum") else None - params.image_id = yield from self.get_image_id_from_image_info(req_params.image_name, image_checksum) + if 'image_name' in req_params: + image_checksum = req_params.image_checksum if req_params.has_field("image_checksum") else None + params.image_id = yield from self.get_image_id_from_image_info(req_params.image_name, image_checksum) #rc, rs = self._rwcal.create_vdu(self._account, params) self._log.debug("Calling create_vdu API with params %s" %(str(params))) @@ -350,9 +357,10 @@ class ResourceMgrCALHandler(object): class Resource(object): - def __init__(self, resource_id, resource_type): + def __init__(self, resource_id, resource_type, request): self._id = resource_id self._type = resource_type + self._request = request @property def resource_id(self): @@ -362,18 +370,20 @@ class Resource(object): def resource_type(self): return self._type + @property + def request(self): + return self._request + def cleanup(self): pass class ComputeResource(Resource): - def __init__(self, resource_id, resource_type): - super(ComputeResource, self).__init__(resource_id, resource_type) + pass class NetworkResource(Resource): - def __init__(self, resource_id, resource_type): - super(NetworkResource, self).__init__(resource_id, resource_type) + pass class ResourcePoolInfo(object): @@ -614,10 +624,10 @@ class NetworkPool(ResourcePool): if resource_id in self._all_resources: self._log.error("Resource with id %s name %s of type %s is already used", resource_id, request.name, resource_type) raise ResMgrNoResourcesAvailable("Resource with name %s of type network is already used" %(resource_id)) - resource = self._resource_class(resource_id, resource_type) + resource = self._resource_class(resource_id, resource_type, request) self._all_resources[resource_id] = resource self._allocated_resources[resource_id] = resource - self._log.info("Successfully allocated virtual-network resource from CAL with resource-id: %s", resource_id) + self._log.info("Successfully allocated virtual-network resource from CAL with resource-id: %s resource type %s", resource_id, resource_type) return resource @asyncio.coroutine @@ -742,7 +752,7 @@ class ComputePool(ResourcePool): def allocate_dynamic_resource(self, request): #request.flavor_id = yield from self.select_resource_flavor(request) resource_id = yield from self._cal.create_virtual_compute(request) - resource = self._resource_class(resource_id, 'dynamic') + resource = self._resource_class(resource_id, 'dynamic', request) self._all_resources[resource_id] = resource self._allocated_resources[resource_id] = resource self._log.info("Successfully allocated virtual-compute resource from CAL with resource-id: %s", resource_id) @@ -763,6 +773,7 @@ class ComputePool(ResourcePool): @asyncio.coroutine def get_resource_info(self, resource): info = yield from self._cal.get_virtual_compute_info(resource.resource_id) + self._log.info("Successfully retrieved virtual-compute information from CAL with resource-id: %s. Info: %s", resource.resource_id, str(info)) response = RwResourceMgrYang.VDUEventData_ResourceInfo() @@ -779,6 +790,19 @@ class ComputePool(ResourcePool): return info def _get_resource_state(self, resource_info, requested_params): + + + def conn_pts_len_equal(): + # if explicit mgmt network is defined then the allocated ports might + # one more than the expected. + allocated_ports = len(resource_info.connection_points) + requested_ports = len(requested_params.connection_points) + + if not requested_params.mgmt_network: + allocated_ports -= 1 + + return allocated_ports == requested_ports + if resource_info.state == 'failed': self._log.error(" Reached failed state.", resource_info.name) @@ -800,8 +824,7 @@ class ComputePool(ResourcePool): resource_info.name, requested_params) return 'pending' - if(len(requested_params.connection_points) != - len(resource_info.connection_points)): + if not conn_pts_len_equal(): self._log.warning(" Waiting for requested number of ports to be assigned to virtual-compute, requested: %d, assigned: %d", resource_info.name, len(requested_params.connection_points), @@ -1423,6 +1446,7 @@ class ResourceMgrCore(object): self._log.error("Event-id conflict. Duplicate event-id: %s", event_id) raise ResMgrDuplicateEventId("Requested event-id :%s already active with pool: %s" %(event_id, pool_name)) + self._log.debug("Re-allocate virtual resource. resource type %s", resource_type) r_info = None cloud_pool_table = self._get_cloud_pool_table(cloud_account_name) pool = cloud_pool_table[resource.pool_name] @@ -1440,7 +1464,7 @@ class ResourceMgrCore(object): return r_info self._resource_table[event_id] = (r_id, cloud_account_name, resource.pool_name) - new_resource = pool._resource_class(r_id, 'dynamic') + new_resource = pool._resource_class(r_id, 'dynamic', request) if resource_type == 'compute': requested_params = RwcalYang.VDUInitParams() requested_params.from_dict(request.as_dict())