本文整理汇总了Python中nailgun.objects.Cluster类的典型用法代码示例。如果您正苦于以下问题:Python Cluster类的具体用法?Python Cluster怎么用?Python Cluster使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Cluster类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mellanox_settings
def mellanox_settings(cls, node_attrs, node):
"""Serialize mellanox node attrs, then it will be
merged with common attributes, if mellanox plugin or iSER storage
enabled.
"""
# Get Mellanox data
neutron_mellanox_data = \
Cluster.get_attributes(node.cluster).editable\
.get('neutron_mellanox', {})
# Get storage data
storage_data = \
Cluster.get_attributes(node.cluster).editable.get('storage', {})
# Get network manager
nm = objects.Node.get_network_manager(node)
# Init mellanox dict
node_attrs['neutron_mellanox'] = {}
# Find Physical port for VFs generation
if 'plugin' in neutron_mellanox_data and \
neutron_mellanox_data['plugin']['value'] == 'ethernet':
node_attrs = cls.set_mellanox_ml2_config(node_attrs, node, nm)
# Fix network scheme to have physical port for RDMA if iSER enabled
if 'iser' in storage_data and storage_data['iser']['value']:
node_attrs = cls.fix_iser_port(node_attrs, node, nm)
return node_attrs
示例2: mellanox_settings
def mellanox_settings(cls, node_attrs, cluster, networks):
"""Mellanox settings
Serialize mellanox node attrsthen it will be
merged with common attributes, if mellanox plugin or iSER storage
enabled.
"""
# Get Mellanox data
neutron_mellanox_data = Cluster.get_attributes(cluster).editable.get("neutron_mellanox", {})
# Get storage data
storage_data = Cluster.get_attributes(cluster).editable.get("storage", {})
# Get network manager
nm = Cluster.get_network_manager(cluster)
# Init mellanox dict
node_attrs["neutron_mellanox"] = {}
# Find Physical port for VFs generation
if "plugin" in neutron_mellanox_data and neutron_mellanox_data["plugin"]["value"] == "ethernet":
node_attrs = cls.set_mellanox_ml2_config(node_attrs, nm, networks)
# Fix network scheme to have physical port for RDMA if iSER enabled
if "iser" in storage_data and storage_data["iser"]["value"]:
node_attrs = cls.fix_iser_port(node_attrs, nm, networks)
return node_attrs
示例3: create_cluster
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
示例4: update_pending_roles
def update_pending_roles(cls, instance, new_pending_roles):
"""Update pending_roles for Node instance.
Logs an error if node doesn't belong to Cluster
:param instance: Node instance
:param new_pending_roles: list of new pending role names
:returns: None
"""
if not instance.cluster_id:
logger.warning(
u"Attempting to assign pending roles to node "
u"'{0}' which isn't added to cluster".format(
instance.full_name))
return
logger.debug(
u"Updating pending roles for node {0}: {1}".format(
instance.full_name,
new_pending_roles))
if new_pending_roles == []:
# TODO(enchantner): research why the hell we need this
Cluster.clear_pending_changes(
instance.cluster,
node_id=instance.id
)
instance.pending_roles = new_pending_roles
db().flush()
示例5: create
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
示例6: test_get_auth_credentials
def test_get_auth_credentials(self):
expected_username = "test"
expected_password = "test"
expected_tenant = "test"
expected_auth_host = "0.0.0.0"
expected_auth_url = "http://{0}:{1}/{2}/".format(
expected_auth_host, settings.AUTH_PORT,
settings.OPENSTACK_API_VERSION["keystone"])
expected = (expected_username, expected_password, expected_tenant,
expected_auth_url)
cluster = self.env.create_cluster(api=False)
updated_attributes = {
"editable": {
"workloads_collector": {
"username": {"value": expected_username},
"password": {"value": expected_password},
"tenant": {"value": expected_tenant}
}
}
}
Cluster.update_attributes(cluster, updated_attributes)
get_host_for_auth_path = ("nailgun.statistics.utils."
"get_mgmt_ip_of_cluster_controller")
with patch(get_host_for_auth_path,
return_value=expected_auth_host):
client_provider = helpers.ClientProvider(cluster)
creds = client_provider.credentials
self.assertEqual(expected, creds)
示例7: create_cluster
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
示例8: _generate_external_network
def _generate_external_network(cls, cluster):
public_cidr, public_gw = db().query(
NetworkGroup.cidr,
NetworkGroup.gateway
).filter_by(
group_id=Cluster.get_default_group(cluster).id,
name='public'
).first()
return {
"L3": {
"subnet": public_cidr,
"gateway": public_gw,
"nameservers": [],
"floating": utils.join_range(
cluster.network_config.floating_ranges[0]),
"enable_dhcp": False
},
"L2": {
"network_type": "flat",
"segment_id": None,
"router_ext": True,
"physnet": "physnet1"
},
"tenant": Cluster.get_creds(cluster)['tenant']['value'],
"shared": False
}
示例9: remove_from_cluster
def remove_from_cluster(cls, instance):
"""Remove Node from Cluster.
Also drops networks assignment for Node and clears both
roles and pending roles
:param instance: Node instance
:returns: None
"""
if instance.cluster:
Cluster.clear_pending_changes(
instance.cluster,
node_id=instance.id
)
netmanager = Cluster.get_network_manager(
instance.cluster
)
netmanager.clear_assigned_networks(instance)
netmanager.clear_bond_configuration(instance)
cls.update_roles(instance, [])
cls.update_pending_roles(instance, [])
cls.remove_replaced_params(instance)
instance.cluster_id = None
instance.group_id = None
instance.kernel_params = None
instance.primary_roles = []
instance.hostname = cls.default_slave_name(instance)
from nailgun.objects import OpenstackConfig
OpenstackConfig.disable_by_nodes([instance])
db().flush()
db().refresh(instance)
示例10: remove_from_cluster
def remove_from_cluster(cls, instance):
"""Remove Node from Cluster.
Also drops networks assignment for Node and clears both
roles and pending roles
:param instance: Node instance
:returns: None
"""
if instance.cluster:
Cluster.clear_pending_changes(
instance.cluster,
node_id=instance.id
)
netmanager = Cluster.get_network_manager(
instance.cluster
)
netmanager.clear_assigned_networks(instance)
netmanager.clear_bond_configuration(instance)
cls.update_roles(instance, [])
cls.update_pending_roles(instance, [])
cls.remove_replaced_params(instance)
instance.cluster_id = None
instance.group_id = None
instance.kernel_params = None
instance.reset_name_to_default()
db().flush()
db().refresh(instance)
示例11: update_pending_roles
def update_pending_roles(cls, instance, new_pending_roles):
if not instance.cluster_id:
logger.warning(
u"Attempting to assign pending roles to node "
u"'{0}' which isn't added to cluster".format(
instance.name or instance.id
)
)
return
logger.debug(
u"Updating pending roles for node {0}: {1}".format(
instance.id,
new_pending_roles
)
)
if new_pending_roles == []:
instance.pending_role_list = []
# research why the hell we need this
Cluster.clear_pending_changes(
instance.cluster,
node_id=instance.id
)
else:
instance.pending_role_list = db().query(models.Role).filter_by(
release_id=instance.cluster.release_id,
).filter(
models.Role.name.in_(new_pending_roles)
).all()
db().flush()
db().refresh(instance)
示例12: update_volumes
def update_volumes(cls, instance):
attrs = instance.attributes
if not attrs:
attrs = cls.create_attributes(instance)
try:
attrs.volumes = instance.volume_manager.gen_volumes_info()
except Exception as exc:
msg = (
u"Failed to generate volumes "
u"info for node '{0}': '{1}'"
).format(
instance.name or instance.mac or instance.id,
str(exc) or "see logs for details"
)
logger.warning(traceback.format_exc())
Notification.create({
"topic": "error",
"message": msg,
"node_id": instance.id
})
if instance.cluster_id:
Cluster.add_pending_changes(
instance.cluster,
"disks",
node_id=instance.id
)
db().add(attrs)
db().flush()
示例13: update_pending_roles
def update_pending_roles(cls, instance, new_pending_roles):
"""Update pending_roles for Node instance.
Logs an error if node doesn't belong to Cluster
:param instance: Node instance
:param new_pending_roles: list of new pending role names
:returns: None
"""
if not instance.cluster_id:
logger.warning(
u"Attempting to assign pending roles to node "
u"'{0}' which isn't added to cluster".format(instance.name or instance.id)
)
return
logger.debug(u"Updating pending roles for node {0}: {1}".format(instance.id, new_pending_roles))
if new_pending_roles == []:
instance.pending_role_list = []
# TODO(enchantner): research why the hell we need this
Cluster.clear_pending_changes(instance.cluster, node_id=instance.id)
else:
instance.pending_role_list = (
db()
.query(models.Role)
.filter_by(release_id=instance.cluster.release_id)
.filter(models.Role.name.in_(new_pending_roles))
.all()
)
db().flush()
db().refresh(instance)
示例14: check_creds
def check_creds(updated_attrs, expected_creds):
Cluster.update_attributes(cluster, updated_attributes)
with patch(get_host_for_auth_path,
return_value=expected_auth_host):
client_provider = helpers.ClientProvider(cluster)
creds = client_provider.credentials
self.assertEqual(expected_creds, creds)
示例15: remove_tag
def remove_tag(cls, instance, tag_name):
from nailgun.objects import Cluster
cls.remove_tag_from_roles(instance, tag_name)
res = instance.tags_metadata.pop(tag_name, None)
for cluster in instance.clusters:
if tag_name not in cluster.tags_metadata:
Cluster.remove_tag_from_roles(cluster, tag_name)
Cluster.remove_primary_tag(cluster, tag_name)
return bool(res)