Esempio n. 1
0
    def post(self, baymodel):
        """Create a new baymodel.

        :param baymodel: a baymodel within the request body.
        """
        baymodel_dict = baymodel.as_dict()
        context = pecan.request.context
        cli = clients.OpenStackClients(context)
        attr_validator.validate_keypair(cli, baymodel_dict['keypair_id'])
        image_data = attr_validator.validate_image(cli,
                                                   baymodel_dict['image_id'])
        baymodel_dict['cluster_distro'] = image_data['os_distro']
        baymodel_dict['project_id'] = context.project_id
        baymodel_dict['user_id'] = context.user_id
        # check permissions for making baymodel public
        if baymodel_dict['public']:
            if not policy.enforce(context, "baymodel:publish", None,
                                  do_raise=False):
                raise exception.BaymodelPublishDenied()

        new_baymodel = objects.BayModel(context, **baymodel_dict)
        new_baymodel.create()
        # Set the HTTP Location Header
        pecan.response.location = link.build_url('baymodels',
                                                 new_baymodel.uuid)
        return BayModel.convert_with_links(new_baymodel)
Esempio n. 2
0
    def post(self, baymodel):
        """Create a new baymodel.

        :param baymodel: a baymodel within the request body.
        """
        baymodel_dict = baymodel.as_dict()
        context = pecan.request.context
        cli = clients.OpenStackClients(context)
        attr_validator.validate_keypair(cli, baymodel_dict['keypair_id'])
        image_data = attr_validator.validate_image(cli,
                                                   baymodel_dict['image_id'])
        baymodel_dict['cluster_distro'] = image_data['os_distro']
        baymodel_dict['project_id'] = context.project_id
        baymodel_dict['user_id'] = context.user_id
        # check permissions for making baymodel public
        if baymodel_dict['public']:
            if not policy.enforce(context, "baymodel:publish", None,
                                  do_raise=False):
                raise exception.BaymodelPublishDenied()

        new_baymodel = objects.BayModel(context, **baymodel_dict)
        new_baymodel.create()
        # Set the HTTP Location Header
        pecan.response.location = link.build_url('baymodels',
                                                 new_baymodel.uuid)
        return BayModel.convert_with_links(new_baymodel)
Esempio n. 3
0
 def test_validate_keypair_with_valid_keypair(self):
     mock_keypair = mock.MagicMock()
     mock_keypair.id = 'test-keypair'
     mock_nova = mock.MagicMock()
     mock_nova.keypairs.get.return_value = mock_keypair
     mock_os_cli = mock.MagicMock()
     mock_os_cli.nova.return_value = mock_nova
     attr_validator.validate_keypair(mock_os_cli, 'test-keypair')
Esempio n. 4
0
 def test_validate_keypair_with_valid_keypair(self):
     mock_keypair = mock.MagicMock()
     mock_keypair.id = 'test-keypair'
     mock_nova = mock.MagicMock()
     mock_nova.keypairs.get.return_value = mock_keypair
     mock_os_cli = mock.MagicMock()
     mock_os_cli.nova.return_value = mock_nova
     attr_validator.validate_keypair(mock_os_cli, 'test-keypair')