Ejemplo n.º 1
0
    def get(self):
        """This method handles the GET requests to retrieve status on instances from the Cloud Verifier. 
        
        Currently, only instances resources are available for GETing, i.e. /v1/instances. All other GET uri's 
        will return errors. instances requests require a single instance_id parameter which identifies the 
        instance to be returned. If the instance_id is not found, a 404 response is returned.  If the instance_id
        was not found, it either completed successfully, or failed.  If found, the instance_id is still polling 
        to contact the Cloud Node. 
        """
        instance_id = self.get_argument("instance_id",
                                        default=None,
                                        strip=True)
        if instance_id is not None:
            instance = cloud_verifier_common.get_instance(instance_id)
            if instance != None:
                response = cloud_verifier_common.process_get_status(instance)
                self.set_status(200)
                self.write(response)
                logger.info('GET returning 200 response for instance_id: ' +
                            instance_id)

            else:
                logger.info('GET returning 404 response. instance_id: ' +
                            instance_id + ' not found.')
                self.set_status(404)
        else:
            # return the available keys in the DB
            json_response = cloud_verifier_common.get_instance_ids()
            self.set_status(200)
            #Since the data is essentially a string, set the content type explicitly
            self.set_header('Content-Type', 'application/json')
            print json_response
            self.write(json_response)
            logger.info('GET returning 200 response for instance_id list')
    def get(self):
        """This method handles the GET requests to retrieve status on instances from the Cloud Verifier. 
        
        Currently, only instances resources are available for GETing, i.e. /v2/instances. All other GET uri's 
        will return errors. instances requests require a single instance_id parameter which identifies the 
        instance to be returned. If the instance_id is not found, a 404 response is returned.  If the instance_id
        was not found, it either completed successfully, or failed.  If found, the instance_id is still polling 
        to contact the Cloud Node. 
        """
        rest_params = common.get_restful_params(self.request.path)
        if rest_params is None:
            common.echo_json_response(
                self, 405, "Not Implemented: Use /v2/instances/ interface")
            return

        if "instances" not in rest_params:
            common.echo_json_response(self, 400, "uri not supported")
            logger.warning('GET returning 400 response. uri not supported: ' +
                           self.request.path)
            return

        instance_id = rest_params["instances"]

        if instance_id is not None:
            instance = self.db.get_instance(instance_id)
            if instance != None:
                response = cloud_verifier_common.process_get_status(instance)
                common.echo_json_response(self, 200, "Success", response)
                #logger.info('GET returning 200 response for instance_id: ' + instance_id)

            else:
                #logger.info('GET returning 404 response. instance id: ' + instance_id + ' not found.')
                common.echo_json_response(self, 404, "instance id not found")
        else:
            # return the available keys in the DB
            json_response = self.db.get_instance_ids()
            common.echo_json_response(self, 200, "Success",
                                      {'uuids': json_response})
            logger.info('GET returning 200 response for instance_id list')