Example #1
0
    def reset_password(self, req, tenant_id, id):
        """Resets DB password on remote instance"""
        LOG.info("Resets DB password on Instance %s", id)
        LOG.debug("Req.environ: %s" % req.environ)

        # Sanitize id
        if not Sanitizer.whitelist_uuid(id):
            return wsgi.Result(errors.wrap(errors.Input.NONALLOWED_CHARACTERS_ID))  

        # Return if instance is not found
        try:
            instance = models.GuestStatus().find_by(instance_id=id)
        except exception.ReddwarfError, e:
            LOG.error("Could not find DB instance in guest_status table: %s" % id)
            return wsgi.Result(errors.wrap(errors.Instance.NOT_FOUND), 404)
Example #2
0
    def restart(self, req, tenant_id, id):
        """Restart an instance."""
        LOG.debug("Called restart() with %s, %s" % (tenant_id, id))
        context = rd_context.ReddwarfContext(
                          auth_tok=req.headers["X-Auth-Token"],
                          tenant=tenant_id)        

        # Sanitize id
        if not Sanitizer.whitelist_uuid(id):
            return wsgi.Result(errors.wrap(errors.Input.NONALLOWED_CHARACTERS_ID))  

        try:
            instance = models.DBInstance().find_by(id=id)
        except exception.ReddwarfError, e:
            LOG.error("Could not find db instance %s to restart" % id)
            return wsgi.Result(errors.wrap(errors.Instance.NOT_FOUND), 404)
Example #3
0
 def create(self, req, body, tenant_id):
     
     # find the service id (cant be done yet at startup due to
     # inconsitencies w/ the load app paste
     # TODO(hub-cap): figure out how to get this to work in __init__ time
     # TODO(hub-cap): The problem with this in __init__ is that the paste
     #   config is generated w/ the same config file as the db flags that
     #   are needed for init. These need to be split so the db can be init'd
     #   w/o the paste stuff. Since the paste stuff inits the
     #   database.service module, it is a chicken before the egg problem.
     #   Simple refactor will fix it and we can move this into the __init__
     #   code. Or maybe we shouldnt due to the nature of changing images.
     #   This needs discussion.
     # TODO(hub-cap): turn this into middleware
     LOG.info("Creating a database instance for tenant '%s'" % tenant_id)
     LOG.info("req : '%s'\n\n" % req)
     LOG.info("body : '%s'\n\n" % body)
     context = rd_context.ReddwarfContext(
                       auth_tok=req.headers["X-Auth-Token"],
                       tenant=tenant_id)
     
     try:
         num_instances = self._check_instance_quota(context, 1)
     except exception.QuotaError, e:
         LOG.exception("Quota Error encountered for tenant %s" % tenant_id)
         maximum_instances_allowed = quota.get_tenant_quotas(context, context.tenant)['instances']
         return wsgi.Result(errors.wrap(errors.Instance.QUOTA_EXCEEDED, "You are only allowed to create %s instances on you account." % maximum_instances_allowed), 413)
Example #4
0
 def delete(self, req, tenant_id, id):
     """Delete a single instance."""
     LOG.debug("Delete() called with %s, %s" % (tenant_id, id))
     # TODO(hub-cap): turn this into middleware
     context = rd_context.ReddwarfContext(
                       auth_tok=req.headers["X-Auth-Token"],
                       tenant=tenant_id)
     
     # Sanitize id
     if not Sanitizer.whitelist_uuid(id):
         return wsgi.Result(errors.wrap(errors.Input.NONALLOWED_CHARACTERS_ID))        
     
     try:
         server = models.DBInstance().find_by(id=id, tenant_id=tenant_id, deleted=False)
     except exception.ReddwarfError, e:
         LOG.exception("Attempting to Delete Instance - Exception occurred finding instance by id %s" % id)
         return wsgi.Result(errors.wrap(errors.Instance.NOT_FOUND), 404)
Example #5
0
    def show(self, req, tenant_id, id):
        """Return information about a specific snapshot."""
        LOG.debug("Snapshots.show() called with %s, %s" % (tenant_id, id))
        LOG.debug("Showing all snapshots")
        
        # Sanitize id
        if not Sanitizer.whitelist_uuid(id):
            return wsgi.Result(errors.wrap(errors.Input.NONALLOWED_CHARACTERS_ID))        
        
#        context = rd_context.ReddwarfContext(
#                          auth_tok=req.headers["X-Auth-Token"],
#                          tenant=tenant_id)
#        LOG.debug("Context: %s" % context.to_dict())
        try:
            snapshot = models.Snapshot().find_by(id=id, deleted=False)
        except exception.ReddwarfError, e:            
            LOG.exception("Snapshot Show() failed with an exception")
            return wsgi.Result(errors.wrap(errors.Snapshot.NOT_FOUND), 404)    
Example #6
0
 def _extract_volume_size(self, body):
     volume_size = None
     
     if body['instance'].get('volume', None) is not None:
         try:
             volume_size = int(body['instance']['volume']['size'])
         except ValueError as e:
             return wsgi.Result(errors.wrap(errors.Input.NONINTEGER_VOLUME_SIZE))
         
     return volume_size
Example #7
0
 def delete(self, req, tenant_id, id):
     """Delete a single snapshot."""
     LOG.info("Snapshots delete() called with %s, %s" % (tenant_id, id))
     LOG.debug("Deleting snapshot")
     
     context = rd_context.ReddwarfContext(
                       auth_tok=req.headers["X-Auth-Token"],
                       tenant=tenant_id)
     LOG.debug("Delete() context") 
     
     # Sanitize id
     if not Sanitizer.whitelist_uuid(id):
         return wsgi.Result(errors.wrap(errors.Input.NONALLOWED_CHARACTERS_ID))          
     
     snapshot = None
     try:
         snapshot = models.Snapshot().find_by(id=id)
     except exception.ReddwarfError, e:
         LOG.exception("Failed to find snapshot with id %s to delete" % id)
         return wsgi.Result(errors.wrap(errors.Snapshot.NOT_FOUND), 404)
Example #8
0
    def create(self, req, body, tenant_id):
        """Creates a snapshot."""
        LOG.debug("Snapshots.create() called with %s, %s" % (tenant_id, id))
        LOG.info("Creating a database snapshot for tenant '%s'" % tenant_id)
        LOG.info("req : '%s'\n\n" % req)
        LOG.info("body : '%s'\n\n" % body)

        snapshot_support = CONFIG.get('reddwarf_snapshot_support', True)
        if not utils.bool_from_string(snapshot_support):
            raise exception.NotImplemented("This resource is temporarily not available")

        # Return if instance is not running
        try:
            instance_id = body['snapshot']['instanceId']
        except exception.ReddwarfError, e:
            LOG.exception("body['snapshot']['instanceId'] does not exist")
            return wsgi.Result(errors.wrap(errors.Snapshot.NO_BODY_INSTANCE_ID))
Example #9
0
    def _extract_snapshot(self, body, tenant_id):

        if 'instance' not in body:
            LOG.error("The body passed to create was malformed")
            raise Exception

        if 'snapshotId' in body['instance']:
            snapshot_id = body['instance']['snapshotId']
            if snapshot_id:
                if not Sanitizer.whitelist_uuid(snapshot_id):
                    return wsgi.Result(errors.wrap(errors.Input.NONALLOWED_CHARACTERS_ID)) 
                try:
                    snapshot = models.Snapshot().find_by(id=snapshot_id, tenant_id=tenant_id, deleted=False)
                    return snapshot
                except exception.ReddwarfError, e:
                    LOG.error("Error finding snapshot to create new instance with - Snapshot Record with id %s not found" % snapshot_id)
                    raise e
Example #10
0
            server = models.DBInstance().find_by(id=id, tenant_id=tenant_id, deleted=False)
        except exception.ReddwarfError, e:
            LOG.exception("Exception occurred when finding instance by id %s" % id)
            return wsgi.Result(errors.wrap(errors.Instance.NOT_FOUND), 404)

        try:
            guest_status = models.GuestStatus().find_by(instance_id=server['id'], deleted=False)
        except exception.ReddwarfError, e:
            LOG.exception("Exception occurred when finding instance guest_status by id %s" % id)
            return wsgi.Result(errors.wrap(errors.Instance.NOT_FOUND), 404)
        
        try:
            flavor = models.ServiceFlavor().find_by(id=server['flavor'], deleted=False)
        except exception.ReddwarfError, e:
            LOG.exception("Exception occurred when finding service flavor for instance id %s" % id)
            return wsgi.Result(errors.wrap(errors.Instance.FLAVOR_NOT_FOUND), 404)

        # Find the security group associated with this server
        secgroups = None
        try:
            secgroup_association = security_group_models.SecurityGroupInstances().find_by(instance_id=server['id'], deleted=False)
            secgroups = [ security_group_models.SecurityGroup().find_by(id=secgroup_association['security_group_id'], deleted=False) ]
        except exception.ModelNotFoundError as e:
            # instances created prior to Security Groups feature will not have a security group
            pass

        # TODO(cp16net): need to set the return code correctly
        LOG.debug("Show() executed correctly")
        return wsgi.Result(views.DBInstanceView(server, guest_status, secgroups, req, tenant_id, flavor['flavor_id']).show(), 200)

    def delete(self, req, tenant_id, id):