

def create_node(self, api=False, exclude=None, expect_http=201, expected_error=None, **kwargs):
    metadata = kwargs.get('meta', {
        
    })
    default_metadata = self.default_metadata()
    default_metadata.update(metadata)
    mac = kwargs.get('mac', self.generate_random_mac())
    if default_metadata['interfaces']:
        if ((not metadata) or ('interfaces' not in metadata)):
            default_metadata['interfaces'][0]['mac'] = mac
            default_metadata['interfaces'][0]['pxe'] = True
            for iface in default_metadata['interfaces'][1:]:
                if ('mac' in iface):
                    iface['mac'] = self.generate_random_mac()
        else:
            for iface in default_metadata['interfaces']:
                if iface.get('pxe'):
                    if (not iface.get('mac')):
                        iface['mac'] = mac
                    elif ('mac' not in kwargs):
                        mac = iface['mac']
                if (iface.get('mac') == mac):
                    break
            else:
                default_metadata['interfaces'][0]['mac'] = mac
                default_metadata['interfaces'][0]['pxe'] = True
    node_data = {
        'mac': mac,
        'status': 'discover',
        'ip': '10.20.0.130',
        'meta': default_metadata,
    }
    if kwargs:
        meta = kwargs.pop('meta', None)
        node_data.update(kwargs)
        if meta:
            kwargs['meta'] = meta
    if (exclude and isinstance(exclude, list)):
        for ex in exclude:
            try:
                del node_data[ex]
            except KeyError as err:
                logger.warning(err)
    if api:
        resp = self.app.post(reverse('NodeCollectionHandler'), jsonutils.dumps(node_data), headers=self.default_headers, expect_errors=True)
        self.tester.assertEqual(resp.status_code, expect_http, resp.body)
        if expected_error:
            self.tester.assertEqual(resp.json_body['message'], expected_error)
        if (str(expect_http)[0] != '2'):
            return None
        self.tester.assertEqual(resp.status_code, expect_http)
        node = resp.json_body
        node_db = Node.get_by_uid(node['id'])
        if (('interfaces' not in node_data['meta']) or (not node_data['meta']['interfaces'])):
            self._set_interfaces_if_not_set_in_meta(node_db.id, kwargs.get('meta', None))
        self.nodes.append(node_db)
    else:
        node = Node.create(node_data)
        db().commit()
        self.nodes.append(node)
    return node

dataset/ETHPy150Open openstack/fuel-web/nailgun/nailgun/test/base.py EnvironmentManager.create_node/original