def test_index(self):
     nodes = [
         {
             'id': 1
         },
         {
             'id': 2
         },
     ]
     interfaces = [
         {
             'id': 1,
             'address': '11:11:11:11:11:11'
         },
         {
             'id': 2,
             'address': '22:22:22:22:22:22'
         },
     ]
     self.mox.StubOutWithMock(db, 'bm_node_get_all')
     self.mox.StubOutWithMock(db, 'bm_interface_get_all_by_bm_node_id')
     db.bm_node_get_all(self.context).AndReturn(nodes)
     db.bm_interface_get_all_by_bm_node_id(self.context, 1).\
             AndRaise(exception.NodeNotFound(node_id=1))
     db.bm_interface_get_all_by_bm_node_id(self.context, 2).\
             AndReturn(interfaces)
     self.mox.ReplayAll()
     res_dict = self.controller.index(self.request)
     self.assertEqual(2, len(res_dict['nodes']))
     self.assertEqual([], res_dict['nodes'][0]['interfaces'])
     self.assertEqual(2, len(res_dict['nodes'][1]['interfaces']))
Ejemplo n.º 2
0
 def test_remove_interface_by_address(self):
     node_id = 1
     interfaces = [
         {
             'id': 1,
             'address': '11:11:11:11:11:11'
         },
         {
             'id': 2,
             'address': '22:22:22:22:22:22'
         },
         {
             'id': 3,
             'address': '33:33:33:33:33:33'
         },
     ]
     self.mox.StubOutWithMock(db, 'bm_node_get')
     self.mox.StubOutWithMock(db, 'bm_interface_get_all_by_bm_node_id')
     self.mox.StubOutWithMock(db, 'bm_interface_destroy')
     db.bm_node_get(self.context, node_id)
     db.bm_interface_get_all_by_bm_node_id(self.context, node_id).\
             AndReturn(interfaces)
     db.bm_interface_destroy(self.context, 2)
     self.mox.ReplayAll()
     body = {'remove_interface': {'address': '22:22:22:22:22:22'}}
     self.controller._remove_interface(self.request, node_id, body)
Ejemplo n.º 3
0
 def _test_index(self, ext_status=False):
     nodes = [
         {
             'id': 1
         },
         {
             'id': 2
         },
     ]
     interfaces = [
         {
             'id': 1,
             'address': '11:11:11:11:11:11'
         },
         {
             'id': 2,
             'address': '22:22:22:22:22:22'
         },
     ]
     self.mox.StubOutWithMock(db, 'bm_node_get_all')
     self.mox.StubOutWithMock(db, 'bm_interface_get_all_by_bm_node_id')
     db.bm_node_get_all(self.context).AndReturn(nodes)
     db.bm_interface_get_all_by_bm_node_id(self.context, 1).\
             AndRaise(exception.NodeNotFound(node_id=1))
     for n in nodes:
         self.ext_mgr.is_loaded('os-baremetal-ext-status').\
             AndReturn(ext_status)
     db.bm_interface_get_all_by_bm_node_id(self.context, 2).\
             AndReturn(interfaces)
     self.mox.ReplayAll()
     res_dict = self.controller.index(self.request)
     self.assertEqual(2, len(res_dict['nodes']))
     self.assertEqual([], res_dict['nodes'][0]['interfaces'])
     self.assertEqual(2, len(res_dict['nodes'][1]['interfaces']))
Ejemplo n.º 4
0
 def test_show_no_interfaces(self):
     node_id = 1
     node = {"id": node_id}
     self.mox.StubOutWithMock(db, "bm_node_get")
     self.mox.StubOutWithMock(db, "bm_interface_get_all_by_bm_node_id")
     db.bm_node_get(self.context, node_id).AndReturn(node)
     db.bm_interface_get_all_by_bm_node_id(self.context, node_id).AndRaise(exception.NodeNotFound(node_id=node_id))
     self.mox.ReplayAll()
     res_dict = self.controller.show(self.request, node_id)
     self.assertEqual(node_id, res_dict["node"]["id"])
     self.assertEqual(0, len(res_dict["node"]["interfaces"]))
 def test_show_no_interfaces(self):
     node_id = 1
     node = {'id': node_id}
     self.mox.StubOutWithMock(db, 'bm_node_get')
     self.mox.StubOutWithMock(db, 'bm_interface_get_all_by_bm_node_id')
     db.bm_node_get(self.context, node_id).AndReturn(node)
     db.bm_interface_get_all_by_bm_node_id(self.context, node_id).\
             AndRaise(exception.NodeNotFound(node_id=node_id))
     self.mox.ReplayAll()
     res_dict = self.controller.show(self.request, node_id)
     self.assertEqual(node_id, res_dict['node']['id'])
     self.assertEqual(0, len(res_dict['node']['interfaces']))
Ejemplo n.º 6
0
 def test_remove_interface(self):
     node_id = 1
     interfaces = [{"id": 1}, {"id": 2}, {"id": 3}]
     body = {"remove_interface": {"id": 2}}
     self.mox.StubOutWithMock(db, "bm_node_get")
     self.mox.StubOutWithMock(db, "bm_interface_get_all_by_bm_node_id")
     self.mox.StubOutWithMock(db, "bm_interface_destroy")
     db.bm_node_get(self.context, node_id)
     db.bm_interface_get_all_by_bm_node_id(self.context, node_id).AndReturn(interfaces)
     db.bm_interface_destroy(self.context, 2)
     self.mox.ReplayAll()
     self.controller._remove_interface(self.request, node_id, body)
Ejemplo n.º 7
0
 def test_show_no_interfaces(self):
     node_id = 1
     node = {'id': node_id}
     self.mox.StubOutWithMock(db, 'bm_node_get')
     self.mox.StubOutWithMock(db, 'bm_interface_get_all_by_bm_node_id')
     db.bm_node_get(self.context, node_id).AndReturn(node)
     db.bm_interface_get_all_by_bm_node_id(self.context, node_id).\
             AndRaise(exception.NodeNotFound(node_id=node_id))
     self.mox.ReplayAll()
     res_dict = self.controller.show(self.request, node_id)
     self.assertEqual(node_id, res_dict['node']['id'])
     self.assertEqual(0, len(res_dict['node']['interfaces']))
Ejemplo n.º 8
0
 def test_show(self):
     node_id = 1
     node = {"id": node_id}
     interfaces = [{"id": 1, "address": "11:11:11:11:11:11"}, {"id": 2, "address": "22:22:22:22:22:22"}]
     self.mox.StubOutWithMock(db, "bm_node_get")
     self.mox.StubOutWithMock(db, "bm_interface_get_all_by_bm_node_id")
     db.bm_node_get(self.context, node_id).AndReturn(node)
     db.bm_interface_get_all_by_bm_node_id(self.context, node_id).AndReturn(interfaces)
     self.mox.ReplayAll()
     res_dict = self.controller.show(self.request, node_id)
     self.assertEqual(node_id, res_dict["node"]["id"])
     self.assertEqual(2, len(res_dict["node"]["interfaces"]))
Ejemplo n.º 9
0
 def test_index(self):
     nodes = [{"id": 1}, {"id": 2}]
     interfaces = [{"id": 1, "address": "11:11:11:11:11:11"}, {"id": 2, "address": "22:22:22:22:22:22"}]
     self.mox.StubOutWithMock(db, "bm_node_get_all")
     self.mox.StubOutWithMock(db, "bm_interface_get_all_by_bm_node_id")
     db.bm_node_get_all(self.context).AndReturn(nodes)
     db.bm_interface_get_all_by_bm_node_id(self.context, 1).AndRaise(exception.NodeNotFound(node_id=1))
     db.bm_interface_get_all_by_bm_node_id(self.context, 2).AndReturn(interfaces)
     self.mox.ReplayAll()
     res_dict = self.controller.index(self.request)
     self.assertEqual(2, len(res_dict["nodes"]))
     self.assertEqual([], res_dict["nodes"][0]["interfaces"])
     self.assertEqual(2, len(res_dict["nodes"][1]["interfaces"]))
Ejemplo n.º 10
0
 def _test_show_no_interfaces(self, ext_status=False):
     node_id = 1
     node = {'id': node_id}
     self.mox.StubOutWithMock(db, 'bm_node_get')
     self.mox.StubOutWithMock(db, 'bm_interface_get_all_by_bm_node_id')
     db.bm_node_get(self.context, node_id).AndReturn(node)
     db.bm_interface_get_all_by_bm_node_id(self.context, node_id).\
             AndRaise(exception.NodeNotFound(node_id=node_id))
     self.ext_mgr.is_loaded('os-baremetal-ext-status').AndReturn(ext_status)
     self.mox.ReplayAll()
     res_dict = self.controller.show(self.request, node_id)
     self.assertEqual(node_id, res_dict['node']['id'])
     self.assertEqual(0, len(res_dict['node']['interfaces']))
Ejemplo n.º 11
0
 def _test_show_no_interfaces(self, ext_status=False):
     node_id = 1
     node = {'id': node_id}
     self.mox.StubOutWithMock(db, 'bm_node_get')
     self.mox.StubOutWithMock(db, 'bm_interface_get_all_by_bm_node_id')
     db.bm_node_get(self.context, node_id).AndReturn(node)
     db.bm_interface_get_all_by_bm_node_id(self.context, node_id).\
             AndRaise(exception.NodeNotFound(node_id=node_id))
     self.ext_mgr.is_loaded('os-baremetal-ext-status').AndReturn(ext_status)
     self.mox.ReplayAll()
     res_dict = self.controller.show(self.request, node_id)
     self.assertEqual(node_id, res_dict['node']['id'])
     self.assertEqual(0, len(res_dict['node']['interfaces']))
Ejemplo n.º 12
0
 def test_show(self):
     node_id = 1
     node = {'id': node_id}
     interfaces = [{'id': 1, 'address': '11:11:11:11:11:11'},
                   {'id': 2, 'address': '22:22:22:22:22:22'},
                   ]
     self.mox.StubOutWithMock(db, 'bm_node_get')
     self.mox.StubOutWithMock(db, 'bm_interface_get_all_by_bm_node_id')
     db.bm_node_get(self.context, node_id).AndReturn(node)
     db.bm_interface_get_all_by_bm_node_id(self.context, node_id).\
             AndReturn(interfaces)
     self.mox.ReplayAll()
     res_dict = self.controller.show(self.request, node_id)
     self.assertEqual(node_id, res_dict['node']['id'])
     self.assertEqual(2, len(res_dict['node']['interfaces']))
Ejemplo n.º 13
0
 def test_show(self):
     node_id = 1
     node = {'id': node_id}
     interfaces = [{'id': 1, 'address': '11:11:11:11:11:11'},
                   {'id': 2, 'address': '22:22:22:22:22:22'},
                   ]
     self.mox.StubOutWithMock(db, 'bm_node_get')
     self.mox.StubOutWithMock(db, 'bm_interface_get_all_by_bm_node_id')
     db.bm_node_get(self.context, node_id).AndReturn(node)
     db.bm_interface_get_all_by_bm_node_id(self.context, node_id).\
             AndReturn(interfaces)
     self.mox.ReplayAll()
     res_dict = self.controller.show(self.request, node_id)
     self.assertEqual(node_id, res_dict['node']['id'])
     self.assertEqual(2, len(res_dict['node']['interfaces']))
Ejemplo n.º 14
0
 def _collect_mac_addresses(self, context, node):
     macs = set()
     macs.add(db.bm_node_get(context, node['id'])['prov_mac_address'])
     for nic in db.bm_interface_get_all_by_bm_node_id(context, node['id']):
         if nic['address']:
             macs.add(nic['address'])
     return sorted(macs)
Ejemplo n.º 15
0
 def show(self, req, id):
     context = req.environ['nova.context']
     authorize(context)
     if _use_ironic():
         # proxy command to Ironic
         icli = _get_ironic_client()
         inode = icli.node.get(id)
         iports = icli.node.list_ports(id)
         node = {
             'id': inode.uuid,
             'interfaces': [],
             'host': 'IRONIC MANAGED',
             'task_state': inode.provision_state,
             'cpus': inode.properties['cpus'],
             'memory_mb': inode.properties['memory_mb'],
             'disk_gb': inode.properties['local_gb'],
             'instance_uuid': inode.instance_uuid
         }
         for port in iports:
             node['interfaces'].append({'address': port.address})
     else:
         # use nova baremetal
         try:
             node = db.bm_node_get(context, id)
         except exception.NodeNotFound:
             raise webob.exc.HTTPNotFound()
         try:
             ifs = db.bm_interface_get_all_by_bm_node_id(context, id)
         except exception.NodeNotFound:
             ifs = []
         node = self._node_dict(node)
         node['interfaces'] = [_interface_dict(i) for i in ifs]
     return {'node': node}
Ejemplo n.º 16
0
 def test_remove_interface(self):
     node_id = 1
     interfaces = [{'id': 1},
                   {'id': 2},
                   {'id': 3},
                   ]
     body = {'remove_interface': {'id': 2}}
     self.mox.StubOutWithMock(db, 'bm_node_get')
     self.mox.StubOutWithMock(db, 'bm_interface_get_all_by_bm_node_id')
     self.mox.StubOutWithMock(db, 'bm_interface_destroy')
     db.bm_node_get(self.context, node_id)
     db.bm_interface_get_all_by_bm_node_id(self.context, node_id).\
             AndReturn(interfaces)
     db.bm_interface_destroy(self.context, 2)
     self.mox.ReplayAll()
     self.controller._remove_interface(self.request, node_id, body)
Ejemplo n.º 17
0
 def index(self, req):
     context = req.environ['nova.context']
     authorize(context)
     nodes = []
     if _use_ironic():
         # proxy command to Ironic
         icli = _get_ironic_client()
         ironic_nodes = icli.node.list(detail=True)
         for inode in ironic_nodes:
             node = {'id': inode.uuid,
                     'interfaces': [],
                     'host': 'IRONIC MANAGED',
                     'task_state': inode.provision_state,
                     'cpus': inode.properties.get('cpus', 0),
                     'memory_mb': inode.properties.get('memory_mb', 0),
                     'disk_gb': inode.properties.get('local_gb', 0)}
             nodes.append(node)
     else:
         # use nova baremetal
         nodes_from_db = db.bm_node_get_all(context)
         for node_from_db in nodes_from_db:
             try:
                 ifs = db.bm_interface_get_all_by_bm_node_id(
                         context, node_from_db['id'])
             except exception.NodeNotFound:
                 ifs = []
             node = self._node_dict(node_from_db)
             node['interfaces'] = [_interface_dict(i) for i in ifs]
             nodes.append(node)
     return {'nodes': nodes}
Ejemplo n.º 18
0
 def show(self, req, id):
     context = req.environ['nova.context']
     authorize(context)
     if _use_ironic():
         # proxy command to Ironic
         icli = _get_ironic_client()
         try:
             inode = icli.node.get(id)
         except ironic_exc.NotFound:
             msg = _("Node %s could not be found.") % id
             raise webob.exc.HTTPNotFound(explanation=msg)
         iports = icli.node.list_ports(id)
         node = {'id': inode.uuid,
                 'interfaces': [],
                 'host': 'IRONIC MANAGED',
                 'task_state': inode.provision_state,
                 'cpus': inode.properties.get('cpus', 0),
                 'memory_mb': inode.properties.get('memory_mb', 0),
                 'disk_gb': inode.properties.get('local_gb', 0),
                 'instance_uuid': inode.instance_uuid}
         for port in iports:
             node['interfaces'].append({'address': port.address})
     else:
         # use nova baremetal
         try:
             node = db.bm_node_get(context, id)
         except exception.NodeNotFound:
             raise webob.exc.HTTPNotFound()
         try:
             ifs = db.bm_interface_get_all_by_bm_node_id(context, id)
         except exception.NodeNotFound:
             ifs = []
         node = self._node_dict(node)
         node['interfaces'] = [_interface_dict(i) for i in ifs]
     return {'node': node}
Ejemplo n.º 19
0
 def test_remove_interface_by_address(self):
     node_id = 1
     interfaces = [{'id': 1, 'address': '11:11:11:11:11:11'},
                   {'id': 2, 'address': '22:22:22:22:22:22'},
                   {'id': 3, 'address': '33:33:33:33:33:33'},
                   ]
     self.mox.StubOutWithMock(db, 'bm_node_get')
     self.mox.StubOutWithMock(db, 'bm_interface_get_all_by_bm_node_id')
     self.mox.StubOutWithMock(db, 'bm_interface_destroy')
     db.bm_node_get(self.context, node_id)
     db.bm_interface_get_all_by_bm_node_id(self.context, node_id).\
             AndReturn(interfaces)
     db.bm_interface_destroy(self.context, 2)
     self.mox.ReplayAll()
     body = {'remove_interface': {'address': '22:22:22:22:22:22'}}
     self.controller._remove_interface(self.request, node_id, body)
Ejemplo n.º 20
0
 def test_remove_interface(self):
     node_id = 1
     interfaces = [{'id': 1},
                   {'id': 2},
                   {'id': 3},
                   ]
     body = {'remove_interface': {'id': 2}}
     self.mox.StubOutWithMock(db, 'bm_node_get')
     self.mox.StubOutWithMock(db, 'bm_interface_get_all_by_bm_node_id')
     self.mox.StubOutWithMock(db, 'bm_interface_destroy')
     db.bm_node_get(self.context, node_id)
     db.bm_interface_get_all_by_bm_node_id(self.context, node_id).\
             AndReturn(interfaces)
     db.bm_interface_destroy(self.context, 2)
     self.mox.ReplayAll()
     self.controller._remove_interface(self.request, node_id, body)
Ejemplo n.º 21
0
Archivo: pxe.py Proyecto: gtriolo/nova
 def _collect_mac_addresses(self, context, node):
     macs = set()
     macs.add(db.bm_node_get(context, node["id"])["prov_mac_address"])
     for nic in db.bm_interface_get_all_by_bm_node_id(context, node["id"]):
         if nic["address"]:
             macs.add(nic["address"])
     return sorted(macs)
Ejemplo n.º 22
0
 def test_remove_interface_by_address(self):
     node_id = 1
     interfaces = [
         {"id": 1, "address": "11:11:11:11:11:11"},
         {"id": 2, "address": "22:22:22:22:22:22"},
         {"id": 3, "address": "33:33:33:33:33:33"},
     ]
     self.mox.StubOutWithMock(db, "bm_node_get")
     self.mox.StubOutWithMock(db, "bm_interface_get_all_by_bm_node_id")
     self.mox.StubOutWithMock(db, "bm_interface_destroy")
     db.bm_node_get(self.context, node_id)
     db.bm_interface_get_all_by_bm_node_id(self.context, node_id).AndReturn(interfaces)
     db.bm_interface_destroy(self.context, 2)
     self.mox.ReplayAll()
     body = {"remove_interface": {"address": "22:22:22:22:22:22"}}
     self.controller._remove_interface(self.request, node_id, body)
Ejemplo n.º 23
0
    def plug(self, instance, vif):
        LOG.debug(_("plug: instance_uuid=%(uuid)s vif=%(vif)s")
                  % {'uuid': instance['uuid'], 'vif': vif})
        network, mapping = vif
        vif_uuid = mapping['vif_uuid']
        ctx = context.get_admin_context()
        node = bmdb.bm_node_get_by_instance_uuid(ctx, instance['uuid'])

        # TODO(deva): optimize this database query
        #             this is just searching for a free physical interface
        pifs = bmdb.bm_interface_get_all_by_bm_node_id(ctx, node['id'])
        for pif in pifs:
            if not pif['vif_uuid']:
                bmdb.bm_interface_set_vif_uuid(ctx, pif['id'], vif_uuid)
                LOG.debug(_("pif:%(id)s is plugged (vif_uuid=%(vif_uuid)s)")
                          % {'id': pif['id'], 'vif_uuid': vif_uuid})
                self._after_plug(instance, network, mapping, pif)
                return

        # NOTE(deva): should this really be raising an exception
        #             when there are no physical interfaces left?
        raise exception.NovaException(_(
                "Baremetal node: %(id)s has no available physical interface"
                " for virtual interface %(vif_uuid)s")
                % {'id': node['id'], 'vif_uuid': vif_uuid})
Ejemplo n.º 24
0
    def plug(self, instance, vif):
        LOG.debug(
            _("plug: instance_uuid=%(uuid)s vif=%(vif)s") % {
                'uuid': instance['uuid'],
                'vif': vif
            })
        network, mapping = vif
        vif_uuid = mapping['vif_uuid']
        ctx = context.get_admin_context()
        node = bmdb.bm_node_get_by_instance_uuid(ctx, instance['uuid'])

        # TODO(deva): optimize this database query
        #             this is just searching for a free physical interface
        pifs = bmdb.bm_interface_get_all_by_bm_node_id(ctx, node['id'])
        for pif in pifs:
            if not pif['vif_uuid']:
                bmdb.bm_interface_set_vif_uuid(ctx, pif['id'], vif_uuid)
                LOG.debug(
                    _("pif:%(id)s is plugged (vif_uuid=%(vif_uuid)s)") % {
                        'id': pif['id'],
                        'vif_uuid': vif_uuid
                    })
                self._after_plug(instance, network, mapping, pif)
                return

        # NOTE(deva): should this really be raising an exception
        #             when there are no physical interfaces left?
        raise exception.NovaException(
            _("Baremetal node: %(id)s has no available physical interface"
              " for virtual interface %(vif_uuid)s") % {
                  'id': node['id'],
                  'vif_uuid': vif_uuid
              })
Ejemplo n.º 25
0
 def index(self, req):
     context = req.environ['nova.context']
     authorize(context)
     nodes = []
     if _use_ironic():
         # proxy command to Ironic
         icli = _get_ironic_client()
         ironic_nodes = icli.node.list(detail=True)
         for inode in ironic_nodes:
             node = {
                 'id': inode.uuid,
                 'interfaces': [],
                 'host': 'IRONIC MANAGED',
                 'task_state': inode.provision_state,
                 'cpus': inode.properties['cpus'],
                 'memory_mb': inode.properties['memory_mb'],
                 'disk_gb': inode.properties['local_gb']
             }
             nodes.append(node)
     else:
         # use nova baremetal
         nodes_from_db = db.bm_node_get_all(context)
         for node_from_db in nodes_from_db:
             try:
                 ifs = db.bm_interface_get_all_by_bm_node_id(
                     context, node_from_db['id'])
             except exception.NodeNotFound:
                 ifs = []
             node = self._node_dict(node_from_db)
             node['interfaces'] = [_interface_dict(i) for i in ifs]
             nodes.append(node)
     return {'nodes': nodes}
Ejemplo n.º 26
0
 def _test_show(self, node, ext_status=False):
     interfaces = [fake_interface(id=1, address='11:11:11:11:11:11'),
                   fake_interface(id=2, address='22:22:22:22:22:22'),
                   ]
     node.update(interfaces=interfaces)
     response = node.copy()
     del response['pm_password']
     self.mox.StubOutWithMock(db, 'bm_node_get')
     self.mox.StubOutWithMock(db, 'bm_interface_get_all_by_bm_node_id')
     db.bm_node_get(self.context, node['id']).AndReturn(node)
     db.bm_interface_get_all_by_bm_node_id(self.context, node['id']).\
             AndReturn(interfaces)
     self.ext_mgr.is_loaded('os-baremetal-ext-status').AndReturn(ext_status)
     self.mox.ReplayAll()
     res_dict = self.controller.show(self.request, node['id'])
     self.assertEqual({'node': response}, res_dict)
     self.assertEqual(2, len(res_dict['node']['interfaces']))
Ejemplo n.º 27
0
 def _test_show(self, node, ext_status=False):
     interfaces = [fake_interface(id=1, address='11:11:11:11:11:11'),
                   fake_interface(id=2, address='22:22:22:22:22:22'),
                   ]
     node.update(interfaces=interfaces)
     response = node.copy()
     del response['pm_password']
     self.mox.StubOutWithMock(db, 'bm_node_get')
     self.mox.StubOutWithMock(db, 'bm_interface_get_all_by_bm_node_id')
     db.bm_node_get(self.context, node['id']).AndReturn(node)
     db.bm_interface_get_all_by_bm_node_id(self.context, node['id']).\
             AndReturn(interfaces)
     self.ext_mgr.is_loaded('os-baremetal-ext-status').AndReturn(ext_status)
     self.mox.ReplayAll()
     res_dict = self.controller.show(self.request, node['id'])
     self.assertEqual({'node': response}, res_dict)
     self.assertEqual(2, len(res_dict['node']['interfaces']))
Ejemplo n.º 28
0
Archivo: pxe.py Proyecto: chiehwen/nova
 def _collect_mac_addresses(self, context, node):
     macs = []
     macs.append(db.bm_node_get(context, node['id'])['prov_mac_address'])
     for nic in db.bm_interface_get_all_by_bm_node_id(context, node['id']):
         if nic['address']:
             macs.append(nic['address'])
     macs.sort()
     return macs
Ejemplo n.º 29
0
 def test_index(self):
     nodes = [{'id': 1},
              {'id': 2},
              ]
     interfaces = [{'id': 1, 'address': '11:11:11:11:11:11'},
                   {'id': 2, 'address': '22:22:22:22:22:22'},
                   ]
     self.mox.StubOutWithMock(db, 'bm_node_get_all')
     self.mox.StubOutWithMock(db, 'bm_interface_get_all_by_bm_node_id')
     db.bm_node_get_all(self.context).AndReturn(nodes)
     db.bm_interface_get_all_by_bm_node_id(self.context, 1).\
             AndRaise(exception.NodeNotFound(node_id=1))
     db.bm_interface_get_all_by_bm_node_id(self.context, 2).\
             AndReturn(interfaces)
     self.mox.ReplayAll()
     res_dict = self.controller.index(self.request)
     self.assertEqual(2, len(res_dict['nodes']))
     self.assertEqual([], res_dict['nodes'][0]['interfaces'])
     self.assertEqual(2, len(res_dict['nodes'][1]['interfaces']))
Ejemplo n.º 30
0
 def _plug_vifs(self, instance, network_info, context=None):
     if not context:
         context = nova_context.get_admin_context()
     node = _get_baremetal_node_by_instance_uuid(instance['uuid'])
     if node:
         pifs = db.bm_interface_get_all_by_bm_node_id(context, node['id'])
         for pif in pifs:
             if pif['vif_uuid']:
                 db.bm_interface_set_vif_uuid(context, pif['id'], None)
     for vif in network_info:
         self.vif_driver.plug(instance, vif)
Ejemplo n.º 31
0
 def _plug_vifs(self, instance, network_info, context=None):
     if not context:
         context = nova_context.get_admin_context()
     node = _get_baremetal_node_by_instance_uuid(instance['uuid'])
     if node:
         pifs = db.bm_interface_get_all_by_bm_node_id(context, node['id'])
         for pif in pifs:
             if pif['vif_uuid']:
                 db.bm_interface_set_vif_uuid(context, pif['id'], None)
     for (network, mapping) in network_info:
         self.vif_driver.plug(instance, (network, mapping))
Ejemplo n.º 32
0
 def _test_index(self, ext_status=False):
     nodes = [{'id': 1},
              {'id': 2},
              ]
     interfaces = [{'id': 1, 'address': '11:11:11:11:11:11'},
                   {'id': 2, 'address': '22:22:22:22:22:22'},
                   ]
     self.mox.StubOutWithMock(db, 'bm_node_get_all')
     self.mox.StubOutWithMock(db, 'bm_interface_get_all_by_bm_node_id')
     db.bm_node_get_all(self.context).AndReturn(nodes)
     db.bm_interface_get_all_by_bm_node_id(self.context, 1).\
             AndRaise(exception.NodeNotFound(node_id=1))
     for n in nodes:
         self.ext_mgr.is_loaded('os-baremetal-ext-status').\
             AndReturn(ext_status)
     db.bm_interface_get_all_by_bm_node_id(self.context, 2).\
             AndReturn(interfaces)
     self.mox.ReplayAll()
     res_dict = self.controller.index(self.request)
     self.assertEqual(2, len(res_dict['nodes']))
     self.assertEqual([], res_dict['nodes'][0]['interfaces'])
     self.assertEqual(2, len(res_dict['nodes'][1]['interfaces']))
Ejemplo n.º 33
0
 def show(self, req, id):
     context = req.environ['nova.context']
     authorize(context)
     try:
         node = db.bm_node_get(context, id)
     except exception.NodeNotFound as e:
         raise webob.exc.HTTPNotFound(explanation=e.format_message())
     try:
         ifs = db.bm_interface_get_all_by_bm_node_id(context, id)
     except exception.NodeNotFound:
         ifs = []
     node = _node_dict(node)
     node['interfaces'] = [_interface_dict(i) for i in ifs]
     return {'node': node}
Ejemplo n.º 34
0
 def show(self, req, id):
     context = req.environ['nova.context']
     authorize(context)
     try:
         node = db.bm_node_get(context, id)
     except exception.NodeNotFound:
         raise webob.exc.HTTPNotFound
     try:
         ifs = db.bm_interface_get_all_by_bm_node_id(context, id)
     except exception.NodeNotFound:
         ifs = []
     node = _node_dict(node)
     node['interfaces'] = [_interface_dict(i) for i in ifs]
     return {'node': node}
Ejemplo n.º 35
0
 def show(self, req, id):
     context = req.environ['nova.context']
     authorize(context)
     try:
         node = db.bm_node_get(context, id)
     except exception.InstanceNotFound:
         raise webob.exc.HTTPNotFound
     try:
         ifs = db.bm_interface_get_all_by_bm_node_id(context, id)
     except exception.InstanceNotFound:
         ifs = []
     node = _node_dict(node)
     node['interfaces'] = [_interface_dict(i) for i in ifs]
     return {'node': node}
Ejemplo n.º 36
0
 def index(self, req):
     context = req.environ["nova.context"]
     authorize(context)
     nodes_from_db = db.bm_node_get_all(context)
     nodes = []
     for node_from_db in nodes_from_db:
         try:
             ifs = db.bm_interface_get_all_by_bm_node_id(context, node_from_db["id"])
         except exception.NodeNotFound:
             ifs = []
         node = _node_dict(node_from_db)
         node["interfaces"] = [_interface_dict(i) for i in ifs]
         nodes.append(node)
     return {"nodes": nodes}
Ejemplo n.º 37
0
 def show(self, req, id):
     context = req.environ["nova.context"]
     authorize(context)
     try:
         node = db.bm_node_get(context, id)
     except exception.NodeNotFound as e:
         raise webob.exc.HTTPNotFound(explanation=e.format_message())
     try:
         ifs = db.bm_interface_get_all_by_bm_node_id(context, id)
     except exception.NodeNotFound:
         ifs = []
     node = _node_dict(node)
     node["interfaces"] = [_interface_dict(i) for i in ifs]
     return {"node": node}
Ejemplo n.º 38
0
 def index(self, req):
     context = req.environ['nova.context']
     authorize(context)
     nodes_from_db = db.bm_node_get_all(context)
     nodes = []
     for node_from_db in nodes_from_db:
         try:
             ifs = db.bm_interface_get_all_by_bm_node_id(
                     context, node_from_db['id'])
         except exception.InstanceNotFound:
             ifs = []
         node = _node_dict(node_from_db)
         node['interfaces'] = [_interface_dict(i) for i in ifs]
         nodes.append(node)
     return {'nodes': nodes}
Ejemplo n.º 39
0
 def index(self, req):
     context = req.environ['nova.context']
     authorize(context)
     nodes_from_db = db.bm_node_get_all(context)
     nodes = []
     for node_from_db in nodes_from_db:
         try:
             ifs = db.bm_interface_get_all_by_bm_node_id(
                     context, node_from_db['id'])
         except exception.NodeNotFound:
             ifs = []
         node = _node_dict(node_from_db)
         node['interfaces'] = [_interface_dict(i) for i in ifs]
         nodes.append(node)
     return {'nodes': nodes}
Ejemplo n.º 40
0
 def _remove_interface(self, req, id, body):
     context = req.environ["nova.context"]
     authorize(context)
     self._check_node_exists(context, id)
     body = body["remove_interface"]
     if_id = body.get("id")
     address = body.get("address")
     if not if_id and not address:
         raise webob.exc.HTTPBadRequest(explanation=_("Must specify id or address"))
     ifs = db.bm_interface_get_all_by_bm_node_id(context, id)
     for i in ifs:
         if if_id and if_id != i["id"]:
             continue
         if address and address != i["address"]:
             continue
         db.bm_interface_destroy(context, i["id"])
         return webob.Response(status_int=202)
     raise webob.exc.HTTPNotFound()
Ejemplo n.º 41
0
 def _remove_interface(self, req, id, body):
     context = req.environ['nova.context']
     authorize(context)
     self._check_node_exists(context, id)
     body = body['remove_interface']
     if_id = body.get('id')
     address = body.get('address')
     if not if_id and not address:
         raise webob.exc.HTTPBadRequest(
                 explanation=_("Must specify id or address"))
     ifs = db.bm_interface_get_all_by_bm_node_id(context, id)
     for i in ifs:
         if if_id and if_id != i['id']:
             continue
         if address and address != i['address']:
             continue
         db.bm_interface_destroy(context, i['id'])
         return
     raise webob.exc.HTTPNotFound()
Ejemplo n.º 42
0
    def __init__(self, **kwargs):
        global _conn
        global _cmds

        if _cmds is None:
            LOG.debug(_("Setting up %s commands."), CONF.baremetal.virtual_power_type)
            _vpc = "nova.virt.baremetal.virtual_power_driver_settings.%s" % CONF.baremetal.virtual_power_type
            _cmds = importutils.import_class(_vpc)
        self._vp_cmd = _cmds()
        self.connection_data = _conn
        node = kwargs.pop("node", {})
        instance = kwargs.pop("instance", {})
        self._node_name = instance.get("hostname", "")
        context = nova_context.get_admin_context()
        ifs = db.bm_interface_get_all_by_bm_node_id(context, node["id"])
        self._mac_addresses = [_normalize_mac(i["address"]) for i in ifs]
        self._connection = None
        self._matched_name = ""
        self.state = None
Ejemplo n.º 43
0
 def plug(self, instance, vif):
     LOG.debug("plug: instance_uuid=%s vif=%s", instance['uuid'], vif)
     network, mapping = vif
     ctx = context.get_admin_context()
     node = bmdb.bm_node_get_by_instance_uuid(ctx, instance['uuid'])
     if not node:
         return
     pifs = bmdb.bm_interface_get_all_by_bm_node_id(ctx, node['id'])
     for pif in pifs:
         if not pif['vif_uuid']:
             bmdb.bm_interface_set_vif_uuid(ctx, pif['id'],
                                            mapping.get('vif_uuid'))
             LOG.debug("pif:%s is plugged (vif_uuid=%s)",
                       pif['id'], mapping.get('vif_uuid'))
             self._after_plug(instance, network, mapping, pif)
             return
     raise exception.NovaException(
             "baremetalnode:%s has no vacant pif for vif_uuid=%s"
             % (node['id'], mapping['vif_uuid']))
Ejemplo n.º 44
0
 def plug(self, instance, vif):
     LOG.debug("plug: instance_uuid=%s vif=%s", instance['uuid'], vif)
     network, mapping = vif
     ctx = context.get_admin_context()
     node = bmdb.bm_node_get_by_instance_uuid(ctx, instance['uuid'])
     if not node:
         return
     pifs = bmdb.bm_interface_get_all_by_bm_node_id(ctx, node['id'])
     for pif in pifs:
         if not pif['vif_uuid']:
             bmdb.bm_interface_set_vif_uuid(ctx, pif['id'],
                                            mapping.get('vif_uuid'))
             LOG.debug("pif:%s is plugged (vif_uuid=%s)", pif['id'],
                       mapping.get('vif_uuid'))
             self._after_plug(instance, network, mapping, pif)
             return
     raise exception.NovaException(
         "baremetalnode:%s has no vacant pif for vif_uuid=%s" %
         (node['id'], mapping['vif_uuid']))
Ejemplo n.º 45
0
 def _remove_interface(self, req, id, body):
     context = req.environ['nova.context']
     authorize(context)
     self._check_node_exists(context, id)
     body = body['remove_interface']
     if_id = body.get('id')
     address = body.get('address')
     if not if_id and not address:
         raise webob.exc.HTTPBadRequest(
                 explanation=_("Must specify id or address"))
     ifs = db.bm_interface_get_all_by_bm_node_id(context, id)
     for i in ifs:
         if if_id and if_id != i['id']:
             continue
         if address and address != i['address']:
             continue
         db.bm_interface_destroy(context, i['id'])
         return webob.Response(status_int=202)
     raise webob.exc.HTTPNotFound()
Ejemplo n.º 46
0
    def __init__(self, **kwargs):
        global _conn
        global _cmds

        if _cmds is None:
            LOG.debug(_("Setting up %s commands."),
                      CONF.baremetal.virtual_power_type)
            _vpc = 'nova.virt.baremetal.virtual_power_driver_settings.%s' % \
                    CONF.baremetal.virtual_power_type
            _cmds = importutils.import_class(_vpc)
        self._vp_cmd = _cmds()
        self.connection_data = _conn
        node = kwargs.pop('node', {})
        instance = kwargs.pop('instance', {})
        self._node_name = instance.get('hostname', "")
        context = nova_context.get_admin_context()
        ifs = db.bm_interface_get_all_by_bm_node_id(context, node['id'])
        self._mac_addresses = [_normalize_mac(i['address']) for i in ifs]
        self._connection = None
        self._matched_name = ''
        self.state = None
Ejemplo n.º 47
0
 def _collect_mac_addresses(self, context, node):
     macs = set()
     for nic in db.bm_interface_get_all_by_bm_node_id(context, node['id']):
         if nic['address']:
             macs.add(nic['address'])
     return sorted(macs)
Ejemplo n.º 48
0
 def macs_for_instance(self, instance):
     context = nova_context.get_admin_context()
     node_id = self._require_node(instance)
     return set(iface["address"] for iface in db.bm_interface_get_all_by_bm_node_id(context, node_id))
Ejemplo n.º 49
0
    def _inject_to_image(self,
                         context,
                         target,
                         node,
                         inst,
                         network_info,
                         injected_files=None,
                         admin_password=None):
        # For now, we assume that if we're not using a kernel, we're using a
        # partitioned disk image where the target partition is the first
        # partition
        target_partition = None
        if not inst['kernel_id']:
            target_partition = "1"

        nics_in_order = []
        pifs = bmdb.bm_interface_get_all_by_bm_node_id(context, node['id'])
        for pif in pifs:
            nics_in_order.append(pif['address'])
        nics_in_order.append(node['prov_mac_address'])

        # rename nics to be in the order in the DB
        LOG.debug("injecting persistent net")
        rules = ""
        i = 0
        for hwaddr in nics_in_order:
            rules += 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ' \
                     'ATTR{address}=="%s", ATTR{dev_id}=="0x0", ' \
                     'ATTR{type}=="1", KERNEL=="eth*", NAME="eth%d"\n' \
                     % (hwaddr.lower(), i)
            i += 1
        if not injected_files:
            injected_files = []
        injected_files.append(
            ('/etc/udev/rules.d/70-persistent-net.rules', rules))
        bootif_name = "eth%d" % (i - 1)

        if inst['key_data']:
            key = str(inst['key_data'])
        else:
            key = None
        net = ""
        nets = []
        ifc_template = open(FLAGS.baremetal_injected_network_template).read()
        ifc_num = -1
        have_injected_networks = False
        for (network_ref, mapping) in network_info:
            ifc_num += 1
            # always inject
            #if not network_ref['injected']:
            #    continue
            have_injected_networks = True
            address = mapping['ips'][0]['ip']
            netmask = mapping['ips'][0]['netmask']
            address_v6 = None
            gateway_v6 = None
            netmask_v6 = None
            if FLAGS.use_ipv6:
                address_v6 = mapping['ip6s'][0]['ip']
                netmask_v6 = mapping['ip6s'][0]['netmask']
                gateway_v6 = mapping['gateway_v6']
            name = 'eth%d' % ifc_num
            if FLAGS.baremetal_use_unsafe_vlan \
                    and mapping['should_create_vlan'] \
                    and network_ref.get('vlan'):
                name = 'eth%d.%d' % (ifc_num, network_ref.get('vlan'))
            net_info = {
                'name': name,
                'address': address,
                'netmask': netmask,
                'gateway': mapping['gateway'],
                'broadcast': mapping['broadcast'],
                'dns': ' '.join(mapping['dns']),
                'address_v6': address_v6,
                'gateway_v6': gateway_v6,
                'netmask_v6': netmask_v6,
                'hwaddress': mapping['mac']
            }
            nets.append(net_info)

        if have_injected_networks:
            _late_load_cheetah()
            net = str(
                Template(ifc_template,
                         searchList=[{
                             'interfaces': nets,
                             'use_ipv6': FLAGS.use_ipv6
                         }]))
        net += "\n"
        net += "auto %s\n" % bootif_name
        net += "iface %s inet dhcp\n" % bootif_name

        if not FLAGS.baremetal_inject_password:
            admin_password = None

        metadata = inst.get('metadata')
        if any((key, net, metadata, admin_password)):
            inst_name = inst['name']

            img_id = inst['image_ref']

            for injection in ('metadata', 'key', 'net', 'admin_password'):
                if locals()[injection]:
                    LOG.info(_('instance %(inst_name)s: injecting '
                               '%(injection)s into image %(img_id)s'),
                             locals(),
                             instance=inst)
            try:
                disk.inject_data(target,
                                 key,
                                 net,
                                 metadata,
                                 admin_password,
                                 files=injected_files,
                                 partition=target_partition,
                                 use_cow=False)

            except Exception as e:
                # This could be a windows image, or a vmdk format disk
                LOG.warn(_('instance %(inst_name)s: ignoring error injecting'
                           ' data into image %(img_id)s (%(e)s)') % locals(),
                         instance=inst)
Ejemplo n.º 50
0
 def macs_for_instance(self, instance):
     context = nova_context.get_admin_context()
     node_uuid = self._require_node(instance)
     node = db.bm_node_get_by_node_uuid(context, node_uuid)
     ifaces = db.bm_interface_get_all_by_bm_node_id(context, node['id'])
     return set(iface['address'] for iface in ifaces)
Ejemplo n.º 51
0
 def macs_for_instance(self, instance):
     context = nova_context.get_admin_context()
     node_uuid = self._require_node(instance)
     node = db.bm_node_get_by_node_uuid(context, node_uuid)
     ifaces = db.bm_interface_get_all_by_bm_node_id(context, node['id'])
     return set(iface['address'] for iface in ifaces)