本文整理汇总了Python中nailgun.objects.Cluster.create方法的典型用法代码示例。如果您正苦于以下问题:Python Cluster.create方法的具体用法?Python Cluster.create怎么用?Python Cluster.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nailgun.objects.Cluster
的用法示例。
在下文中一共展示了Cluster.create方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fn
# 需要导入模块: from nailgun.objects import Cluster [as 别名]
# 或者: from nailgun.objects.Cluster import create [as 别名]
def fn():
# try to commit wrong data
Cluster.create(
{
"id": "500",
"release_id": "500"
}
)
self.db.commit()
示例2: create_cluster
# 需要导入模块: from nailgun.objects import Cluster [as 别名]
# 或者: from nailgun.objects.Cluster import create [as 别名]
def create_cluster(self, api=True, exclude=None, **kwargs):
cluster_data = {"name": "cluster-api-" + str(randint(0, 1000000))}
editable_attributes = kwargs.pop("editable_attributes", None)
if kwargs:
cluster_data.update(kwargs)
if "release_id" not in cluster_data:
cluster_data["release_id"] = self.create_release(api=False).id
if exclude and isinstance(exclude, list):
for ex in exclude:
try:
del cluster_data[ex]
except KeyError as err:
logger.warning(err)
if api:
resp = self.app.post(
reverse("ClusterCollectionHandler"),
jsonutils.dumps(cluster_data),
headers=self.default_headers,
expect_errors=True,
)
self.tester.assertEqual(resp.status_code, 201, resp.body)
cluster = resp.json_body
cluster_db = Cluster.get_by_uid(cluster["id"])
else:
cluster = Cluster.create(cluster_data)
cluster_db = cluster
db().commit()
self.clusters.append(cluster_db)
if editable_attributes:
Cluster.patch_attributes(cluster_db, {"editable": editable_attributes})
return cluster
示例3: create_cluster
# 需要导入模块: from nailgun.objects import Cluster [as 别名]
# 或者: from nailgun.objects.Cluster import create [as 别名]
def create_cluster(self, api=True, exclude=None, **kwargs):
cluster_data = {
'name': 'cluster-api-' + str(randint(0, 1000000)),
}
if kwargs:
cluster_data.update(kwargs)
if 'release_id' not in cluster_data:
cluster_data['release_id'] = self.create_release(api=False).id
if exclude and isinstance(exclude, list):
for ex in exclude:
try:
del cluster_data[ex]
except KeyError as err:
logger.warning(err)
if api:
resp = self.app.post(
reverse('ClusterCollectionHandler'),
jsonutils.dumps(cluster_data),
headers=self.default_headers,
expect_errors=True
)
self.tester.assertEqual(resp.status_code, 201)
cluster = resp.json_body
self.clusters.append(
Cluster.get_by_uid(cluster['id'])
)
else:
cluster = Cluster.create(cluster_data)
db().commit()
self.clusters.append(cluster)
return cluster