本文整理汇总了Python中nailgun.objects.Cluster.get_by_uid方法的典型用法代码示例。如果您正苦于以下问题:Python Cluster.get_by_uid方法的具体用法?Python Cluster.get_by_uid怎么用?Python Cluster.get_by_uid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nailgun.objects.Cluster
的用法示例。
在下文中一共展示了Cluster.get_by_uid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_cluster
# 需要导入模块: from nailgun.objects import Cluster [as 别名]
# 或者: from nailgun.objects.Cluster import get_by_uid [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
示例2: create
# 需要导入模块: from nailgun.objects import Cluster [as 别名]
# 或者: from nailgun.objects.Cluster import get_by_uid [as 别名]
def create(cls, data):
new_group = super(NodeGroup, cls).create(data)
try:
cluster = Cluster.get_by_uid(new_group.cluster_id)
nm = Cluster.get_network_manager(cluster)
nst = cluster.network_config.segmentation_type
# We have two node groups here when user adds the first custom
# node group.
if NodeGroupCollection.get_by_cluster_id(cluster.id).count() == 2:
nm.ensure_gateways_present_in_default_node_group(cluster)
nm.create_network_groups(
cluster, neutron_segment_type=nst, node_group_id=new_group.id,
set_all_gateways=True)
nm.create_admin_network_group(new_group.cluster_id, new_group.id)
except (
errors.OutOfVLANs,
errors.OutOfIPs,
errors.NoSuitableCIDR
) as exc:
db().delete(new_group)
raise errors.CannotCreate(exc.message)
db().flush()
db().refresh(cluster)
return new_group
示例3: checkout
# 需要导入模块: from nailgun.objects import Cluster [as 别名]
# 或者: from nailgun.objects.Cluster import get_by_uid [as 别名]
def checkout(self, instance):
fetch_file = os.path.join(
const.REPOS_DIR,
instance.repo_name,
'.git/FETCH_HEAD'
)
if os.path.exists(fetch_file):
current_ts = time.time()
cluster = Cluster.get_by_uid(instance.env_id)
last_fetch = os.stat(fetch_file).st_mtime
if cluster.status != CLUSTER_STATUSES.deployment and \
current_ts - last_fetch < const.REPO_TTL:
return
logger.debug("Repo TTL exceeded. Fetching code...")
ssh_cmd = self._get_ssh_cmd(instance.repo_name)
if not os.path.exists(self._get_key_path(instance.repo_name)):
logger.debug('Key file does not exist. Creating...')
self._create_key_file(instance.repo_name)
with instance.repo.git.custom_environment(GIT_SSH=ssh_cmd):
commit = instance.repo.remotes.origin.fetch(refspec=instance.ref)
commit = commit[0].commit
instance.repo.head.reference = commit
instance.repo.head.reset(index=True, working_tree=True)
示例4: process_deployment_for_cluster
# 需要导入模块: from nailgun.objects import Cluster [as 别名]
# 或者: from nailgun.objects.Cluster import get_by_uid [as 别名]
def process_deployment_for_cluster(cls, cluster, cluster_data):
from cluster_upgrade.objects.relations import UpgradeRelationObject
relation = UpgradeRelationObject.get_cluster_relation(cluster.id)
orig_env = Cluster.get_by_uid(relation.orig_cluster_id)
seed_env = Cluster.get_by_uid(relation.seed_cluster_id)
cluster_data['upgrade'] = {
'relation_info': {
'orig_cluster_id': relation.orig_cluster_id,
'seed_cluster_id': relation.seed_cluster_id,
'orig_cluster_version': orig_env.release.environment_version,
'seed_cluster_version': seed_env.release.environment_version
}
}
示例5: create_cluster
# 需要导入模块: from nailgun.objects import Cluster [as 别名]
# 或者: from nailgun.objects.Cluster import get_by_uid [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
示例6: assign_vip
# 需要导入模块: from nailgun.objects import Cluster [as 别名]
# 或者: from nailgun.objects.Cluster import get_by_uid [as 别名]
def assign_vip(cls, cluster_id, network_name):
"""Idempotent assignment VirtualIP addresses to cluster.
Returns VIP for given cluster and network.
It's required for HA deployment to have IP address
not assigned to any of nodes. Currently we need one
VIP per network in cluster. If cluster already has
IP address from this network, it remains unchanged.
If one of the nodes is the node from other cluster,
this func will fail.
:param cluster_id: Cluster database ID.
:type cluster_id: int
:param network_name: Network name
:type network_name: str
:returns: None
:raises: Exception
"""
cluster = Cluster.get_by_uid(cluster_id)
if not cluster:
raise Exception(u"Cluster id='%s' not found" % cluster_id)
network = db().query(NetworkGroup).\
filter(NetworkGroup.cluster_id == cluster_id).\
filter_by(name=network_name).first()
if not network:
raise Exception(u"Network '%s' for cluster_id=%s not found." %
(network_name, cluster_id))
admin_net_id = cls.get_admin_network_group_id()
cluster_ips = [ne.ip_addr for ne in db().query(IPAddr).filter_by(
network=network.id,
node=None
).filter(
not_(IPAddr.network == admin_net_id)
).all()]
# check if any of used_ips in required cidr: network.cidr
ips_belongs_to_net = False
for ip in cluster_ips:
if cls.check_ip_belongs_to_net(ip, network):
ips_belongs_to_net = True
break
if ips_belongs_to_net:
vip = cluster_ips[0]
else:
# IP address has not been assigned, let's do it
vip = cls.get_free_ips(network.id)[0]
ne_db = IPAddr(network=network.id, ip_addr=vip)
db().add(ne_db)
db().commit()
return vip
示例7: test_get_attributes_centos
# 需要导入模块: from nailgun.objects import Cluster [as 别名]
# 或者: from nailgun.objects.Cluster import get_by_uid [as 别名]
def test_get_attributes_centos(self):
self.skipTest("CentOS is unavailable in current release.")
self.env.upload_fixtures(["openstack"])
info = InstallationInfo()
release = ReleaseCollection.filter_by(None, operating_system="CentOS")
cluster_data = self.env.create_cluster(release_id=release[0].id)
cluster = Cluster.get_by_uid(cluster_data["id"])
editable = cluster.attributes.editable
attr_key_list = [a[1] for a in info.attributes_white_list]
attrs_dict = info.get_attributes(editable, info.attributes_white_list)
self.assertEqual(set(attr_key_list), set(attrs_dict.keys()))
示例8: create
# 需要导入模块: from nailgun.objects import Cluster [as 别名]
# 或者: from nailgun.objects.Cluster import get_by_uid [as 别名]
def create(cls, data):
new_group = super(NodeGroup, cls).create(data)
cluster = Cluster.get_by_uid(new_group.cluster_id)
try:
fire_callback_on_nodegroup_create(new_group)
except errors.CannotCreate:
db().delete(new_group)
db().flush()
db().refresh(cluster)
return new_group
示例9: create
# 需要导入模块: from nailgun.objects import Cluster [as 别名]
# 或者: from nailgun.objects.Cluster import get_by_uid [as 别名]
def create(cls, data):
new_group = super(NodeGroup, cls).create(data)
try:
cluster = Cluster.get_by_uid(new_group.cluster_id)
nm = Cluster.get_network_manager(cluster)
nst = cluster.network_config.segmentation_type
nm.create_network_groups(cluster, nst, gid=new_group.id)
nm.create_admin_network_group(new_group.cluster_id, new_group.id)
except (errors.OutOfVLANs, errors.OutOfIPs, errors.NoSuitableCIDR, errors.InvalidNetworkPool) as exc:
db().delete(new_group)
raise errors.CannotCreate(exc.message)
db().flush()
return new_group
示例10: test_get_attributes_ubuntu
# 需要导入模块: from nailgun.objects import Cluster [as 别名]
# 或者: from nailgun.objects.Cluster import get_by_uid [as 别名]
def test_get_attributes_ubuntu(self):
self.env.upload_fixtures(["openstack"])
info = InstallationInfo()
release = ReleaseCollection.filter_by(None, operating_system="Ubuntu")
cluster_data = self.env.create_cluster(release_id=release[0].id)
cluster = Cluster.get_by_uid(cluster_data["id"])
editable = cluster.attributes.editable
attr_key_list = [a[1] for a in info.attributes_white_list]
attrs_dict = info.get_attributes(editable, info.attributes_white_list)
self.assertEqual(
# no vlan splinters for ubuntu
set(attr_key_list) - set(("vlan_splinters", "vlan_splinters_ovs")),
set(attrs_dict.keys()),
)
示例11: test_get_attributes_centos
# 需要导入模块: from nailgun.objects import Cluster [as 别名]
# 或者: from nailgun.objects.Cluster import get_by_uid [as 别名]
def test_get_attributes_centos(self):
self.env.upload_fixtures(['openstack'])
info = InstallationInfo()
release = ReleaseCollection.filter_by(None, operating_system='CentOS')
cluster_data = self.env.create_cluster(
release_id=release[0].id
)
cluster = Cluster.get_by_uid(cluster_data['id'])
editable = cluster.attributes.editable
attr_key_list = [a[1] for a in info.attributes_white_list]
attrs_dict = info.get_attributes(editable)
self.assertEqual(
set(attr_key_list),
set(attrs_dict.keys())
)
示例12: _do_test_attributes_in_white_list
# 需要导入模块: from nailgun.objects import Cluster [as 别名]
# 或者: from nailgun.objects.Cluster import get_by_uid [as 别名]
def _do_test_attributes_in_white_list(self, release,
expected_attributes):
cluster_data = self.env.create_cluster(
release_id=release.id
)
cluster = Cluster.get_by_uid(cluster_data['id'])
editable = cluster.attributes.editable
info = InstallationInfo()
actual_attributes = info.get_attributes(
editable, info.attributes_white_list)
self.assertEqual(
set(expected_attributes),
set(actual_attributes.keys())
)
示例13: test_clear_data_for_removed_cluster
# 需要导入模块: from nailgun.objects import Cluster [as 别名]
# 或者: from nailgun.objects.Cluster import get_by_uid [as 别名]
def test_clear_data_for_removed_cluster(self, get_info_mock, *_):
cls_id, res_data = self.collect_for_operational_cluster(get_info_mock)
cls = Cluster.get_by_uid(cls_id)
Cluster.delete(cls)
oswl_collect_once(consts.OSWL_RESOURCE_TYPES.vm)
last = OpenStackWorkloadStats.get_last_by(
cls_id, consts.OSWL_RESOURCE_TYPES.vm)
removed = dict(self.vms_info[0])
removed['time'] = last.updated_time.isoformat()
res_data.update({
'removed': [removed],
'current': []})
# current data is cleared when cluster is deleted
self.assertEqual(last.resource_data, res_data)
示例14: init
# 需要导入模块: from nailgun.objects import Cluster [as 别名]
# 或者: from nailgun.objects.Cluster import get_by_uid [as 别名]
def init(self, instance):
overrides = {
'nodes': {},
'roles': {}
}
repo_path = os.path.join(const.REPOS_DIR, instance.repo_name)
templates_dir = os.path.join(os.path.dirname(__file__),
'templates', 'gitrepo')
overrides_path = os.path.join(repo_path, 'overrides.yaml')
try:
self.checkout(instance)
except exc.GitCommandError as e:
logger.debug(("Remote returned following error {}. "
"Seem remote has not been initialised. "
"Skipping checkout".format(e)))
cluster = Cluster.get_by_uid(instance.env_id)
for node in cluster.nodes:
overrides['nodes'][node.uid] = "node_{}_configs".format(node.uid)
for role in node.all_roles:
overrides['roles'][role] = role + '_configs'
if not os.path.exists(overrides_path):
with open(os.path.join(repo_path, 'overrides.yaml'), 'w') as fd:
yaml.dump(overrides, fd, default_flow_style=False)
else:
logger.debug('Overrides file exists. Skipping autogenerated...')
pass
copy_tree(templates_dir, repo_path)
if instance.repo.is_dirty(untracked_files=True):
instance.repo.git.add('-A')
instance.repo.git.commit('-m "Config repo Initialized"')
ssh_cmd = self._get_ssh_cmd(instance.repo_name)
with instance.repo.git.custom_environment(
GIT_SSH=ssh_cmd):
res = instance.repo.remotes.origin.push(
refspec='HEAD:' + instance.ref)
logger.debug("Push result {}".format(res[0].flags))
if res[0].flags not in (2, 256):
logger.debug("Push error. Result code should be 2 or 256")
if res[0].flags == res[0].UP_TO_DATE:
raise errors.NoChanges
else:
raise errors.UnresolvableConflict
示例15: test_get_attributes_ubuntu
# 需要导入模块: from nailgun.objects import Cluster [as 别名]
# 或者: from nailgun.objects.Cluster import get_by_uid [as 别名]
def test_get_attributes_ubuntu(self):
self.env.upload_fixtures(['openstack'])
info = InstallationInfo()
release = ReleaseCollection.filter_by(None, operating_system='Ubuntu')
cluster_data = self.env.create_cluster(
release_id=release[0].id
)
cluster = Cluster.get_by_uid(cluster_data['id'])
editable = cluster.attributes.editable
attr_key_list = [a[1] for a in info.attributes_white_list]
attrs_dict = info.get_attributes(editable, info.attributes_white_list)
self.assertEqual(
# No vlan splinters for ubuntu.
# And no mellanox related entries since 8.0.
set(attr_key_list) - set(
('vlan_splinters', 'vlan_splinters_ovs',
'mellanox', 'mellanox_vf_num', 'iser')),
set(attrs_dict.keys())
)