Support credential API

Adds the `openstack coe credential rotate` command which corresponds to
PATCH /v1/credential/{cluster-uuid} in the API.

Change-Id: I849df62cac5b154d78ead139cf3e0a4ea2fd55ca
Signed-off-by: Matthew Northcott <matthewnorthcott@catalystcloud.nz>
This commit is contained in:
Matthew Northcott
2025-08-05 14:49:07 +12:00
parent eb0db0cd81
commit 6357cfaa79
5 changed files with 79 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from osc_lib.command import command
from osc_lib.i18n import _
class RotateCredential(command.Command):
_description = _("Rotate the credentials for the cluster using the "
"current user account.")
def get_parser(self, prog_name):
parser = super(RotateCredential, self).get_parser(prog_name)
parser.add_argument('cluster',
metavar='<cluster>',
help='ID or name of the cluster')
return parser
def take_action(self, parsed_args):
self.log.debug("take_action(%s)", parsed_args)
mag_client = self.app.client_manager.container_infra
try:
cluster = mag_client.credentials.update(parsed_args.cluster)
except Exception as e:
print("Credential rotation failed: %s" % e)
else:
print("Request to rotate credentials for cluster %s accepted."
% cluster.uuid)

View File

@@ -22,6 +22,7 @@ from magnumclient.common import httpclient
from magnumclient.v1 import certificates
from magnumclient.v1 import cluster_templates
from magnumclient.v1 import clusters
from magnumclient.v1 import credentials
from magnumclient.v1 import mservices
from magnumclient.v1 import nodegroups
from magnumclient.v1 import quotas
@@ -213,3 +214,4 @@ class Client(object):
self.stats = stats.StatsManager(self.http_client)
self.quotas = quotas.QuotasManager(self.http_client)
self.nodegroups = nodegroups.NodeGroupManager(self.http_client)
self.credentials = credentials.CredentialManager(self.http_client)

View File

@@ -0,0 +1,31 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from magnumclient.common import base
class Cluster(base.Resource):
def __repr__(self):
return "<Cluster %s>" % self._info
class CredentialManager(base.Manager):
api_name = "credentials"
resource_class = Cluster
@staticmethod
def _path(id=None):
return "/v1/credentials/%s" % id
def update(self, id):
resp, resp_body = self.api.json_request('PATCH', self._path(id=id))
return self.resource_class(self, resp_body)

View File

@@ -0,0 +1,5 @@
---
features:
- |
Implemented OpenStack command for credential-rotate which can be invoked
with `openstack coe credential rotate <cluster>`.

View File

@@ -66,3 +66,5 @@ openstack.container_infra.v1 =
coe_nodegroup_delete = magnumclient.osc.v1.nodegroups:DeleteNodeGroup
coe_nodegroup_update = magnumclient.osc.v1.nodegroups:UpdateNodeGroup
coe_credential_rotate = magnumclient.osc.v1.credentials:RotateCredential