From: Pedro Gonzalez Gomez Date: Thu, 20 Jun 2024 14:22:40 +0000 (+0200) Subject: mgr/dashboard: enable editing of cluster api url on multi-cluster edit form and fix... X-Git-Tag: v20.0.0~1530^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=23c2cda3e7af9a6248843aabce249d693690bf55;p=ceph.git mgr/dashboard: enable editing of cluster api url on multi-cluster edit form and fix password field as required - Removes unnecessary comments - Alias name can keep its name when editing Fixes: https://tracker.ceph.com/issues/66770 Signed-off-by: Pedro Gonzalez Gomez --- diff --git a/src/pybind/mgr/dashboard/controllers/multi_cluster.py b/src/pybind/mgr/dashboard/controllers/multi_cluster.py index 8fdecf99d4448..87cc8314ae4b8 100644 --- a/src/pybind/mgr/dashboard/controllers/multi_cluster.py +++ b/src/pybind/mgr/dashboard/controllers/multi_cluster.py @@ -267,12 +267,13 @@ class MultiCluster(RESTController): @Endpoint('PUT') @UpdatePermission # pylint: disable=unused-variable - def edit_cluster(self, url, cluster_alias, username, verify=False, ssl_certificate=None): + def edit_cluster(self, name, url, cluster_alias, username, verify=False, ssl_certificate=None): multicluster_config = self.load_multi_cluster_config() if "config" in multicluster_config: for key, cluster_details in multicluster_config["config"].items(): for cluster in cluster_details: - if cluster["url"] == url and cluster["user"] == username: + if cluster["name"] == name and cluster["user"] == username: + cluster['url'] = url cluster['cluster_alias'] = cluster_alias cluster['ssl_verify'] = verify cluster['ssl_certificate'] = ssl_certificate if verify else '' diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/multi-cluster/multi-cluster-form/multi-cluster-form.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/multi-cluster/multi-cluster-form/multi-cluster-form.component.html index 6cc09c772b18f..4bdb2ad45c991 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/multi-cluster/multi-cluster-form/multi-cluster-form.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/multi-cluster/multi-cluster-form/multi-cluster-form.component.html @@ -117,7 +117,7 @@ This field is required. diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/multi-cluster/multi-cluster-form/multi-cluster-form.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/multi-cluster/multi-cluster-form/multi-cluster-form.component.ts index 32548f63c8a35..596ddff11ecf5 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/multi-cluster/multi-cluster-form/multi-cluster-form.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/multi-cluster/multi-cluster-form/multi-cluster-form.component.ts @@ -52,7 +52,6 @@ export class MultiClusterFormComponent implements OnInit, OnDestroy { ngOnInit(): void { if (this.action === 'edit') { this.remoteClusterForm.get('remoteClusterUrl').setValue(this.cluster.url); - this.remoteClusterForm.get('remoteClusterUrl').disable(); this.remoteClusterForm.get('clusterAlias').setValue(this.cluster.cluster_alias); this.remoteClusterForm.get('ssl').setValue(this.cluster.ssl_verify); this.remoteClusterForm.get('ssl_cert').setValue(this.cluster.ssl_certificate); @@ -76,7 +75,6 @@ export class MultiClusterFormComponent implements OnInit, OnDestroy { createForm() { this.remoteClusterForm = new CdFormGroup({ - // showToken: new FormControl(false), username: new FormControl('', [ CdValidators.custom('uniqueUrlandUser', (username: string) => { let remoteClusterUrl = ''; @@ -96,7 +94,12 @@ export class MultiClusterFormComponent implements OnInit, OnDestroy { ); }) ]), - password: new FormControl('', []), + password: new FormControl( + null, + CdValidators.custom('requiredNotEdit', (value: string) => { + return this.action !== 'edit' && !value; + }) + ), remoteClusterUrl: new FormControl(null, { validators: [ CdValidators.custom('endpoint', (value: string) => { @@ -116,11 +119,6 @@ export class MultiClusterFormComponent implements OnInit, OnDestroy { Validators.required ] }), - // apiToken: new FormControl('', [ - // CdValidators.requiredIf({ - // showToken: true - // }) - // ]), clusterAlias: new FormControl(null, { validators: [ Validators.required, @@ -128,7 +126,9 @@ export class MultiClusterFormComponent implements OnInit, OnDestroy { return ( (this.action === 'connect' || this.action === 'edit') && this.clusterAliasNames && - this.clusterAliasNames.indexOf(clusterAlias) !== -1 + this.clusterAliasNames.indexOf(clusterAlias) !== -1 && + this.cluster?.cluster_alias && + this.cluster.cluster_alias !== clusterAlias ); }) ] @@ -197,7 +197,14 @@ export class MultiClusterFormComponent implements OnInit, OnDestroy { case 'edit': this.subs.add( this.multiClusterService - .editCluster(this.cluster.url, clusterAlias, this.cluster.user, ssl, ssl_certificate) + .editCluster( + this.cluster.name, + url, + clusterAlias, + this.cluster.user, + ssl, + ssl_certificate + ) .subscribe({ ...commonSubscribtion, complete: () => this.handleSuccess($localize`Cluster updated successfully`) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/multi-cluster.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/multi-cluster.service.ts index 5a03abd22ff74..df901697e6827 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/multi-cluster.service.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/multi-cluster.service.ts @@ -116,6 +116,7 @@ export class MultiClusterService { } editCluster( + name: string, url: any, clusterAlias: string, username: string, @@ -123,6 +124,7 @@ export class MultiClusterService { ssl_certificate = '' ) { return this.http.put('api/multi-cluster/edit_cluster', { + name: name, url, cluster_alias: clusterAlias, username: username, diff --git a/src/pybind/mgr/dashboard/openapi.yaml b/src/pybind/mgr/dashboard/openapi.yaml index 99c4ee54f0b8b..ae2fdd8bb02c1 100644 --- a/src/pybind/mgr/dashboard/openapi.yaml +++ b/src/pybind/mgr/dashboard/openapi.yaml @@ -7244,6 +7244,8 @@ paths: properties: cluster_alias: type: string + name: + type: string ssl_certificate: type: string url: @@ -7254,6 +7256,7 @@ paths: default: false type: boolean required: + - name - url - cluster_alias - username