def _get_system_variables(self, namespace_id: int) -> Dict: """获取系统变量""" return collect_system_variable( access_token=self.ctx_cluster.context.auth.access_token, project_id=self.ctx_cluster.project_id, namespace_id=namespace_id, )
def update(self, instance, validated_data): ns_info = self.get_ns_info_by_id(instance.namespace_id) perm_ctx = NamespaceScopedPermCtx( username=self.context["request"].user.username, project_id=instance.project_id, cluster_id=ns_info['cluster_id'], name=ns_info['name'], ) NamespaceScopedPermission().can_update(perm_ctx) # update sys variable sys_variables = collect_system_variable( access_token=self.context["request"].user.token.access_token, project_id=instance.project_id, namespace_id=instance.namespace_id, ) return instance.upgrade_app( access_token=self.access_token, chart_version_id=validated_data["upgrade_verion"], answers=validated_data["get_answers"], customs=validated_data["get_customs"], valuefile=validated_data.get("get_valuefile"), updator=self.request_username, sys_variables=sys_variables, valuefile_name=validated_data.get("get_valuefile_name"), cmd_flags=validated_data["cmd_flags"], )
def create(self, validated_data): namespace_info = self.get_ns_info_by_id(validated_data["namespace_info"]) check_cluster_perm( user=self.context["request"].user, project_id=namespace_info["project_id"], cluster_id=namespace_info["cluster_id"], request=self.context["request"], ) sys_variables = collect_system_variable( access_token=self.context["request"].user.token.access_token, project_id=namespace_info["project_id"], namespace_id=namespace_info["id"], ) return App.objects.initialize_app( access_token=self.access_token, name=validated_data.get("name"), project_id=self.project_id, cluster_id=namespace_info["cluster_id"], namespace_id=namespace_info["id"], namespace=namespace_info["name"], chart_version=validated_data["chart_version"], answers=validated_data["get_answers"], customs=validated_data["get_customs"], valuefile=validated_data.get("get_valuefile"), creator=self.request_username, updator=self.request_username, sys_variables=sys_variables, valuefile_name=validated_data.get('get_valuefile_name'), cmd_flags=validated_data["cmd_flags"], )
def _get_bcs_variables(self): sys_variables = bcs_variable.collect_system_variable( access_token=self.access_token, project_id=self.project_id, namespace_id=self.namespace_info["id"]) bcs_variables = bcs_variable.get_bcs_variables( self.project_id, self.namespace_info["cluster_id"], self.namespace_info["id"]) sys_variables.update(bcs_variables) return sys_variables
def _get_bcs_variables(self) -> Dict[str, str]: res_ctx = self.res_ctx namespace_id = res_ctx.namespace_id sys_variables = bcs_variable.collect_system_variable( access_token=res_ctx.access_token, project_id=res_ctx.project_id, namespace_id=namespace_id, ) bcs_variables = bcs_variable.get_bcs_variables(res_ctx.project_id, res_ctx.cluster_id, namespace_id) sys_variables.update(bcs_variables) return sys_variables
def update(self, instance, validated_data): # update sys variable sys_variables = collect_system_variable( access_token=self.context["request"].user.token.access_token, project_id=instance.project_id, namespace_id=instance.namespace_id, ) return instance.upgrade_app( access_token=self.access_token, chart_version_id=validated_data["upgrade_verion"], answers=validated_data["get_answers"], customs=validated_data["get_customs"], valuefile=validated_data.get("get_valuefile"), updator=self.request_username, sys_variables=sys_variables, valuefile_name=validated_data.get("get_valuefile_name"), cmd_flags=validated_data["cmd_flags"], )
def collect_system_variable(self, access_token, project_id, namespace_id): return bcs_variable.collect_system_variable( access_token=access_token, project_id=project_id, namespace_id=namespace_id )