def rc_list(self, context, bay_ident): bay = conductor_utils.retrieve_bay(context, bay_ident) self.k8s_api = k8s.create_k8s_api(context, bay) try: resp = self.k8s_api.list_namespaced_replication_controller( namespace='default') except rest.ApiException as err: raise exception.KubernetesAPIFailed(err=err) if resp is None: raise exception.ReplicationControllerListNotFound( bay_uuid=bay.uuid) rcs = [] for entry in resp._items: rc = {} rc['uuid'] = entry.metadata.uid rc['name'] = entry.metadata.name rc['project_id'] = context.project_id rc['user_id'] = context.user_id rc['images'] = [ c.image for c in entry.spec.template.spec.containers] rc['bay_uuid'] = bay.uuid # Convert string to dictionary rc['labels'] = ast.literal_eval(entry.metadata.labels) rc['replicas'] = entry.status.replicas rc_obj = objects.ReplicationController(context, **rc) rcs.append(rc_obj) return rcs
def rc_list(self, context, bay_ident): # Since bay identifier is specified verify whether its a UUID # or Name. If name is specified as bay identifier need to extract # the bay uuid since its needed to get the k8s_api object. if not utils.is_uuid_like(bay_ident): bay = objects.Bay.get_by_name(context, bay_ident) bay_ident = bay.uuid bay_uuid = bay_ident self.k8s_api = k8s.create_k8s_api_rc(context, bay_uuid) try: resp = self.k8s_api.list_namespaced_replication_controller( namespace='default') except rest.ApiException as err: raise exception.KubernetesAPIFailed(err=err) if resp is None: raise exception.ReplicationControllerListNotFound( bay_uuid=bay_uuid) rcs = [] for entry in resp._items: rc = {} rc['uuid'] = entry.metadata.uid rc['name'] = entry.metadata.name rc['project_id'] = context.project_id rc['user_id'] = context.user_id rc['images'] = [ c.image for c in entry.spec.template.spec.containers] rc['bay_uuid'] = bay_uuid # Convert string to dictionary rc['labels'] = ast.literal_eval(entry.metadata.labels) rc['replicas'] = entry.status.replicas rc_obj = objects.ReplicationController(context, **rc) rcs.append(rc_obj) return rcs
def get_by_uuid(cls, context, uuid, bay_uuid, k8s_api): """Return a :class:`ReplicationController` object based on uuid. :param context: Security context :param uuid: the uuid of a ReplicationController. :param bay_uuid: the UUID of the Bay. :returns: a :class:`ReplicationController` object. """ try: resp = k8s_api.list_namespaced_replication_controller( namespace='default') except rest.ApiException as err: raise exception.KubernetesAPIFailed(err=err) if resp is None: raise exception.ReplicationControllerListNotFound( bay_uuid=bay_uuid) rc = {} for entry in resp.items: if entry.metadata.uid == uuid: rc['uuid'] = entry.metadata.uid rc['name'] = entry.metadata.name rc['project_id'] = context.project_id rc['user_id'] = context.user_id rc['images'] = [ c.image for c in entry.spec.template.spec.containers ] rc['bay_uuid'] = bay_uuid # Convert string to dictionary rc['labels'] = ast.literal_eval(entry.metadata.labels) rc['replicas'] = entry.status.replicas rc_obj = ReplicationController(context, **rc) return rc_obj raise exception.ReplicationControllerNotFound(rc=uuid)