本文整理汇总了Python中nailgun.objects.Node.create方法的典型用法代码示例。如果您正苦于以下问题:Python Node.create方法的具体用法?Python Node.create怎么用?Python Node.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nailgun.objects.Node
的用法示例。
在下文中一共展示了Node.create方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_node
# 需要导入模块: from nailgun.objects import Node [as 别名]
# 或者: from nailgun.objects.Node import create [as 别名]
def create_node(self, api=False, exclude=None, expect_http=201, expected_error=None, **kwargs):
# TODO(alekseyk) Simplify 'interfaces' and 'mac' manipulation logic
metadata = kwargs.get("meta")
default_metadata = self.default_metadata()
if metadata:
default_metadata.update(metadata)
meta_ifaces = "interfaces" in metadata
mac = kwargs.get("mac", self.generate_random_mac())
if default_metadata["interfaces"]:
default_metadata["interfaces"][0]["mac"] = mac
if not metadata or not meta_ifaces:
for iface in default_metadata["interfaces"][1:]:
if "mac" in iface:
iface["mac"] = self.generate_random_mac()
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
示例2: create_node
# 需要导入模块: from nailgun.objects import Node [as 别名]
# 或者: from nailgun.objects.Node import create [as 别名]
def create_node(
self, api=False,
exclude=None, expect_http=201,
expect_message=None,
**kwargs):
#TODO(alekseyk) Simplify 'interfaces' and 'mac' manipulation logic
metadata = kwargs.get('meta')
default_metadata = self.default_metadata()
if metadata:
default_metadata.update(metadata)
meta_ifaces = 'interfaces' in metadata
mac = kwargs.get('mac', self.generate_random_mac())
if default_metadata['interfaces']:
default_metadata['interfaces'][0]['mac'] = mac
if not metadata or not meta_ifaces:
for iface in default_metadata['interfaces'][1:]:
if 'mac' in iface:
iface['mac'] = self.generate_random_mac()
node_data = {
'mac': mac,
'status': 'discover',
'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)
if expect_message:
self.tester.assertEqual(resp.body, expect_message)
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