Esempio n. 1
0
    def get_one(self, baymodel_ident):
        """Retrieve information about the given baymodel.

        :param baymodel_ident: UUID or logical name of a baymodel.
        """
        rpc_baymodel = api_utils.get_rpc_resource('BayModel', baymodel_ident)
        return BayModel.convert_with_links(rpc_baymodel)
Esempio n. 2
0
    def patch(self, container_ident, patch):
        """Update an existing container.

        :param container_ident: UUID or name of a container.
        :param patch: a json PATCH document to apply to this container.
        """
        rpc_container = api_utils.get_rpc_resource('Container',
                                                   container_ident)
        try:
            container_dict = rpc_container.as_dict()
            container = Container(**api_utils.apply_jsonpatch(
                container_dict, patch))
        except api_utils.JSONPATCH_EXCEPTIONS as e:
            raise exception.PatchError(patch=patch, reason=e)

        # Update only the fields that have changed
        for field in objects.Container.fields:
            try:
                patch_val = getattr(container, field)
            except AttributeError:
                # Ignore fields that aren't exposed in the API
                continue
            if patch_val == wtypes.Unset:
                patch_val = None
            if rpc_container[field] != patch_val:
                rpc_container[field] = patch_val

        rpc_container.save()
        return Container.convert_with_links(rpc_container)
Esempio n. 3
0
File: bay.py Progetto: yamt/magnum
    def patch(self, bay_ident, patch):
        """Update an existing bay.

        :param bay_ident: UUID or logical name of a bay.
        :param patch: a json PATCH document to apply to this bay.
        """
        rpc_bay = api_utils.get_rpc_resource('Bay', bay_ident)
        try:
            bay_dict = rpc_bay.as_dict()
            bay = Bay(**api_utils.apply_jsonpatch(bay_dict, patch))
        except api_utils.JSONPATCH_EXCEPTIONS as e:
            raise exception.PatchError(patch=patch, reason=e)

        # Update only the fields that have changed
        for field in objects.Bay.fields:
            try:
                patch_val = getattr(bay, field)
            except AttributeError:
                # Ignore fields that aren't exposed in the API
                continue
            if patch_val == wtypes.Unset:
                patch_val = None
            if rpc_bay[field] != patch_val:
                rpc_bay[field] = patch_val

        delta = rpc_bay.obj_what_changed()

        validate_bay_properties(delta)

        res_bay = pecan.request.rpcapi.bay_update(rpc_bay)
        return Bay.convert_with_links(res_bay)
Esempio n. 4
0
    def delete(self, baymodel_ident):
        """Delete a baymodel.

        :param baymodel_ident: UUID or logical name of a baymodel.
        """
        rpc_baymodel = api_utils.get_rpc_resource('BayModel', baymodel_ident)
        rpc_baymodel.destroy()
Esempio n. 5
0
File: bay.py Progetto: sidx64/magnum
    def patch(self, bay_ident, patch):
        """Update an existing bay.

        :param bay_ident: UUID or logical name of a bay.
        :param patch: a json PATCH document to apply to this bay.
        """
        rpc_bay = api_utils.get_rpc_resource('Bay', bay_ident)
        try:
            bay_dict = rpc_bay.as_dict()
            bay = Bay(**api_utils.apply_jsonpatch(bay_dict, patch))
        except api_utils.JSONPATCH_EXCEPTIONS as e:
            raise exception.PatchError(patch=patch, reason=e)

        # Update only the fields that have changed
        for field in objects.Bay.fields:
            try:
                patch_val = getattr(bay, field)
            except AttributeError:
                # Ignore fields that aren't exposed in the API
                continue
            if patch_val == wtypes.Unset:
                patch_val = None
            if rpc_bay[field] != patch_val:
                rpc_bay[field] = patch_val

        res_bay = pecan.request.rpcapi.bay_update(rpc_bay)
        return Bay.convert_with_links(res_bay)
Esempio n. 6
0
    def get_one(self, baymodel_ident):
        """Retrieve information about the given baymodel.

        :param baymodel_ident: UUID or logical name of a baymodel.
        """
        rpc_baymodel = api_utils.get_rpc_resource('BayModel', baymodel_ident)
        return BayModel.convert_with_links(rpc_baymodel)
Esempio n. 7
0
    def patch(self, container_ident, patch):
        """Update an existing container.

        :param container_ident: UUID or name of a container.
        :param patch: a json PATCH document to apply to this container.
        """
        rpc_container = api_utils.get_rpc_resource('Container',
                                                   container_ident)
        try:
            container_dict = rpc_container.as_dict()
            container = Container(
                **api_utils.apply_jsonpatch(container_dict, patch))
        except api_utils.JSONPATCH_EXCEPTIONS as e:
            raise exception.PatchError(patch=patch, reason=e)

        # Update only the fields that have changed
        for field in objects.Container.fields:
            try:
                patch_val = getattr(container, field)
            except AttributeError:
                # Ignore fields that aren't exposed in the API
                continue
            if patch_val == wtypes.Unset:
                patch_val = None
            if rpc_container[field] != patch_val:
                rpc_container[field] = patch_val

        rpc_container.save()
        return Container.convert_with_links(rpc_container)
Esempio n. 8
0
    def _default(self, container_ident):
        if pecan.request.method != "PUT":
            pecan.abort(405, ("HTTP method %s is not allowed" % pecan.request.method))
        container_uuid = api_utils.get_rpc_resource("Container", container_ident).uuid

        LOG.debug("Calling conductor.container_start with %s" % container_uuid)
        return pecan.request.rpcapi.container_start(container_uuid)
Esempio n. 9
0
    def delete(self, baymodel_ident):
        """Delete a baymodel.

        :param baymodel_ident: UUID or logical name of a baymodel.
        """
        rpc_baymodel = api_utils.get_rpc_resource('BayModel', baymodel_ident)
        rpc_baymodel.destroy()
Esempio n. 10
0
File: bay.py Progetto: sidx64/magnum
    def delete(self, bay_ident):
        """Delete a bay.

        :param bay_ident: UUID of a bay or logical name of the bay.
        """
        rpc_bay = api_utils.get_rpc_resource('Bay', bay_ident)

        pecan.request.rpcapi.bay_delete(rpc_bay.uuid)
Esempio n. 11
0
File: bay.py Progetto: sidx64/magnum
    def get_one(self, bay_ident):
        """Retrieve information about the given bay.

        :param bay_ident: UUID of a bay or logical name of the bay.
        """
        rpc_bay = api_utils.get_rpc_resource('Bay', bay_ident)

        return Bay.convert_with_links(rpc_bay)
Esempio n. 12
0
 def _default(self, container_ident):
     if pecan.request.method != 'GET':
         pecan.abort(
             405, ('HTTP method %s is not allowed' % pecan.request.method))
     container_uuid = api_utils.get_rpc_resource('Container',
                                                 container_ident).uuid
     LOG.debug('Calling conductor.container_logs with %s' % container_uuid)
     return pecan.request.rpcapi.container_logs(container_uuid)
Esempio n. 13
0
    def get_one(self, container_ident):
        """Retrieve information about the given container.

        :param container_ident: UUID or name of a container.
        """
        rpc_container = api_utils.get_rpc_resource("Container", container_ident)
        res_container = pecan.request.rpcapi.container_show(rpc_container.uuid)
        return Container.convert_with_links(res_container)
Esempio n. 14
0
File: bay.py Progetto: yamt/magnum
    def get_one(self, bay_ident):
        """Retrieve information about the given bay.

        :param bay_ident: UUID of a bay or logical name of the bay.
        """
        rpc_bay = api_utils.get_rpc_resource('Bay', bay_ident)

        return Bay.convert_with_links(rpc_bay)
Esempio n. 15
0
    def delete(self, container_ident):
        """Delete a container.

        :param container_ident: UUID or Name of a container.
        """
        rpc_container = api_utils.get_rpc_resource("Container", container_ident)
        pecan.request.rpcapi.container_delete(rpc_container.uuid)
        rpc_container.destroy()
Esempio n. 16
0
File: bay.py Progetto: yamt/magnum
    def delete(self, bay_ident):
        """Delete a bay.

        :param bay_ident: UUID of a bay or logical name of the bay.
        """
        rpc_bay = api_utils.get_rpc_resource('Bay', bay_ident)

        pecan.request.rpcapi.bay_delete(rpc_bay.uuid)
Esempio n. 17
0
    def get_one(self, bay_ident):
        """Retrieve information about the given certificate.

        :param bay_ident: UUID of a bay or
        logical name of the bay.
        """
        rpc_bay = api_utils.get_rpc_resource('Bay', bay_ident)
        certificate = pecan.request.rpcapi.get_ca_certificate(rpc_bay)
        return Certificate.convert_with_links(certificate)
Esempio n. 18
0
 def _default(self, container_ident, command):
     if pecan.request.method != 'PUT':
         pecan.abort(405, ('HTTP method %s is not allowed'
                           % pecan.request.method))
     container_uuid = api_utils.get_rpc_resource('Container',
                                                 container_ident).uuid
     LOG.debug('Calling conductor.container_exec with %s command %s'
               % (container_uuid, command))
     return pecan.request.rpcapi.container_exec(container_uuid, command)
Esempio n. 19
0
    def delete(self, container_ident):
        """Delete a container.

        :param container_ident: UUID or Name of a container.
        """
        rpc_container = api_utils.get_rpc_resource('Container',
                                                   container_ident)
        pecan.request.rpcapi.container_delete(rpc_container.uuid)
        rpc_container.destroy()
Esempio n. 20
0
    def get_one(self, bay_ident):
        """Retrieve information about the given certificate.

        :param bay_ident: UUID of a bay or
        logical name of the bay.
        """
        rpc_bay = api_utils.get_rpc_resource('Bay', bay_ident)
        certificate = pecan.request.rpcapi.get_ca_certificate(rpc_bay)
        return Certificate.convert_with_links(certificate)
Esempio n. 21
0
    def get_one(self, container_ident):
        """Retrieve information about the given container.

        :param container_ident: UUID or name of a container.
        """
        rpc_container = api_utils.get_rpc_resource('Container',
                                                   container_ident)
        res_container = pecan.request.rpcapi.container_show(rpc_container.uuid)
        return Container.convert_with_links(res_container)
Esempio n. 22
0
    def delete(self, x509keypair_ident):
        """Delete a x509keypair.

        :param x509keypair_ident: UUID of a x509keypair or logical
        name of the x509keypair.
        """
        rpc_x509keypair = api_utils.get_rpc_resource('X509KeyPair',
                                                     x509keypair_ident)

        pecan.request.rpcapi.x509keypair_delete(rpc_x509keypair.uuid)
Esempio n. 23
0
    def get_one(self, x509keypair_ident):
        """Retrieve information about the given x509keypair.

        :param x509keypair_ident: UUID of a x509keypair or
        logical name of the x509keypair.
        """
        rpc_x509keypair = api_utils.get_rpc_resource('X509KeyPair',
                                                     x509keypair_ident)

        return X509KeyPair.convert_with_links(rpc_x509keypair)
Esempio n. 24
0
    def delete(self, x509keypair_ident):
        """Delete a x509keypair.

        :param x509keypair_ident: UUID of a x509keypair or logical
        name of the x509keypair.
        """
        rpc_x509keypair = api_utils.get_rpc_resource('X509KeyPair',
                                                     x509keypair_ident)

        pecan.request.rpcapi.x509keypair_delete(rpc_x509keypair.uuid)
Esempio n. 25
0
    def get_one(self, x509keypair_ident):
        """Retrieve information about the given x509keypair.

        :param x509keypair_ident: UUID of a x509keypair or
        logical name of the x509keypair.
        """
        rpc_x509keypair = api_utils.get_rpc_resource('X509KeyPair',
                                                     x509keypair_ident)

        return X509KeyPair.convert_with_links(rpc_x509keypair)
Esempio n. 26
0
    def test_get_rpc_resource_with_name(self, mock_get_by_uuid,
                                        mock_get_by_name, mock_request):
        mock_bay = mock.MagicMock
        mock_get_by_name.return_value = mock_bay

        returned_bay = utils.get_rpc_resource('Bay', 'fake-name')

        self.assertFalse(mock_get_by_uuid.called)
        mock_get_by_name.assert_called_once_with(mock_request.context,
                                                 'fake-name')
        self.assertEqual(mock_bay, returned_bay)
Esempio n. 27
0
    def test_get_rpc_resource_with_uuid(self, mock_get_by_uuid,
                                        mock_get_by_name, mock_request):
        mock_bay = mock.MagicMock
        mock_get_by_uuid.return_value = mock_bay
        uuid = common_utils.generate_uuid()

        returned_bay = utils.get_rpc_resource('Bay', uuid)

        mock_get_by_uuid.assert_called_once_with(mock_request.context, uuid)
        self.assertFalse(mock_get_by_name.called)
        self.assertEqual(mock_bay, returned_bay)
Esempio n. 28
0
 def wrapper(func, *args, **kwargs):
     baymodel_ident = args[1]
     patch = args[2]
     baymodel = api_utils.get_rpc_resource('BayModel', baymodel_ident)
     try:
         baymodel_dict = api_utils.apply_jsonpatch(baymodel.as_dict(),
                                                   patch)
     except api_utils.JSONPATCH_EXCEPTIONS as e:
         raise exception.PatchError(patch=patch, reason=e)
     _enforce_volume_driver_types(baymodel_dict)
     return func(*args, **kwargs)
Esempio n. 29
0
 def wrapper(func, *args, **kwargs):
     baymodel_ident = args[1]
     patch = args[2]
     baymodel = api_utils.get_rpc_resource('BayModel', baymodel_ident)
     try:
         baymodel_dict = api_utils.apply_jsonpatch(baymodel.as_dict(),
                                                   patch)
     except api_utils.JSONPATCH_EXCEPTIONS as e:
         raise exception.PatchError(patch=patch, reason=e)
     baymodel = objects.BayModel(pecan.request.context, **baymodel_dict)
     _enforce_network_driver_types(baymodel)
     return func(*args, **kwargs)
Esempio n. 30
0
 def _set_bay_uuid(self, value):
     if value and self._bay_uuid != value:
         try:
             bay = api_utils.get_rpc_resource('Bay', value)
             self._bay_uuid = bay.uuid
         except exception.BayNotFound as e:
             # Change error code because 404 (NotFound) is inappropriate
             # response for a POST request to create a Bay
             e.code = 400  # BadRequest
             raise e
     elif value == wtypes.Unset:
         self._bay_uuid = wtypes.Unset
Esempio n. 31
0
 def wrapper(func, *args, **kwargs):
     baymodel_ident = args[1]
     patch = args[2]
     baymodel = api_utils.get_rpc_resource('BayModel', baymodel_ident)
     try:
         baymodel_dict = api_utils.apply_jsonpatch(baymodel.as_dict(),
                                                   patch)
     except api_utils.JSONPATCH_EXCEPTIONS as e:
         raise exception.PatchError(patch=patch, reason=e)
     baymodel = objects.BayModel(pecan.request.context, **baymodel_dict)
     _enforce_network_driver_types(baymodel)
     return func(*args, **kwargs)
Esempio n. 32
0
File: bay.py Progetto: yamt/magnum
 def _set_baymodel_id(self, value):
     if value and self._baymodel_id != value:
         try:
             baymodel = api_utils.get_rpc_resource('BayModel', value)
             self._baymodel_id = baymodel.uuid
         except exception.BayModelNotFound as e:
             # Change error code because 404 (NotFound) is inappropriate
             # response for a POST request to create a Bay
             e.code = 400  # BadRequest
             raise e
     elif value == wtypes.Unset:
         self._baymodel_id = wtypes.Unset
Esempio n. 33
0
    def test_get_rpc_resource_with_name(
            self,
            mock_get_by_uuid,
            mock_get_by_name,
            mock_request):
        mock_bay = mock.MagicMock
        mock_get_by_name.return_value = mock_bay

        returned_bay = utils.get_rpc_resource('Bay', 'fake-name')

        self.assertFalse(mock_get_by_uuid.called)
        mock_get_by_name.assert_called_once_with(mock_request.context,
                                                 'fake-name')
        self.assertEqual(mock_bay, returned_bay)
Esempio n. 34
0
    def test_get_rpc_resource_with_uuid(
            self,
            mock_get_by_uuid,
            mock_get_by_name,
            mock_request):
        mock_bay = mock.MagicMock
        mock_get_by_uuid.return_value = mock_bay
        uuid = common_utils.generate_uuid()

        returned_bay = utils.get_rpc_resource('Bay', uuid)

        mock_get_by_uuid.assert_called_once_with(mock_request.context, uuid)
        self.assertFalse(mock_get_by_name.called)
        self.assertEqual(mock_bay, returned_bay)
Esempio n. 35
0
    def patch(self, baymodel_ident, patch):
        """Update an existing baymodel.

        :param baymodel_ident: UUID or logic name of a baymodel.
        :param patch: a json PATCH document to apply to this baymodel.
        """
        context = pecan.request.context
        rpc_baymodel = api_utils.get_rpc_resource('BayModel', baymodel_ident)
        try:
            baymodel_dict = rpc_baymodel.as_dict()
            baymodel = BayModel(**api_utils.apply_jsonpatch(
                baymodel_dict,
                patch))
        except api_utils.JSONPATCH_EXCEPTIONS as e:
            raise exception.PatchError(patch=patch, reason=e)

        # check permissions when updating baymodel public flag
        if rpc_baymodel.public != baymodel.public:
            if not policy.enforce(context, "baymodel:publish", None,
                                  do_raise=False):
                raise exception.BaymodelPublishDenied()

        # Update only the fields that have changed
        for field in objects.BayModel.fields:
            try:
                patch_val = getattr(baymodel, field)
            except AttributeError:
                # Ignore fields that aren't exposed in the API
                continue
            if patch_val == wtypes.Unset:
                patch_val = None
            if rpc_baymodel[field] != patch_val:
                rpc_baymodel[field] = patch_val

        rpc_baymodel.save()
        return BayModel.convert_with_links(rpc_baymodel)
Esempio n. 36
0
    def patch(self, baymodel_ident, patch):
        """Update an existing baymodel.

        :param baymodel_ident: UUID or logic name of a baymodel.
        :param patch: a json PATCH document to apply to this baymodel.
        """
        context = pecan.request.context
        rpc_baymodel = api_utils.get_rpc_resource('BayModel', baymodel_ident)
        try:
            baymodel_dict = rpc_baymodel.as_dict()
            baymodel = BayModel(**api_utils.apply_jsonpatch(
                baymodel_dict,
                patch))
        except api_utils.JSONPATCH_EXCEPTIONS as e:
            raise exception.PatchError(patch=patch, reason=e)

        # check permissions when updating baymodel public flag
        if rpc_baymodel.public != baymodel.public:
            if not policy.enforce(context, "baymodel:publish", None,
                                  do_raise=False):
                raise exception.BaymodelPublishDenied()

        # Update only the fields that have changed
        for field in objects.BayModel.fields:
            try:
                patch_val = getattr(baymodel, field)
            except AttributeError:
                # Ignore fields that aren't exposed in the API
                continue
            if patch_val == wtypes.Unset:
                patch_val = None
            if rpc_baymodel[field] != patch_val:
                rpc_baymodel[field] = patch_val

        rpc_baymodel.save()
        return BayModel.convert_with_links(rpc_baymodel)
Esempio n. 37
0
 def get_bay(self):
     if not self._bay:
         self._bay = api_utils.get_rpc_resource('Bay', self.bay_uuid)
     return self._bay
Esempio n. 38
0
 def get_bay(self):
     if not self._bay:
         self._bay = api_utils.get_rpc_resource('Bay', self.bay_uuid)
     return self._bay
Esempio n. 39
0
 def wrapper(func, *args, **kwargs):
     baymodel_ident = args[1]
     baymodel = api_utils.get_rpc_resource('BayModel', baymodel_ident)
     _enforce_network_driver_types(baymodel)
     return func(*args, **kwargs)
Esempio n. 40
0
 def wrapper(func, *args, **kwargs):
     baymodel_ident = args[1]
     baymodel = api_utils.get_rpc_resource('BayModel', baymodel_ident)
     _enforce_network_driver_types(baymodel)
     return func(*args, **kwargs)