diff options
Diffstat (limited to 'troveclient/v1/root.py')
| -rw-r--r-- | troveclient/v1/root.py | 45 |
1 files changed, 39 insertions, 6 deletions
diff --git a/troveclient/v1/root.py b/troveclient/v1/root.py index 6246219..99c6672 100644 --- a/troveclient/v1/root.py +++ b/troveclient/v1/root.py @@ -22,22 +22,55 @@ from troveclient.v1 import users class Root(base.ManagerWithFind): """Manager class for Root resource.""" resource_class = users.User - url = "/instances/%s/root" + instances_url = "/instances/%s/root" + clusters_url = "/clusters/%s/root" def create(self, instance): """Implements root-enable API. - Enable the root user and return the root password for the specified db instance. """ - resp, body = self.api.client.post(self.url % base.getid(instance)) - common.check_for_exceptions(resp, body, self.url) + return self.create_instance_root(instance) + + def create_instance_root(self, instance, root_password=None): + """Implements root-enable for instances.""" + return self._enable_root(self.instances_url % base.getid(instance), + root_password) + + def create_cluster_root(self, cluster, root_password=None): + """Implements root-enable for clusters.""" + return self._enable_root(self.clusters_url % base.getid(cluster), + root_password) + + def _enable_root(self, uri, root_password=None): + """Implements root-enable API. + Enable the root user and return the root password for the + specified db instance or cluster. + """ + if root_password: + resp, body = self.api.client.post(uri, + body={"password": root_password}) + else: + resp, body = self.api.client.post(uri) + common.check_for_exceptions(resp, body, uri) return body['user']['name'], body['user']['password'] def is_root_enabled(self, instance): """Return whether root is enabled for the instance.""" - resp, body = self.api.client.get(self.url % base.getid(instance)) - common.check_for_exceptions(resp, body, self.url) + return self.is_instance_root_enabled(instance) + + def is_instance_root_enabled(self, instance): + """Returns whether root is enabled for the instance.""" + return self._is_root_enabled(self.instances_url % base.getid(instance)) + + def is_cluster_root_enabled(self, cluster): + """Returns whether root is enabled for the cluster.""" + return self._is_root_enabled(self.clusters_url % base.getid(cluster)) + + def _is_root_enabled(self, uri): + """Return whether root is enabled for the instance or the cluster.""" + resp, body = self.api.client.get(uri) + common.check_for_exceptions(resp, body, uri) return self.resource_class(self, body, loaded=True) # Appease the abc gods |
