diff --git a/doc/api_samples/os-baremetal-nodes/baremetal-node-create-req.json b/doc/api_samples/os-baremetal-nodes/baremetal-node-create-req.json index fa6455c4903f..389517ed74a9 100644 --- a/doc/api_samples/os-baremetal-nodes/baremetal-node-create-req.json +++ b/doc/api_samples/os-baremetal-nodes/baremetal-node-create-req.json @@ -7,7 +7,6 @@ "pm_address": "10.1.2.3", "pm_user": "pm_user", "pm_password": "pm_pass", - "prov_mac_address": "12:34:56:78:90:ab", "terminal_port": 8000 } -} \ No newline at end of file +} diff --git a/doc/api_samples/os-baremetal-nodes/baremetal-node-create-req.xml b/doc/api_samples/os-baremetal-nodes/baremetal-node-create-req.xml index 3cbc3ea8a1c3..a06b8d73fed2 100644 --- a/doc/api_samples/os-baremetal-nodes/baremetal-node-create-req.xml +++ b/doc/api_samples/os-baremetal-nodes/baremetal-node-create-req.xml @@ -6,6 +6,5 @@ local_gb="128" pm_address="10.1.2.3" pm_user="pm_user" - prov_mac_address="12:34:56:78:90:ab" terminal_port="8000" -/> \ No newline at end of file +/> diff --git a/doc/api_samples/os-baremetal-nodes/baremetal-node-create-resp.json b/doc/api_samples/os-baremetal-nodes/baremetal-node-create-resp.json index 0f176482cfe2..fdb206560078 100644 --- a/doc/api_samples/os-baremetal-nodes/baremetal-node-create-resp.json +++ b/doc/api_samples/os-baremetal-nodes/baremetal-node-create-resp.json @@ -8,7 +8,6 @@ "memory_mb": 8192, "pm_address": "10.1.2.3", "pm_user": "pm_user", - "prov_mac_address": "12:34:56:78:90:ab", "service_host": "host", "terminal_port": 8000 } diff --git a/doc/api_samples/os-baremetal-nodes/baremetal-node-create-resp.xml b/doc/api_samples/os-baremetal-nodes/baremetal-node-create-resp.xml index 20fb43b640d3..6a0b3a2666d5 100644 --- a/doc/api_samples/os-baremetal-nodes/baremetal-node-create-resp.xml +++ b/doc/api_samples/os-baremetal-nodes/baremetal-node-create-resp.xml @@ -4,7 +4,6 @@ pm_address="10.1.2.3" cpus="8" memory_mb="8192" - prov_mac_address="12:34:56:78:90:ab" service_host="host" local_gb="128" id="1" diff --git a/doc/api_samples/os-baremetal-nodes/baremetal-node-create-with-address-req.json b/doc/api_samples/os-baremetal-nodes/baremetal-node-create-with-address-req.json new file mode 100644 index 000000000000..82b6485b9b9e --- /dev/null +++ b/doc/api_samples/os-baremetal-nodes/baremetal-node-create-with-address-req.json @@ -0,0 +1,13 @@ +{ + "node": { + "service_host": "host", + "cpus": 8, + "memory_mb": 8192, + "local_gb": 128, + "pm_address": "10.1.2.3", + "pm_user": "pm_user", + "pm_password": "pm_pass", + "prov_mac_address": "12:34:56:78:90:ab", + "terminal_port": 8000 + } +} diff --git a/doc/api_samples/os-baremetal-nodes/baremetal-node-create-with-address-req.xml b/doc/api_samples/os-baremetal-nodes/baremetal-node-create-with-address-req.xml new file mode 100644 index 000000000000..8065c41c1deb --- /dev/null +++ b/doc/api_samples/os-baremetal-nodes/baremetal-node-create-with-address-req.xml @@ -0,0 +1,11 @@ + + diff --git a/doc/api_samples/os-baremetal-nodes/baremetal-node-create-with-address-resp.json b/doc/api_samples/os-baremetal-nodes/baremetal-node-create-with-address-resp.json new file mode 100644 index 000000000000..90ff4e3710d7 --- /dev/null +++ b/doc/api_samples/os-baremetal-nodes/baremetal-node-create-with-address-resp.json @@ -0,0 +1,21 @@ +{ + "node": { + "cpus": 8, + "id": 1, + "instance_uuid": null, + "interfaces": [ + { + "address": "12:34:56:78:90:ab", + "datapath_id": null, + "id": 1, + "port_no": null + } + ], + "local_gb": 128, + "memory_mb": 8192, + "pm_address": "10.1.2.3", + "pm_user": "pm_user", + "service_host": "host", + "terminal_port": 8000 + } +} diff --git a/doc/api_samples/os-baremetal-nodes/baremetal-node-create-with-address-resp.xml b/doc/api_samples/os-baremetal-nodes/baremetal-node-create-with-address-resp.xml new file mode 100644 index 000000000000..1432629ede83 --- /dev/null +++ b/doc/api_samples/os-baremetal-nodes/baremetal-node-create-with-address-resp.xml @@ -0,0 +1,19 @@ + + + + + + diff --git a/doc/api_samples/os-baremetal-nodes/baremetal-node-list-resp.json b/doc/api_samples/os-baremetal-nodes/baremetal-node-list-resp.json index d85f7c6f7ed4..1b8d5a8cec9b 100644 --- a/doc/api_samples/os-baremetal-nodes/baremetal-node-list-resp.json +++ b/doc/api_samples/os-baremetal-nodes/baremetal-node-list-resp.json @@ -16,7 +16,6 @@ "memory_mb": 8192, "pm_address": "10.1.2.3", "pm_user": "pm_user", - "prov_mac_address": "12:34:56:78:90:ab", "service_host": "host", "terminal_port": 8000 } diff --git a/doc/api_samples/os-baremetal-nodes/baremetal-node-list-resp.xml b/doc/api_samples/os-baremetal-nodes/baremetal-node-list-resp.xml index feb3d6f1dfd1..2afc47f67e8e 100644 --- a/doc/api_samples/os-baremetal-nodes/baremetal-node-list-resp.xml +++ b/doc/api_samples/os-baremetal-nodes/baremetal-node-list-resp.xml @@ -5,7 +5,6 @@ pm_address="10.1.2.3" cpus="8" memory_mb="8192" - prov_mac_address="12:34:56:78:90:ab" service_host="host" local_gb="128" id="1" diff --git a/doc/api_samples/os-baremetal-nodes/baremetal-node-show-resp.json b/doc/api_samples/os-baremetal-nodes/baremetal-node-show-resp.json index c407c20a2774..a8ba25ef9fe8 100644 --- a/doc/api_samples/os-baremetal-nodes/baremetal-node-show-resp.json +++ b/doc/api_samples/os-baremetal-nodes/baremetal-node-show-resp.json @@ -15,7 +15,6 @@ "memory_mb": 8192, "pm_address": "10.1.2.3", "pm_user": "pm_user", - "prov_mac_address": "12:34:56:78:90:ab", "service_host": "host", "terminal_port": 8000 } diff --git a/doc/api_samples/os-baremetal-nodes/baremetal-node-show-resp.xml b/doc/api_samples/os-baremetal-nodes/baremetal-node-show-resp.xml index 12d881a3f49a..438ee5921ab0 100644 --- a/doc/api_samples/os-baremetal-nodes/baremetal-node-show-resp.xml +++ b/doc/api_samples/os-baremetal-nodes/baremetal-node-show-resp.xml @@ -4,7 +4,6 @@ pm_address="10.1.2.3" cpus="8" memory_mb="8192" - prov_mac_address="12:34:56:78:90:ab" service_host="host" local_gb="128" id="1" diff --git a/nova/api/openstack/compute/contrib/baremetal_nodes.py b/nova/api/openstack/compute/contrib/baremetal_nodes.py index b3f226039b27..f69db50f00af 100644 --- a/nova/api/openstack/compute/contrib/baremetal_nodes.py +++ b/nova/api/openstack/compute/contrib/baremetal_nodes.py @@ -26,7 +26,7 @@ from nova.virt.baremetal import db authorize = extensions.extension_authorizer('compute', 'baremetal_nodes') node_fields = ['id', 'cpus', 'local_gb', 'memory_mb', 'pm_address', - 'pm_user', 'prov_mac_address', + 'pm_user', 'service_host', 'terminal_port', 'instance_uuid', ] @@ -129,9 +129,21 @@ class BareMetalNodeController(wsgi.Controller): def create(self, req, body): context = req.environ['nova.context'] authorize(context) - node = db.bm_node_create(context, body['node']) + values = body['node'].copy() + prov_mac_address = values.pop('prov_mac_address', None) + node = db.bm_node_create(context, values) node = _node_dict(node) - node['interfaces'] = [] + if prov_mac_address: + if_id = db.bm_interface_create(context, + bm_node_id=node['id'], + address=prov_mac_address, + datapath_id=None, + port_no=None) + if_ref = db.bm_interface_get(context, if_id) + node['interfaces'] = [_interface_dict(if_ref)] + else: + node['interfaces'] = [] + print node return {'node': node} def delete(self, req, id): diff --git a/nova/tests/api/openstack/compute/contrib/test_baremetal_nodes.py b/nova/tests/api/openstack/compute/contrib/test_baremetal_nodes.py index 76ebd8dec735..23d06cad20d5 100644 --- a/nova/tests/api/openstack/compute/contrib/test_baremetal_nodes.py +++ b/nova/tests/api/openstack/compute/contrib/test_baremetal_nodes.py @@ -46,7 +46,6 @@ class BareMetalNodesTest(test.TestCase): 'pm_address': "10.1.2.3", 'pm_user': "pm_user", 'pm_password': "pm_pass", - 'prov_mac_address': "12:34:56:78:90:ab", 'terminal_port': 8000, 'interfaces': [], } diff --git a/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-create-req.json.tpl b/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-create-req.json.tpl index 82b6485b9b9e..389517ed74a9 100644 --- a/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-create-req.json.tpl +++ b/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-create-req.json.tpl @@ -7,7 +7,6 @@ "pm_address": "10.1.2.3", "pm_user": "pm_user", "pm_password": "pm_pass", - "prov_mac_address": "12:34:56:78:90:ab", "terminal_port": 8000 } } diff --git a/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-create-req.xml.tpl b/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-create-req.xml.tpl index 8065c41c1deb..a06b8d73fed2 100644 --- a/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-create-req.xml.tpl +++ b/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-create-req.xml.tpl @@ -6,6 +6,5 @@ local_gb="128" pm_address="10.1.2.3" pm_user="pm_user" - prov_mac_address="12:34:56:78:90:ab" terminal_port="8000" /> diff --git a/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-create-resp.json.tpl b/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-create-resp.json.tpl index a0d976b99940..855b67150216 100644 --- a/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-create-resp.json.tpl +++ b/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-create-resp.json.tpl @@ -6,7 +6,6 @@ "local_gb": 128, "pm_address": "10.1.2.3", "pm_user": "pm_user", - "prov_mac_address": "12:34:56:78:90:ab", "terminal_port": 8000, "instance_uuid": null, "id": %(node_id)s, diff --git a/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-create-resp.xml.tpl b/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-create-resp.xml.tpl index 1c3700841810..15d0640c9e81 100644 --- a/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-create-resp.xml.tpl +++ b/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-create-resp.xml.tpl @@ -6,7 +6,6 @@ local_gb="128" pm_address="10.1.2.3" pm_user="pm_user" - prov_mac_address="12:34:56:78:90:ab" terminal_port="8000" instance_uuid="None" id="%(node_id)s"> diff --git a/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-create-with-address-req.json.tpl b/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-create-with-address-req.json.tpl new file mode 100644 index 000000000000..458aa128223f --- /dev/null +++ b/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-create-with-address-req.json.tpl @@ -0,0 +1,13 @@ +{ + "node": { + "service_host": "host", + "cpus": 8, + "memory_mb": 8192, + "local_gb": 128, + "pm_address": "10.1.2.3", + "pm_user": "pm_user", + "pm_password": "pm_pass", + "prov_mac_address": "%(address)s", + "terminal_port": 8000 + } +} diff --git a/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-create-with-address-req.xml.tpl b/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-create-with-address-req.xml.tpl new file mode 100644 index 000000000000..2c7273709eb6 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-create-with-address-req.xml.tpl @@ -0,0 +1,11 @@ + + diff --git a/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-create-with-address-resp.json.tpl b/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-create-with-address-resp.json.tpl new file mode 100644 index 000000000000..dae8d4373e14 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-create-with-address-resp.json.tpl @@ -0,0 +1,19 @@ +{ + "node": { + "service_host": "host", + "cpus": 8, + "memory_mb": 8192, + "local_gb": 128, + "pm_address": "10.1.2.3", + "pm_user": "pm_user", + "terminal_port": 8000, + "instance_uuid": null, + "id": %(node_id)s, + "interfaces": [{ + "id": %(interface_id)s, + "address": "%(address)s", + "datapath_id": null, + "port_no": null + }] + } +} diff --git a/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-create-with-address-resp.xml.tpl b/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-create-with-address-resp.xml.tpl new file mode 100644 index 000000000000..b036a1d47237 --- /dev/null +++ b/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-create-with-address-resp.xml.tpl @@ -0,0 +1,19 @@ + + + + + + diff --git a/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-list-resp.json.tpl b/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-list-resp.json.tpl index 4a5e0370174a..a38bdf6d7f93 100644 --- a/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-list-resp.json.tpl +++ b/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-list-resp.json.tpl @@ -6,7 +6,6 @@ "local_gb": 128, "pm_address": "10.1.2.3", "pm_user": "pm_user", - "prov_mac_address": "12:34:56:78:90:ab", "terminal_port": 8000, "instance_uuid": null, "id": %(node_id)s, diff --git a/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-list-resp.xml.tpl b/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-list-resp.xml.tpl index f8cfc3885b58..5bb51d4be3ec 100644 --- a/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-list-resp.xml.tpl +++ b/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-list-resp.xml.tpl @@ -7,7 +7,6 @@ local_gb="128" pm_address="10.1.2.3" pm_user="pm_user" - prov_mac_address="12:34:56:78:90:ab" terminal_port="8000" instance_uuid="None" id="%(node_id)s"> diff --git a/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-show-resp.json.tpl b/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-show-resp.json.tpl index 67a878a4a12a..dae8d4373e14 100644 --- a/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-show-resp.json.tpl +++ b/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-show-resp.json.tpl @@ -6,7 +6,6 @@ "local_gb": 128, "pm_address": "10.1.2.3", "pm_user": "pm_user", - "prov_mac_address": "12:34:56:78:90:ab", "terminal_port": 8000, "instance_uuid": null, "id": %(node_id)s, diff --git a/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-show-resp.xml.tpl b/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-show-resp.xml.tpl index 6670241162a7..7fc10026e2a0 100644 --- a/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-show-resp.xml.tpl +++ b/nova/tests/integrated/api_samples/os-baremetal-nodes/baremetal-node-show-resp.xml.tpl @@ -6,7 +6,6 @@ local_gb="128" pm_address="10.1.2.3" pm_user="pm_user" - prov_mac_address="12:34:56:78:90:ab" terminal_port="8000" instance_uuid="None" id="%(node_id)s"> diff --git a/nova/tests/integrated/test_api_samples.py b/nova/tests/integrated/test_api_samples.py index c0c908e077c6..5a2327bc098f 100644 --- a/nova/tests/integrated/test_api_samples.py +++ b/nova/tests/integrated/test_api_samples.py @@ -2782,9 +2782,24 @@ class BareMetalNodesJsonTest(ApiSampleTestBase, bm_db_base.BMDBTestCase): return self._verify_response("baremetal-node-create-resp", subs, response, 200) + def _create_node_with_address(self): + address = '12:34:56:78:90:ab' + req_subs = {'address': address} + response = self._do_post("os-baremetal-nodes", + "baremetal-node-create-with-address-req", + req_subs) + subs = {'node_id': '(?P\d+)', + 'interface_id': '\d+', + 'address': address} + return self._verify_response("baremetal-node-create-with-address-resp", + subs, response, 200) + def test_create_node(self): self._create_node() + def test_create_node_with_address(self): + self._create_node_with_address() + def test_list_nodes(self): node_id = self._create_node() interface_id = self._add_interface(node_id)