Beispiel #1
0
    def post(self, compute_id, request_data):
        """
        Perform a migrate against a virtual compute resource
        """
        DLOG.verbose("Compute-API migrate called for compute %s, "
                     "migrate_type=%s." %
                     (compute_id, request_data.migrate_type))

        if not validate.valid_uuid_str(compute_id):
            DLOG.error("Invalid uuid received, uuid=%s." % compute_id)
            return pecan.abort(httplib.BAD_REQUEST)

        http_response = httplib.BAD_REQUEST

        if 'live' == request_data.migrate_type:
            rpc_request = rpc.APIRequestLiveMigrateInstance()
            rpc_request.uuid = compute_id
            http_response = self._do_migrate(rpc_request)

        elif 'cold' == request_data.migrate_type:
            rpc_request = rpc.APIRequestColdMigrateInstance()
            rpc_request.uuid = compute_id
            http_response = self._do_migrate(rpc_request)

        elif 'evacuate' == request_data.migrate_type:
            rpc_request = rpc.APIRequestEvacuateInstance()
            rpc_request.uuid = compute_id
            http_response = self._do_migrate(rpc_request)

        if httplib.ACCEPTED != http_response:
            DLOG.error("Compute migrate %s failed for %s, http_response=%s." %
                       (request_data.migrate_type, compute_id, http_response))
            return pecan.abort(http_response)
Beispiel #2
0
    def delete(self, volume_uuid):
        DLOG.verbose("Volume-API delete called for volume %s." % volume_uuid)

        if not validate.valid_uuid_str(volume_uuid):
            DLOG.error("Invalid uuid received, uuid=%s." % volume_uuid)
            return pecan.abort(httplib.BAD_REQUEST)

        vim_connection = pecan.request.vim.open_connection()
        rpc_request = rpc.APIRequestDeleteVolume()
        rpc_request.uuid = volume_uuid
        vim_connection.send(rpc_request.serialize())
        msg = vim_connection.receive()
        if msg is None:
            DLOG.error("No response received for volume %s." % volume_uuid)
            return pecan.abort(httplib.INTERNAL_SERVER_ERROR)

        response = rpc.RPCMessage.deserialize(msg)
        if rpc.RPC_MSG_TYPE.DELETE_VOLUME_RESPONSE != response.type:
            DLOG.error("Unexpected message type received, msg_type=%s." %
                       response.type)
            return pecan.abort(httplib.INTERNAL_SERVER_ERROR)

        if rpc.RPC_MSG_RESULT.NOT_FOUND == response.result:
            DLOG.debug("Volume %s was not found." % volume_uuid)
            return pecan.abort(httplib.NOT_FOUND)

        elif rpc.RPC_MSG_RESULT.SUCCESS == response.result:
            return None

        DLOG.error("Unexpected result received for volume %s, result=%s." %
                   (volume_uuid, response.result))
        return pecan.abort(httplib.INTERNAL_SERVER_ERROR)
Beispiel #3
0
    def post(self, compute_id, request_data):
        """
        Perform an operation against a virtual compute resource
        """
        DLOG.verbose("Compute-API operate called for compute %s, "
                     "operation=%s." %
                     (compute_id, request_data.compute_operation))

        if not validate.valid_uuid_str(compute_id):
            DLOG.error("Invalid uuid received, uuid=%s." % compute_id)
            return pecan.abort(httplib.BAD_REQUEST)

        http_response = httplib.BAD_REQUEST

        if 'start' == request_data.compute_operation:
            rpc_request = rpc.APIRequestStartInstance()
            rpc_request.uuid = compute_id
            http_response = self._do_operation(rpc_request)

        elif 'stop' == request_data.compute_operation:
            rpc_request = rpc.APIRequestStopInstance()
            rpc_request.uuid = compute_id
            http_response = self._do_operation(rpc_request)

        elif 'pause' == request_data.compute_operation:
            rpc_request = rpc.APIRequestPauseInstance()
            rpc_request.uuid = compute_id
            http_response = self._do_operation(rpc_request)

        elif 'unpause' == request_data.compute_operation:
            rpc_request = rpc.APIRequestUnpauseInstance()
            rpc_request.uuid = compute_id
            http_response = self._do_operation(rpc_request)

        elif 'suspend' == request_data.compute_operation:
            rpc_request = rpc.APIRequestSuspendInstance()
            rpc_request.uuid = compute_id
            http_response = self._do_operation(rpc_request)

        elif 'resume' == request_data.compute_operation:
            rpc_request = rpc.APIRequestResumeInstance()
            rpc_request.uuid = compute_id
            http_response = self._do_operation(rpc_request)

        elif 'reboot' == request_data.compute_operation:
            rpc_request = rpc.APIRequestRebootInstance()
            rpc_request.uuid = compute_id
            http_response = self._do_operation(rpc_request)

        if httplib.ACCEPTED != http_response:
            DLOG.error(
                "Compute operation %s failed for %s, http_response=%s." %
                (request_data.compute_operation, compute_id, http_response))
            return pecan.abort(http_response)
Beispiel #4
0
    def get_one(self, compute_id):
        if not validate.valid_uuid_str(compute_id):
            DLOG.error("Invalid uuid received, uuid=%s." % compute_id)
            return pecan.abort(httplib.BAD_REQUEST)

        compute = ComputeQueryData()
        http_response = self._get_compute_details(compute_id, compute)
        if httplib.OK == http_response:
            return compute
        else:
            return pecan.abort(http_response)
Beispiel #5
0
    def get_one(self, volume_uuid):
        DLOG.verbose("Volume-API get called for volume %s." % volume_uuid)

        if not validate.valid_uuid_str(volume_uuid):
            DLOG.error("Invalid uuid received, uuid=%s." % volume_uuid)
            return pecan.abort(httplib.BAD_REQUEST)

        volume = VolumeQueryData()
        http_response = self._get_volume_details(volume_uuid, volume)
        if httplib.OK == http_response:
            return volume
        else:
            return pecan.abort(http_response)
Beispiel #6
0
    def get_one(self, image_uuid):
        DLOG.verbose("Image-API get called for image %s." % image_uuid)

        if not validate.valid_uuid_str(image_uuid):
            DLOG.error("Invalid uuid received, uuid=%s." % image_uuid)
            return pecan.abort(httplib.BAD_REQUEST)

        image = ImageQueryData()
        http_response = self._get_image_details(image_uuid, image)
        if httplib.OK == http_response:
            return image
        else:
            return pecan.abort(http_response)
Beispiel #7
0
    def put(self, volume_uuid, volume_update_data):
        DLOG.verbose("Volume-API update called for volume %s." % volume_uuid)

        if not validate.valid_uuid_str(volume_uuid):
            DLOG.error("Invalid uuid received, uuid=%s." % volume_uuid)
            return pecan.abort(httplib.BAD_REQUEST)

        volume_data = VolumeQueryData()
        http_response = self._get_volume_details(volume_uuid, volume_data)
        if httplib.OK != http_response:
            return pecan.abort(http_response)

        rpc_request = rpc.APIRequestUpdateVolume()
        rpc_request.uuid = volume_uuid
        if volume_update_data.description is None:
            rpc_request.description = volume_data.description
        else:
            rpc_request.description = volume_update_data.description

        vim_connection = pecan.request.vim.open_connection()
        vim_connection.send(rpc_request.serialize())
        msg = vim_connection.receive()
        if msg is None:
            DLOG.error("No response received for volume %s." % volume_uuid)
            return pecan.abort(httplib.INTERNAL_SERVER_ERROR)

        response = rpc.RPCMessage.deserialize(msg)
        if rpc.RPC_MSG_TYPE.UPDATE_VOLUME_RESPONSE != response.type:
            DLOG.error("Unexpected message type received, msg_type=%s." %
                       response.type)
            return pecan.abort(httplib.INTERNAL_SERVER_ERROR)

        if rpc.RPC_MSG_RESULT.SUCCESS == response.result:
            volume = VolumeQueryData()
            volume.uuid = response.uuid
            volume.name = response.name
            volume.description = response.description
            volume.disk_size = response.size_gb
            volume.bootable = response.bootable
            volume.encrypted = response.encrypted
            volume.availability_status = response.avail_status
            volume.action = response.action
            return volume

        DLOG.error("Unexpected result received for volume %s, result=%s." %
                   (volume_uuid, response.result))
        return pecan.abort(httplib.INTERNAL_SERVER_ERROR)
Beispiel #8
0
    def get_one(self, strategy_uuid):
        if not validate.valid_uuid_str(strategy_uuid):
            DLOG.error("Invalid strategy uuid received, uuid=%s." %
                       strategy_uuid)
            return pecan.abort(
                httplib.BAD_REQUEST,
                "Invalid strategy uuid, uuid=%s" % strategy_uuid)

        rpc_request = rpc.APIRequestGetSwUpdateStrategy()
        rpc_request.uuid = strategy_uuid
        vim_connection = pecan.request.vim.open_connection()
        vim_connection.send(rpc_request.serialize())
        msg = vim_connection.receive(timeout_in_secs=30)
        if msg is None:
            DLOG.error("No response received.")
            return pecan.abort(httplib.INTERNAL_SERVER_ERROR)

        response = rpc.RPCMessage.deserialize(msg)
        if rpc.RPC_MSG_TYPE.GET_SW_UPDATE_STRATEGY_RESPONSE != response.type:
            DLOG.error("Unexpected message type received, msg_type=%s." %
                       response.type)
            return pecan.abort(httplib.INTERNAL_SERVER_ERROR)

        if rpc.RPC_MSG_RESULT.SUCCESS == response.result:
            strategy = json.loads(response.strategy)
            query_data = SwUpdateStrategyQueryData()
            query_data.convert_strategy(strategy)
            return query_data

        elif rpc.RPC_MSG_RESULT.NOT_FOUND == response.result:
            DLOG.debug("No strategy exists matching strategy uuid %s" %
                       strategy_uuid)
            return pecan.abort(httplib.NOT_FOUND)

        DLOG.error("Unexpected result received, result=%s." % response.result)
        return pecan.abort(httplib.INTERNAL_SERVER_ERROR)
Beispiel #9
0
    def put(self, image_uuid, image_update_data):
        DLOG.verbose("Image-API update called for image %s." % image_uuid)

        if not validate.valid_uuid_str(image_uuid):
            DLOG.error("Invalid uuid received, uuid=%s." % image_uuid)
            return pecan.abort(httplib.BAD_REQUEST)

        image_data = ImageQueryData()
        http_response = self._get_image_details(image_uuid, image_data)
        if httplib.OK != http_response:
            return pecan.abort(http_response)

        rpc_request = rpc.APIRequestUpdateImage()
        rpc_request.uuid = image_uuid
        if image_update_data.description is None:
            rpc_request.description = image_data.description
        else:
            rpc_request.description = image_update_data.description

        if image_update_data.minimum_disk_size is None:
            rpc_request.min_disk_size_gb = image_data.minimum_disk_size
        else:
            rpc_request.min_disk_size_gb = image_update_data.minimum_disk_size

        if image_update_data.minimum_memory_size is None:
            rpc_request.min_memory_size_mb = image_data.minimum_memory_size
        else:
            rpc_request.min_memory_size_mb \
                = image_update_data.minimum_memory_size

        if image_update_data.visibility is None:
            rpc_request.visibility = image_data.visibility
        else:
            rpc_request.visibility = image_update_data.visibility

        if image_update_data.protected is None:
            rpc_request.protected = image_data.protected
        else:
            rpc_request.protected = image_update_data.protected

        if image_update_data.properties is None:
            rpc_request.properties = json.loads(image_data.properties)
        else:
            try:
                rpc_request.properties \
                    = json.loads(image_update_data.properties)
            except ValueError:
                DLOG.error("Invalid properties received, properties=%s."
                           % image_update_data.properties)
                return pecan.abort(httplib.BAD_REQUEST)
        vim_connection = pecan.request.vim.open_connection()
        vim_connection.send(rpc_request.serialize())
        msg = vim_connection.receive()
        if msg is None:
            DLOG.error("No response received for image %s." % image_uuid)
            return pecan.abort(httplib.INTERNAL_SERVER_ERROR)

        response = rpc.RPCMessage.deserialize(msg)
        if rpc.RPC_MSG_TYPE.UPDATE_IMAGE_RESPONSE != response.type:
            DLOG.error("Unexpected message type received, msg_type=%s."
                       % response.type)
            return pecan.abort(httplib.INTERNAL_SERVER_ERROR)

        if rpc.RPC_MSG_RESULT.SUCCESS == response.result:
            image = ImageQueryData()
            image.uuid = response.uuid
            image.name = response.name
            image.description = response.description
            image.container_format = response.container_format
            image.disk_format = response.disk_format
            image.minimum_disk_size = response.min_disk_size_gb
            image.minimum_memory_size = response.min_memory_size_mb
            image.visibility = response.visibility
            image.protected = response.protected
            image.availability_status = response.avail_status
            image.action = response.action
            image.properties = response.properties
            return image

        DLOG.error("Unexpected result received for image %s, result=%s."
                   % (image_uuid, response.result))
        return pecan.abort(httplib.INTERNAL_SERVER_ERROR)