示例#1
0
文件: experiment.py 项目: zhcf/nauta
    def create(self,
               namespace: str,
               labels: Dict[str, str] = None,
               annotations: Dict[str, str] = None):
        # exclude labels with None values - labels won't be correctly added otherwise
        labels = {key: value
                  for key, value in labels.items()
                  if value} if labels else None

        exp_kubernetes = KubernetesObject(
            self,
            client.V1ObjectMeta(name=self.name,
                                namespace=namespace,
                                labels=labels),
            kind="Experiment",
            apiVersion=f"{self.api_group_name}/{self.crd_version}")
        schema = ExperimentKubernetesSchema()
        body, err = schema.dump(exp_kubernetes)
        if err:
            raise RuntimeError(
                Texts.K8S_DUMP_PREPARATION_ERROR_MSG.format(err=err))
        self.body = body

        response = super().create(namespace=namespace)
        created_exp, err = schema.load(response)
        if err:
            raise RuntimeError(
                Texts.K8S_RESPONSE_LOAD_ERROR_MSG.format(err=err))
        return created_exp
示例#2
0
文件: run.py 项目: yuanbw/nauta
    def create(self,
               namespace: str,
               labels: Dict[str, str] = None,
               annotations: Dict[str, str] = None):
        run_kubernetes = KubernetesObject(
            self,
            client.V1ObjectMeta(name=self.name,
                                namespace=namespace,
                                labels=labels,
                                annotations=annotations),
            kind="Run",
            apiVersion=f"{self.api_group_name}/{self.crd_version}")
        schema = RunKubernetesSchema()
        body, err = schema.dump(run_kubernetes)
        if err:
            raise RuntimeError(
                f'preparing dump of RunKubernetes request object error - {err}'
            )
        self.body = body

        response = super().create(namespace=namespace)
        created_run, err = schema.load(response)
        if err:
            raise RuntimeError(
                f'load of RunKubernetes request object error - {err}')
        return created_run
示例#3
0
    def update(self):
        exp_kubernetes = KubernetesObject(self, client.V1ObjectMeta(name=self.name,
                                                                    namespace=self.namespace),
                                          kind="Experiment", apiVersion=f"{self.api_group_name}/{self.crd_version}")
        schema = ExperimentKubernetesSchema()
        body, err = schema.dump(exp_kubernetes)
        if err:
            raise RuntimeError(Texts.K8S_DUMP_PREPARATION_ERROR_MSG.format(err=err))
        self.body = body

        response = super().update()
        updated_exp, err = schema.load(response)
        if err:
            raise RuntimeError(Texts.K8S_RESPONSE_LOAD_ERROR_MSG.format(err=err))
        return updated_exp
示例#4
0
文件: run.py 项目: yuanbw/nauta
    def update(self):
        run_kubernetes = KubernetesObject(
            self,
            client.V1ObjectMeta(name=self.name, namespace=self.namespace),
            kind="Run",
            apiVersion=f"{self.api_group_name}/{self.crd_version}")
        schema = RunKubernetesSchema()
        body, err = schema.dump(run_kubernetes)
        if err:
            raise RuntimeError(
                f'preparing dump of RunKubernetes request object error - {err}'
            )
        self.body = body

        response = super().update()
        updated_run, err = schema.load(response)
        if err:
            raise RuntimeError(
                f'load of RunKubernetes request object error - {err}')
        return updated_run