예제 #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)
예제 #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)
예제 #3
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
예제 #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)
예제 #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)    
예제 #6
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)
예제 #7
0
        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))
        
        # Sanitize instance_id
        if not Sanitizer.whitelist_uuid(instance_id):
            return wsgi.Result(errors.wrap(errors.Input.NONALLOWED_CHARACTERS_INSTANCE_ID))          
        
        try:
            guest_status = models.GuestStatus().find_by(instance_id=instance_id)
        except exception.ReddwarfError, e:
            LOG.error("Could not find DB instance in guest_status table: %s" % instance_id)
            return wsgi.Result(errors.wrap(errors.Instance.NOT_FOUND), 404)

        # Return when instance is not in running state
        if not guest_status['state']:
            LOG.error("Unable to create Snapshot, the instance %s is not in running state." % instance_id)
            return wsgi.Result(errors.wrap(errors.Instance.INSTANCE_NOT_RUNNING), 403)

        if guest_status['state'] != result_state.ResultState.name(result_state.ResultState.RUNNING):
            LOG.error("Unable to create snapshot, the instance %s is locked for operation in progress." % instance_id)