コード例 #1
0
ファイル: k8s_conductor.py プロジェクト: Gobella/magnum
    def rc_delete(self, context, rc_ident, bay_ident):
        LOG.debug("rc_delete %s", rc_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)
        if utils.is_uuid_like(rc_ident):
            rc = objects.ReplicationController.get_by_uuid(context, rc_ident,
                                                           bay_uuid,
                                                           self.k8s_api)
            rc_name = rc.name
        else:
            rc_name = rc_ident
        if conductor_utils.object_has_stack(context, bay_uuid):
            try:
                self.k8s_api.delete_namespaced_replication_controller(
                    name=str(rc_name),
                    body={},
                    namespace='default')
            except rest.ApiException as err:
                if err.status == 404:
                    pass
                else:
                    raise exception.KubernetesAPIFailed(err=err)
コード例 #2
0
ファイル: k8s_conductor.py プロジェクト: leader716/magnum
    def rc_delete(self, context, rc_ident, bay_ident):
        LOG.debug("rc_delete %s", rc_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)
        if utils.is_uuid_like(rc_ident):
            rc = objects.ReplicationController.get_by_uuid(context, rc_ident,
                                                           bay_uuid,
                                                           self.k8s_api)
            rc_name = rc.name
        else:
            rc_name = rc_ident
        if conductor_utils.object_has_stack(context, bay_uuid):
            try:
                self.k8s_api.delete_namespaced_replication_controller(
                    name=str(rc_name),
                    body={},
                    namespace='default')
            except rest.ApiException as err:
                if err.status == 404:
                    pass
                else:
                    raise exception.KubernetesAPIFailed(err=err)
コード例 #3
0
ファイル: k8s_conductor.py プロジェクト: Gobella/magnum
    def rc_show(self, context, rc_ident, bay_ident):
        LOG.debug("rc_show %s", rc_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)
        if utils.is_uuid_like(rc_ident):
            rc = objects.ReplicationController.get_by_uuid(context, rc_ident,
                                                           bay_uuid,
                                                           self.k8s_api)
        else:
            rc = objects.ReplicationController.get_by_name(context, rc_ident,
                                                           bay_uuid,
                                                           self.k8s_api)

        return rc
コード例 #4
0
ファイル: k8s_conductor.py プロジェクト: Gobella/magnum
    def rc_create(self, context, rc):
        LOG.debug("rc_create")
        self.k8s_api = k8s.create_k8s_api_rc(context, rc.bay_uuid)
        manifest = k8s_manifest.parse(rc.manifest)
        try:
            resp = self.k8s_api.create_namespaced_replication_controller(
                body=manifest,
                namespace='default')
        except rest.ApiException as err:
            raise exception.KubernetesAPIFailed(err=err)

        if resp is None:
            raise exception.ReplicationControllerCreationFailed(
                bay_uuid=rc.bay_uuid)

        rc['uuid'] = resp.metadata.uid
        rc['name'] = resp.metadata.name
        rc['images'] = [c.image for c in resp.spec.template.spec.containers]
        rc['labels'] = ast.literal_eval(resp.metadata.labels)
        rc['replicas'] = resp.status.replicas
        return rc
コード例 #5
0
ファイル: k8s_conductor.py プロジェクト: leader716/magnum
    def rc_show(self, context, rc_ident, bay_ident):
        LOG.debug("rc_show %s", rc_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)
        if utils.is_uuid_like(rc_ident):
            rc = objects.ReplicationController.get_by_uuid(context, rc_ident,
                                                           bay_uuid,
                                                           self.k8s_api)
        else:
            rc = objects.ReplicationController.get_by_name(context, rc_ident,
                                                           bay_uuid,
                                                           self.k8s_api)

        return rc
コード例 #6
0
ファイル: k8s_conductor.py プロジェクト: leader716/magnum
    def rc_create(self, context, rc):
        LOG.debug("rc_create")
        self.k8s_api = k8s.create_k8s_api_rc(context, rc.bay_uuid)
        manifest = k8s_manifest.parse(rc.manifest)
        try:
            resp = self.k8s_api.create_namespaced_replication_controller(
                body=manifest,
                namespace='default')
        except rest.ApiException as err:
            raise exception.KubernetesAPIFailed(err=err)

        if resp is None:
            raise exception.ReplicationControllerCreationFailed(
                bay_uuid=rc.bay_uuid)

        rc['uuid'] = resp.metadata.uid
        rc['name'] = resp.metadata.name
        rc['images'] = [c.image for c in resp.spec.template.spec.containers]
        rc['labels'] = ast.literal_eval(resp.metadata.labels)
        rc['replicas'] = resp.status.replicas
        return rc
コード例 #7
0
ファイル: k8s_conductor.py プロジェクト: Gobella/magnum
    def rc_update(self, context, rc_ident, bay_ident, manifest):
        LOG.debug("rc_update %s", rc_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)
        if utils.is_uuid_like(rc_ident):
            rc = objects.ReplicationController.get_by_uuid(context, rc_ident,
                                                           bay_uuid,
                                                           self.k8s_api)
        else:
            rc = objects.ReplicationController.get_by_name(context, rc_ident,
                                                           bay_uuid,
                                                           self.k8s_api)
        try:
            resp = self.k8s_api.replace_namespaced_replication_controller(
                name=str(rc.name),
                body=manifest,
                namespace='default')
        except rest.ApiException as err:
            raise exception.KubernetesAPIFailed(err=err)

        if resp is None:
            raise exception.ReplicationControllerNotFound(rc=rc.uuid)

        rc['uuid'] = resp.metadata.uid
        rc['name'] = resp.metadata.name
        rc['project_id'] = context.project_id
        rc['user_id'] = context.user_id
        rc['images'] = [c.image for c in resp.spec.template.spec.containers]
        rc['bay_uuid'] = bay_uuid
        rc['labels'] = ast.literal_eval(resp.metadata.labels)
        rc['replicas'] = resp.status.replicas

        return rc
コード例 #8
0
ファイル: k8s_conductor.py プロジェクト: leader716/magnum
    def rc_update(self, context, rc_ident, bay_ident, manifest):
        LOG.debug("rc_update %s", rc_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)
        if utils.is_uuid_like(rc_ident):
            rc = objects.ReplicationController.get_by_uuid(context, rc_ident,
                                                           bay_uuid,
                                                           self.k8s_api)
        else:
            rc = objects.ReplicationController.get_by_name(context, rc_ident,
                                                           bay_uuid,
                                                           self.k8s_api)
        try:
            resp = self.k8s_api.replace_namespaced_replication_controller(
                name=str(rc.name),
                body=manifest,
                namespace='default')
        except rest.ApiException as err:
            raise exception.KubernetesAPIFailed(err=err)

        if resp is None:
            raise exception.ReplicationControllerNotFound(rc=rc.uuid)

        rc['uuid'] = resp.metadata.uid
        rc['name'] = resp.metadata.name
        rc['project_id'] = context.project_id
        rc['user_id'] = context.user_id
        rc['images'] = [c.image for c in resp.spec.template.spec.containers]
        rc['bay_uuid'] = bay_uuid
        rc['labels'] = ast.literal_eval(resp.metadata.labels)
        rc['replicas'] = resp.status.replicas

        return rc
コード例 #9
0
ファイル: k8s_conductor.py プロジェクト: Gobella/magnum
    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
コード例 #10
0
ファイル: k8s_conductor.py プロジェクト: leader716/magnum
    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