Exemple #1
0
 def _action(self, instance_id, body):
     """
     Perform a server "action" -- reboot/rebuild/resize/etc.
     """
     url = "/instances/%s/action" % instance_id
     resp, body = self.api.client.post(url, body=body)
     check_for_exceptions(resp, body)
 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)
Exemple #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 _list(self, url, response_key):
     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 [self.resource_class(self, res) for res in body[response_key]]
 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 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 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)
 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 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)
Exemple #10
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)
Exemple #11
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)
Exemple #12
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 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)
Exemple #14
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)
Exemple #15
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)
    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)
        check_for_exceptions(resp, body)
        if not body:
            raise Exception("Call to " + url + " did not return a body.")
        return base.Resource(self, body)
Exemple #18
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']]
 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']]
Exemple #20
0
 def _action(self, instance_id, body):
     """
     Perform a server "action" -- reboot/rebuild/resize/etc.
     """
     url = "/instances/%s/action" % instance_id
     resp, body = self.api.client.post(url, body=body)
     check_for_exceptions(resp, body)
     if body:
         return self.resource_class(self, body, loaded=True)
     return body
 def _action(self, instance_id, body):
     """
     Perform a server "action" -- reboot/rebuild/resize/etc.
     """
     url = "/instances/%s/action" % instance_id
     resp, body = self.api.client.post(url, body=body)
     check_for_exceptions(resp, body)
     if body:
         return self.resource_class(self, body, loaded=True)
     return body
Exemple #22
0
    def show(self, tenant_id):
        """Get a list of all quotas for a tenant id"""

        url = "/mgmt/quotas/%s" % tenant_id
        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.")
        if 'quotas' not in body:
            raise Exception("Missing key value 'quotas' in response body.")
        return body['quotas']
Exemple #23
0
    def test_check_for_exceptions(self):
        status = [400, 422, 500]
        for s in status:
            resp = Mock()
            resp.status = s
            self.assertRaises(ValueError, common.check_for_exceptions, resp,
                              "body")

        # a no-exception case
        resp = Mock()
        resp.status = 200
        common.check_for_exceptions(resp, "body")
    def test_check_for_exceptions(self):
        status = [400, 422, 500]
        for s in status:
            resp = Mock()
            resp.status = s
            self.assertRaises(ValueError,
                              common.check_for_exceptions, resp, "body")

        # a no-exception case
        resp = Mock()
        resp.status = 200
        common.check_for_exceptions(resp, "body")
Exemple #25
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)
     check_for_exceptions(resp, body)
     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']
Exemple #26
0
 def _list(self, url, response_key, limit=None, marker=None):
     resp, body = self.api.client.get(limit_url(url, limit, marker))
     check_for_exceptions(resp, body)
     if not body:
         raise Exception("Call to " + url + " did not return a body.")
     links = body.get('links', [])
     next_links = [link['href'] for link in links if link['rel'] == 'next']
     next_marker = None
     for link in next_links:
         # Extract the marker from the url.
         parsed_url = urlparse.urlparse(link)
         query_dict = dict(urlparse.parse_qsl(parsed_url.query))
         next_marker = query_dict.get('marker', None)
     users = [self.resource_class(self, res) for res in body[response_key]]
     return Paginated(users, next_marker=next_marker, links=links)
Exemple #27
0
 def _list(self, url, response_key, limit=None, marker=None):
     resp, body = self.api.client.get(limit_url(url, limit, marker))
     check_for_exceptions(resp, body)
     if not body:
         raise Exception("Call to " + url +
                         " did not return a body.")
     links = body.get('links', [])
     next_links = [link['href'] for link in links if link['rel'] == 'next']
     next_marker = None
     for link in next_links:
         # Extract the marker from the url.
         parsed_url = urlparse.urlparse(link)
         query_dict = dict(urlparse.parse_qsl(parsed_url.query))
         next_marker = query_dict.get('marker', None)
     users = [self.resource_class(self, res) for res in body[response_key]]
     return Paginated(users, next_marker=next_marker, links=links)
Exemple #28
0
 def is_root_enabled(self, instance_id):
     """ Return True if root is enabled for the instance;
     False otherwise"""
     resp, body = self.api.client.get(self.url % instance_id)
     check_for_exceptions(resp, body)
     return body['rootEnabled']
 def delete(self, instance_id, username, hostname=None):
     """Delete an existing user in the specified instance"""
     user = quote_user_host(username, hostname)
     url = "/instances/%s/users/%s" % (instance_id, user)
     resp, body = self.api.client.delete(url)
     check_for_exceptions(resp, body)
 def delete(self, instance_id, dbname):
     """Delete an existing database in the specified instance"""
     url = "/instances/%s/databases/%s" % (instance_id, dbname)
     resp, body = self.api.client.delete(url)
     check_for_exceptions(resp, body)
Exemple #31
0
 def delete(self, instance_id, user):
     """Delete an existing user in the specified instance"""
     url = "/instances/%s/users/%s" % (instance_id, user)
     resp, body = self.api.client.delete(url)
     check_for_exceptions(resp, body)
Exemple #32
0
 def delete(self, instance_id, user):
     """Delete an existing user in the specified instance"""
     url = "/instances/%s/users/%s" % (instance_id, user)
     resp, body = self.api.client.delete(url)
     check_for_exceptions(resp, body)
Exemple #33
0
 def delete(self, instance_id, username, hostname=None):
     """Delete an existing user in the specified instance"""
     user = quote_user_host(username, hostname)
     url = "/instances/%s/users/%s" % (instance_id, user)
     resp, body = self.api.client.delete(url)
     check_for_exceptions(resp, body)
 def delete(self, instance_id, dbname):
     """Delete an existing database in the specified instance"""
     url = "/instances/%s/databases/%s" % (instance_id, dbname)
     resp, body = self.api.client.delete(url)
     check_for_exceptions(resp, body)