Allow baymodel name when bay is created

Bay needs baymodel id when bay is created. But usually, user want to use
`baymodel name` instead of baymodel id.
This patch supports baymodel name when bay is created.

Eg. magnum bay-create --name bay1 --baymodel-id baymodel-name

Partially implements blueprint name-based-resource-management

Change-Id: I8c042c461d46a251c1cd6772979d77a95b902de5
This commit is contained in:
OTSUKA, Yuanying 2015-03-20 13:48:49 +09:00
parent 50f4f85f2f
commit 61ce7f876e
2 changed files with 8 additions and 2 deletions

View File

@ -52,7 +52,7 @@ class Bay(base.APIBase):
def _set_baymodel_id(self, value):
if value and self._baymodel_id != value:
try:
baymodel = objects.BayModel.get(pecan.request.context, value)
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

View File

@ -319,7 +319,7 @@ class TestPost(api_base.FunctionalTest):
def setUp(self):
super(TestPost, self).setUp()
obj_utils.create_test_baymodel(self.context)
self.baymodel = obj_utils.create_test_baymodel(self.context)
p = mock.patch.object(rpcapi.API, 'bay_create')
self.mock_bay_create = p.start()
self.mock_bay_create.side_effect = self._simulate_rpc_bay_create
@ -383,6 +383,12 @@ class TestPost(api_base.FunctionalTest):
self.assertEqual(400, response.status_int)
self.assertTrue(response.json['error_message'])
def test_create_bay_with_baymodel_name(self):
bdict = apiutils.bay_post_data(baymodel_id=self.baymodel.name)
response = self.post_json('/bays', bdict, expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(201, response.status_int)
def test_create_bay_with_node_count_zero(self):
bdict = apiutils.bay_post_data()
bdict['node_count'] = 0