Example #1
0
 def _action(self, host_id, body):
     """
     Perform a host "action" -- update
     """
     url = "/mgmt/hosts/%s/instances/action" % host_id
     resp, body = self.api.client.post(url, body=body)
     check_for_exceptions(resp, body)
    def upgrade(self, instance, datastore_version):
        """Upgrades an instance with a new datastore version."""
        body = {"instance": {"datastore_version": datastore_version}}

        url = "/instances/%s" % base.getid(instance)
        resp, body = self.api.client.patch(url, body=body)
        common.check_for_exceptions(resp, body, url)
Example #3
0
 def change_passwords(self, instance, users):
     """Change the password for one or more users."""
     instance_id = base.getid(instance)
     user_dict = {"users": users}
     url = "/instances/%s/users" % instance_id
     resp, body = self.api.client.put(url, body=user_dict)
     check_for_exceptions(resp, body)
 def module_remove(self, instance, module):
     """Remove a module from an instance.
     """
     url = "/instances/%s/modules/%s" % (base.getid(instance),
                                         base.getid(module))
     resp, body = self.api.client.delete(url)
     common.check_for_exceptions(resp, body, url)
Example #5
0
    def update(self,
               instance,
               configuration=None,
               name=None,
               detach_replica_source=False,
               remove_configuration=False,
               is_public=None,
               allowed_cidrs=None):
        """Update instance.

        The configuration change, detach_replica and access change cannot be
        updated at the same time.
        """
        body = {"instance": {}}
        if configuration and remove_configuration:
            raise Exception("Cannot attach and detach configuration "
                            "simultaneously.")
        if remove_configuration:
            body["instance"]["configuration"] = None
        if configuration is not None:
            body["instance"]["configuration"] = base.getid(configuration)
        if name is not None:
            body["instance"]["name"] = name
        if detach_replica_source:
            body["instance"]["replica_of"] = None
        if is_public is not None or allowed_cidrs is not None:
            body["instance"]['access'] = {}
            if is_public is not None:
                body["instance"]['access']['is_public'] = is_public
            if allowed_cidrs is not None:
                body["instance"]['access']['allowed_cidrs'] = allowed_cidrs

        url = "/instances/%s" % base.getid(instance)
        resp, body = self.api.client.put(url, body=body)
        common.check_for_exceptions(resp, body, url)
Example #6
0
 def delete(self, version, name):
     """Mgmt call to delete a configuration parameter."""
     output = {'version_id': version, 'parameter_name': name}
     url = ("/mgmt/datastores/versions/%(version_id)s/"
            "parameters/%(parameter_name)s" % output)
     resp, body = self.api.client.delete(url)
     common.check_for_exceptions(resp, body, url)
Example #7
0
 def _action(self, instance_id, body):
     """
     Perform a server "action" -- reboot/rebuild/resize/etc.
     """
     url = "/mgmt/instances/%s/action" % instance_id
     resp, body = self.api.client.post(url, body=body)
     check_for_exceptions(resp, body)
 def modify(self, instance, configuration=None):
     body = {"instance": {}}
     if configuration is not None:
         body["instance"]["configuration"] = base.getid(configuration)
     url = "/instances/%s" % base.getid(instance)
     resp, body = self.api.client.put(url, body=body)
     common.check_for_exceptions(resp, body, url)
Example #9
0
 def change_passwords(self, instance, users):
     """Change the password for one or more users."""
     instance_id = base.getid(instance)
     user_dict = {"users": users}
     url = "/instances/%s/users" % instance_id
     resp, body = self.api.client.put(url, body=user_dict)
     common.check_for_exceptions(resp, body, url)
    def _log_action(self,
                    instance,
                    log_name,
                    enable=None,
                    disable=None,
                    publish=None,
                    discard=None):
        """Perform action on guest log.

        :param instance: The :class:`Instance` (or its ID) of the database
                         instance to get the log for.
        :param log_name: The name of <log> to publish
        :param enable: Turn on <log>
        :param disable: Turn off <log>
        :param publish: Publish log to associated container
        :param discard: Delete the associated container
        :rtype: List of :class:`DatastoreLog`.
        """
        body = {"name": log_name}
        if enable:
            body.update({'enable': int(enable)})
        if disable:
            body.update({'disable': int(disable)})
        if publish:
            body.update({'publish': int(publish)})
        if discard:
            body.update({'discard': int(discard)})
        url = "/instances/%s/log" % base.getid(instance)
        resp, body = self.api.client.post(url, body=body)
        common.check_for_exceptions(resp, body, url)
        return DatastoreLog(self, body['log'], loaded=True)
Example #11
0
    def edit(self,
             instance,
             configuration=None,
             name=None,
             detach_replica_source=False,
             remove_configuration=False):
        body = {"instance": {}}
        if configuration and remove_configuration:
            raise Exception("Cannot attach and detach configuration "
                            "simultaneously.")
        if remove_configuration:
            body["instance"]["configuration"] = None
        if configuration is not None:
            body["instance"]["configuration"] = configuration
        if name is not None:
            body["instance"]["name"] = name
        if detach_replica_source:
            # TODO(glucas): Remove slave_of after updating trove
            # (see trove.instance.service.InstanceController#edit)
            body["instance"]["slave_of"] = None
            body["instance"]["replica_of"] = None

        url = "/instances/%s" % base.getid(instance)
        resp, body = self.api.client.patch(url, body=body)
        common.check_for_exceptions(resp, body, url)
 def module_remove(self, instance, module):
     """Remove a module from an instance.
     """
     url = "/instances/%s/modules/%s" % (base.getid(instance),
                                         base.getid(module))
     resp, body = self.api.client.delete(url)
     common.check_for_exceptions(resp, body, url)
Example #13
0
 def _action(self, instance_id, body):
     """
     Perform a server "action" -- reboot/rebuild/resize/etc.
     """
     url = "/mgmt/instances/%s/action" % instance_id
     resp, body = self.api.client.post(url, body=body)
     common.check_for_exceptions(resp, body, url)
 def _action(self, host_id, body):
     """
     Perform a host "action" -- update
     """
     url = "/mgmt/hosts/%s/instances/action" % host_id
     resp, body = self.api.client.post(url, body=body)
     common.check_for_exceptions(resp, body, url)
Example #15
0
    def _log_action(self, instance, log_name, enable=None, disable=None,
                    publish=None, discard=None):
        """Perform action on guest log.

        :param instance: The :class:`Instance` (or its ID) of the database
                         instance to get the log for.
        :param log_name: The name of <log> to publish
        :param enable: Turn on <log>
        :param disable: Turn off <log>
        :param publish: Publish log to associated container
        :param discard: Delete the associated container
        :rtype: List of :class:`DatastoreLog`.
        """
        body = {"name": log_name}
        if enable:
            body.update({'enable': int(enable)})
        if disable:
            body.update({'disable': int(disable)})
        if publish:
            body.update({'publish': int(publish)})
        if discard:
            body.update({'discard': int(discard)})
        url = "/instances/%s/log" % base.getid(instance)
        resp, body = self.api.client.post(url, body=body)
        common.check_for_exceptions(resp, body, url)
        return DatastoreLog(self, body['log'], loaded=True)
Example #16
0
    def delete(self, configuration):
        """Delete the specified configuration.

        :param configuration: The configuration id to delete
        """
        url = "/configurations/%s" % base.getid(configuration)
        resp, body = self.api.client.delete(url)
        common.check_for_exceptions(resp, body, url)
Example #17
0
    def delete(self, backup_id):
        """Delete the specified backup.

        :param backup_id: The backup id to delete
        """
        url = "/backups/%s" % backup_id
        resp, body = self.api.client.delete(url)
        common.check_for_exceptions(resp, body, url)
Example #18
0
    def delete(self, security_group_rule):
        """Delete the specified security group rule.

        :param security_group_rule: The security group rule to delete
        """
        url = "/security-group-rules/%s" % base.getid(security_group_rule)
        resp, body = self.api.client.delete(url)
        common.check_for_exceptions(resp, body, url)
Example #19
0
 def module_apply(self, instance, modules):
     """Apply modules to an instance."""
     url = "/instances/%s/modules" % base.getid(instance)
     body = {"modules": self._get_module_list(modules)}
     resp, body = self.api.client.post(url, body=body)
     common.check_for_exceptions(resp, body, url)
     return [core_modules.Module(self, module, loaded=True)
             for module in body['modules']]
 def _action(self, cluster, body):
     """Perform a cluster "action" -- grow/shrink/etc."""
     url = "/clusters/%s" % base.getid(cluster)
     resp, body = self.api.client.post(url, body=body)
     common.check_for_exceptions(resp, body, url)
     if body:
         return self.resource_class(self, body['cluster'], loaded=True)
     return body
    def delete(self, cluster):
        """Delete the specified cluster.

        :param cluster: The cluster to delete
        """
        url = "/clusters/%s" % base.getid(cluster)
        resp, body = self.api.client.delete(url)
        common.check_for_exceptions(resp, body, url)
Example #22
0
 def revoke(self, instance, username, database, hostname=None):
     """Revoke from an existing user access permissions to a database."""
     instance_id = base.getid(instance)
     user = quote_user_host(username, hostname)
     url = "/instances/%(instance_id)s/users/%(user)s/" "databases/%(database)s"
     local_vars = locals()
     resp, body = self.api.client.delete(url % local_vars)
     check_for_exceptions(resp, body)
Example #23
0
 def create(self, instance_id):
     """
     Enable the root user and return the root password for the
     sepcified db instance
     """
     resp, body = self.api.client.post(self.url % instance_id)
     check_for_exceptions(resp, body)
     return body['user']['name'], body['user']['password']
    def delete(self, security_group_rule):
        """Delete the specified security group rule.

        :param security_group_rule: The security group rule to delete
        """
        url = "/security-group-rules/%s" % base.getid(security_group_rule)
        resp, body = self.api.client.delete(url)
        common.check_for_exceptions(resp, body, url)
 def create(self, instance_id, users):
     """
     Create users with permissions to the specified databases
     """
     body = {"users": users}
     url = "/instances/%s/users" % instance_id
     resp, body = self.api.client.post(url, body=body)
     common.check_for_exceptions(resp, body, url)
Example #26
0
 def revoke(self, instance, username, database, hostname=None):
     """Revoke from an existing user access permissions to a database."""
     instance_id = base.getid(instance)
     user = quote_user_host(username, hostname)
     url = ("/instances/%(instance_id)s/users/%(user)s/"
            "databases/%(database)s")
     resp, body = self.api.client.delete(url % locals())
     check_for_exceptions(resp, body)
Example #27
0
 def create(self, instance_id, users):
     """
     Create users with permissions to the specified databases
     """
     body = {"users": users}
     url = "/instances/%s/users" % instance_id
     resp, body = self.api.client.post(url, body=body)
     check_for_exceptions(resp, body)
Example #28
0
 def grant(self, instance, username, databases, hostname=None):
     """Allow an existing user permissions to access a database."""
     instance_id = base.getid(instance)
     user = quote_user_host(username, hostname)
     url = "/instances/%(instance_id)s/users/%(user)s/databases"
     dbs = {'databases': [{'name': db} for db in databases]}
     resp, body = self.api.client.put(url % locals(), body=dbs)
     check_for_exceptions(resp, body)
Example #29
0
 def grant(self, instance, username, databases, hostname=None):
     """Allow an existing user permissions to access a database."""
     instance_id = base.getid(instance)
     user = quote_user_host(username, hostname)
     url = "/instances/%(instance_id)s/users/%(user)s/databases"
     dbs = {'databases': [{'name': db} for db in databases]}
     resp, body = self.api.client.put(url % locals(), body=dbs)
     check_for_exceptions(resp, body)
Example #30
0
 def create(self, instance_id):
     """
     Enable the root user and return the root password for the
     sepcified db instance
     """
     resp, body = self.api.client.post(self.url % instance_id)
     check_for_exceptions(resp, body)
     return body['user']['name'], body['user']['password']
 def create(self, instance_id, databases):
     """
     Create new databases within the specified instance
     """
     body = {"databases": databases}
     url = "/instances/%s/databases" % instance_id
     resp, body = self.api.client.post(url, body=body)
     check_for_exceptions(resp, body)
 def _action(self, instance, body):
     """Perform a server "action" -- reboot/rebuild/resize/etc."""
     url = "/instances/%s/action" % base.getid(instance)
     resp, body = self.api.client.post(url, body=body)
     common.check_for_exceptions(resp, body, url)
     if body:
         return self.resource_class(self, body, loaded=True)
     return body
Example #33
0
 def _action(self, cluster, body):
     """Perform a cluster "action" -- grow/shrink/etc."""
     url = "/clusters/%s" % base.getid(cluster)
     resp, body = self.api.client.post(url, body=body)
     common.check_for_exceptions(resp, body, url)
     if body:
         return self.resource_class(self, body['cluster'], loaded=True)
     return body
    def delete(self, instance):
        """Delete the specified instance.

        :param instance: A reference to the instance to delete
        """
        url = "/instances/%s" % base.getid(instance)
        resp, body = self.api.client.delete(url)
        common.check_for_exceptions(resp, body, url)
Example #35
0
    def delete(self, instance):
        """Delete the specified instance.

        :param instance: A reference to the instance to delete
        """
        url = "/instances/%s" % base.getid(instance)
        resp, body = self.api.client.delete(url)
        common.check_for_exceptions(resp, body, url)
Example #36
0
 def _action(self, instance, body):
     """Perform a server "action" -- reboot/rebuild/resize/etc."""
     url = "/instances/%s/action" % base.getid(instance)
     resp, body = self.api.client.post(url, body=body)
     common.check_for_exceptions(resp, body, url)
     if body:
         return self.resource_class(self, body, loaded=True)
     return body
Example #37
0
    def delete(self, cluster):
        """Delete the specified cluster.

        :param cluster: The cluster to delete
        """
        url = "/clusters/%s" % base.getid(cluster)
        resp, body = self.api.client.delete(url)
        common.check_for_exceptions(resp, body, url)
Example #38
0
    def delete(self, backup):
        """Delete the specified backup.

        :param backup: The backup to delete
        """
        url = "/backups/%s" % base.getid(backup)
        resp, body = self.api.client.delete(url)
        common.check_for_exceptions(resp, body, url)
Example #39
0
 def module_apply(self, instance, modules):
     """Apply modules to an instance."""
     url = "/instances/%s/modules" % base.getid(instance)
     body = {"modules": self._get_module_list(modules)}
     resp, body = self.api.client.post(url, body=body)
     common.check_for_exceptions(resp, body, url)
     return [core_modules.Module(self, module, loaded=True)
             for module in body['modules']]
 def edit(self, configuration_id, values):
     """
     Update an existing configuration.
     """
     body = {"configuration": {"values": json.loads(values)}}
     url = "/configurations/%s" % configuration_id
     resp, body = self.api.client.patch(url, body=body)
     common.check_for_exceptions(resp, body, url)
    def index(self):
        """List all accounts with non-terminated instances"""

        url = "/mgmt/accounts"
        resp, body = self.api.client.get(url)
        common.check_for_exceptions(resp, body, url)
        if not body:
            raise Exception("Call to " + url + " did not return a body.")
        return [self.resource_class(self, res) for res in body['accounts']]
    def index(self):
        """Get a list of all accounts with non-deleted instances"""

        url = "/mgmt/accounts"
        resp, body = self.api.client.get(url)
        check_for_exceptions(resp, body)
        if not body:
            raise Exception("Call to " + url + " did not return a body.")
        return base.Resource(self, body)
    def index(self):
        """Get a list of all accounts with non-deleted instances"""

        url = "/mgmt/accounts"
        resp, body = self.api.client.get(url)
        common.check_for_exceptions(resp, body, url)
        if not body:
            raise Exception("Call to " + url + " did not return a body.")
        return base.Resource(self, body)
Example #44
0
    def create(self, instance_id):
        """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 % instance_id)
        common.check_for_exceptions(resp, body, self.url)
        return body['user']['name'], body['user']['password']
Example #45
0
    def update(self, module, name=None, module_type=None,
               contents=None, description=None,
               all_tenants=None, datastore=None,
               datastore_version=None, auto_apply=None,
               visible=None, live_update=None,
               all_datastores=None, all_datastore_versions=None,
               priority_apply=None, apply_order=None,
               full_access=None):
        """Update an existing module. Passing in
        datastore=None or datastore_version=None has the effect of
        making it available for all datastores/versions.
        """
        body = {
            "module": {
            }
        }
        if name is not None:
            body["module"]["name"] = name
        if module_type is not None:
            body["module"]["type"] = module_type
        if contents is not None:
            contents = utils.encode_data(contents)
            body["module"]["contents"] = contents
        if description is not None:
            body["module"]["description"] = description
        datastore_obj = {}
        if datastore:
            datastore_obj["type"] = datastore
        if datastore_version:
            datastore_obj["version"] = datastore_version
        if datastore_obj:
            body["module"]["datastore"] = datastore_obj
        if all_datastores:
            body["module"]["all_datastores"] = int(all_datastores)
        if all_datastore_versions:
            body["module"]["all_datastore_versions"] = int(
                all_datastore_versions)
        if all_tenants is not None:
            body["module"]["all_tenants"] = int(all_tenants)
        if auto_apply is not None:
            body["module"]["auto_apply"] = int(auto_apply)
        if visible is not None:
            body["module"]["visible"] = int(visible)
        if live_update is not None:
            body["module"]["live_update"] = int(live_update)
        if priority_apply is not None:
            body["module"]["priority_apply"] = int(priority_apply)
        if apply_order is not None:
            body["module"]["apply_order"] = apply_order
        if full_access is not None:
            body["module"]["full_access"] = int(full_access)

        url = "/modules/%s" % base.getid(module)
        resp, body = self.api.client.put(url, body=body)
        common.check_for_exceptions(resp, body, url)
        return Module(self, body['module'], loaded=True)
Example #46
0
 def update(self, configuration_id, values, name=None, description=None):
     """Update an existing configuration."""
     body = {"configuration": {"values": json.loads(values)}}
     if name:
         body['configuration']['name'] = name
     if description:
         body['configuration']['description'] = description
     url = "/configurations/%s" % configuration_id
     resp, body = self.api.client.put(url, body=body)
     common.check_for_exceptions(resp, body, url)
Example #47
0
    def edit(self, instance_id, configuration=None, name=None):
        body = {"instance": {}}
        if configuration is not None:
            body["instance"]["configuration"] = configuration
        if name is not None:
            body["instance"]["name"] = name

        url = "/instances/%s" % instance_id
        resp, body = self.api.client.patch(url, body=body)
        common.check_for_exceptions(resp, body, url)
 def show(self, tenant_id):
     """Get a list of quota limits for a tenant"""
     url = "/mgmt/quotas/%s" % tenant_id
     resp, body = self.api.client.get(url)
     common.check_for_exceptions(resp, body, url)
     if not body:
         raise Exception("Call to " + url + " did not return a body.")
     if 'quotas' not in body:
         raise Exception("Missing key value 'quotas' in response body.")
     return body['quotas']
 def edit(self, configuration, values):
     """Update an existing configuration."""
     body = {
         "configuration": {
             "values": json.loads(values)
         }
     }
     url = "/configurations/%s" % base.getid(configuration)
     resp, body = self.api.client.patch(url, body=body)
     common.check_for_exceptions(resp, body, url)
 def delete(self, version, name):
     """Mgmt call to delete a configuration parameter."""
     output = {
         'version_id': version,
         'parameter_name': name
     }
     url = ("/mgmt/datastores/versions/%(version_id)s/"
            "parameters/%(parameter_name)s" % output)
     resp, body = self.api.client.delete(url)
     common.check_for_exceptions(resp, body, url)
Example #51
0
 def modify(self, instance, configuration=None):
     body = {
         "instance": {
         }
     }
     if configuration is not None:
         body["instance"]["configuration"] = base.getid(configuration)
     url = "/instances/%s" % base.getid(instance)
     resp, body = self.api.client.put(url, body=body)
     common.check_for_exceptions(resp, body, url)
Example #52
0
 def list_access(self, instance, username, hostname=None):
     """Show all databases the given user has access to. """
     instance_id = base.getid(instance)
     user = quote_user_host(username, hostname)
     url = "/instances/%(instance_id)s/users/%(user)s/databases"
     resp, body = self.api.client.get(url % locals())
     check_for_exceptions(resp, body)
     if not body:
         raise Exception("Call to %s did not return to a body" % url)
     return [databases.Database(self, db) for db in body['databases']]
Example #53
0
 def list_access(self, instance, username, hostname=None):
     """Show all databases the given user has access to. """
     instance_id = base.getid(instance)
     user = quote_user_host(username, hostname)
     url = "/instances/%(instance_id)s/users/%(user)s/databases"
     resp, body = self.api.client.get(url % locals())
     check_for_exceptions(resp, body)
     if not body:
         raise Exception("Call to %s did not return to a body" % url)
     return [databases.Database(self, db) for db in body['databases']]
Example #54
0
    def log_list(self, instance):
        """Get a list of all guest logs.

        :param instance: The :class:`Instance` (or its ID) of the database
                         instance to get the log for.
        :rtype: list of :class:`DatastoreLog`.
        """
        url = '/instances/%s/log' % base.getid(instance)
        resp, body = self.api.client.get(url)
        common.check_for_exceptions(resp, body, url)
        return [DatastoreLog(self, log, loaded=True) for log in body['logs']]
Example #55
0
 def update(self, id, quotas):
     """Set limits for quotas."""
     url = "/mgmt/quotas/%s" % id
     body = {"quotas": quotas}
     resp, body = self.api.client.put(url, body=body)
     common.check_for_exceptions(resp, body, url)
     if not body:
         raise Exception("Call to " + url + " did not return a body.")
     if 'quotas' not in body:
         raise Exception("Missing key value 'quotas' in response body.")
     return body['quotas']
Example #56
0
    def upgrade(self, instance, datastore_version):
        """Upgrades an instance with a new datastore version."""
        body = {
            "instance": {
                "datastore_version": datastore_version
            }
        }

        url = "/instances/%s" % base.getid(instance)
        resp, body = self.api.client.patch(url, body=body)
        common.check_for_exceptions(resp, body, url)