本文整理汇总了Python中nailgun.objects.Node类的典型用法代码示例。如果您正苦于以下问题:Python Node类的具体用法?Python Node怎么用?Python Node使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Node类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: serialize
def serialize(cls, instance, fields=None):
from nailgun.objects import Node
data_dict = super(NodeSerializer, cls).serialize(instance, fields)
data_dict['fqdn'] = Node.get_node_fqdn(instance)
data_dict['status'] = Node.get_status(instance)
data_dict['tags'] = instance.tag_names
return data_dict
示例2: generate_network_scheme
def generate_network_scheme(cls, node, networks):
attrs = super(NeutronNetworkDeploymentSerializer60, cls).generate_network_scheme(node, networks)
for item in attrs.get("transformations", ()):
if "tags" in item:
item["vlan_ids"] = item["tags"]
# Include information about all subnets that don't belong to this node.
# This is used during deployment to configure routes to all other
# networks in the environment.
nm = Cluster.get_network_manager(node.cluster)
other_nets = nm.get_networks_not_on_node(node, networks)
netgroup_mapping = [("storage", "br-storage"), ("management", "br-mgmt"), ("fuelweb_admin", "br-fw-admin")]
if Node.should_have_public(node):
netgroup_mapping.append(("public", "br-ex"))
for ngname, brname in netgroup_mapping:
netgroup = nm.get_network_by_netname(ngname, networks)
if netgroup.get("gateway"):
attrs["endpoints"][brname]["gateway"] = netgroup["gateway"]
attrs["endpoints"][brname]["other_nets"] = other_nets.get(ngname, [])
if Node.should_have_public(node):
attrs["endpoints"]["br-ex"]["default_gateway"] = True
else:
gw = nm.get_default_gateway(node.id)
attrs["endpoints"]["br-fw-admin"]["gateway"] = gw
attrs["endpoints"]["br-fw-admin"]["default_gateway"] = True
return attrs
示例3: generate_network_metadata
def generate_network_metadata(cls, cluster):
nodes = dict()
nm = Cluster.get_network_manager(cluster)
for n in Cluster.get_nodes_not_for_deletion(cluster):
name = Node.get_slave_name(n)
node_roles = Node.all_roles(n)
ip_by_net = {"fuelweb_admin": None, "storage": None, "management": None, "public": None}
for net in ip_by_net:
netgroup = nm.get_node_network_by_netname(n, net)
if netgroup.get("ip"):
ip_by_net[net] = netgroup["ip"].split("/")[0]
netw_roles = {
"admin/pxe": ip_by_net["fuelweb_admin"],
"fw-admin": ip_by_net["fuelweb_admin"],
"keystone/api": ip_by_net["management"],
"swift/api": ip_by_net["management"],
"sahara/api": ip_by_net["management"],
"ceilometer/api": ip_by_net["management"],
"cinder/api": ip_by_net["management"],
"glance/api": ip_by_net["management"],
"heat/api": ip_by_net["management"],
"nova/api": ip_by_net["management"],
"murano/api": ip_by_net["management"],
"horizon": ip_by_net["management"],
"management": ip_by_net["management"],
"mgmt/api": ip_by_net["management"],
"mgmt/database": ip_by_net["management"],
"mgmt/messaging": ip_by_net["management"],
"mgmt/corosync": ip_by_net["management"],
"mgmt/memcache": ip_by_net["management"],
"mgmt/vip": ip_by_net["management"],
"mongo/db": ip_by_net["management"],
"ceph/public": ip_by_net["management"],
"storage": ip_by_net["storage"],
"ceph/replication": ip_by_net["storage"],
"swift/replication": ip_by_net["storage"],
"cinder/iscsi": ip_by_net["storage"],
"ex": ip_by_net["public"],
"public/vip": ip_by_net["public"],
"ceph/radosgw": ip_by_net["public"],
}
nodes[name] = {
"uid": n.uid,
"fqdn": n.fqdn,
"name": name,
"user_node_name": n.name,
"swift_zone": n.uid,
"node_roles": node_roles,
"network_roles": netw_roles,
}
return dict(nodes=nodes, vips=nm.assign_vips_for_net_groups(cluster))
示例4: create_node
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
示例5: set_default_node_volumes
def set_default_node_volumes(cls, node):
from .objects.volumes import VolumeObject
try:
VolumeObject.set_default_node_volumes(node)
except Exception as exc:
logger.exception(exc)
msg = "Failed to generate volumes for node '{0}': '{1}'".format(
node.human_readable_name, six.text_type(exc)
)
Notification.create({"topic": "error", "message": msg, "node_id": node.id})
if node.cluster_id:
Node.add_pending_change(node, "disks")
示例6: 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 = 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
示例7: update_nodes
def update_nodes(cls, instance, nodes_ids):
"""Update Cluster nodes by specified node IDs
Nodes with specified IDs will replace existing ones in Cluster
:param instance: Cluster instance
:param nodes_ids: list of nodes ids
:returns: None
"""
# TODO(NAME): sepatate nodes
# for deletion and addition by set().
new_nodes = []
if nodes_ids:
new_nodes = db().query(models.Node).filter(
models.Node.id.in_(nodes_ids)
)
nodes_to_remove = [n for n in instance.nodes
if n not in new_nodes]
nodes_to_add = [n for n in new_nodes
if n not in instance.nodes]
for node in nodes_to_add:
if not node.online:
raise errors.NodeOffline(
u"Cannot add offline node "
u"'{0}' to environment".format(node.id)
)
# we should reset hostname to default value to guarantee
# hostnames uniqueness for nodes outside clusters
from nailgun.objects import Node
for node in nodes_to_remove:
node.hostname = Node.default_slave_name(node)
map(instance.nodes.remove, nodes_to_remove)
map(instance.nodes.append, nodes_to_add)
net_manager = cls.get_network_manager(instance)
map(
net_manager.clear_assigned_networks,
nodes_to_remove
)
map(
net_manager.clear_bond_configuration,
nodes_to_remove
)
cls.replace_provisioning_info_on_nodes(instance, [], nodes_to_remove)
cls.replace_deployment_info_on_nodes(instance, [], nodes_to_remove)
from nailgun.objects import NodeCollection
NodeCollection.reset_network_template(nodes_to_remove)
map(
net_manager.assign_networks_by_default,
nodes_to_add
)
cls.update_nodes_network_template(instance, nodes_to_add)
db().flush()
示例8: get_dpdk_driver
def get_dpdk_driver(cls, instance, dpdk_drivers):
from nailgun.objects import Node
pci_id = instance.meta.get('pci_id', '').lower()
sriov_enabled = Node.sriov_enabled(instance.node)
for driver, device_ids in six.iteritems(dpdk_drivers):
if pci_id in device_ids:
if sriov_enabled:
return consts.DPDK_DRIVER_IN_SRIOV_CASE
return driver
return None
示例9: generate_network_metadata
def generate_network_metadata(cls, cluster):
nodes = dict()
nm = Cluster.get_network_manager(cluster)
for node in Cluster.get_nodes_not_for_deletion(cluster):
name = Node.get_slave_name(node)
node_roles = Node.all_roles(node)
network_roles = cls.get_network_role_mapping_to_ip(node)
nodes[name] = {
"uid": node.uid,
"fqdn": Node.get_node_fqdn(node),
"name": name,
"user_node_name": node.name,
"swift_zone": node.uid,
"node_roles": node_roles,
"network_roles": network_roles,
}
return dict(nodes=nodes, vips=nm.assign_vips_for_net_groups(cluster))
示例10: generate_network_metadata
def generate_network_metadata(cls, cluster):
metadata = super(NeutronNetworkTemplateSerializer70,
cls).generate_network_metadata(cluster)
for node_data in metadata['nodes'].values():
node = Node.get_by_uid(node_data['uid'])
network_roles = cls._get_network_roles(node)
ip_per_ep = cls._get_endpoint_to_ip_mapping(node)
node_data['network_roles'] = {}
for role, ep in network_roles.items():
node_data['network_roles'][role] = ip_per_ep.get(ep)
return metadata
示例11: add_vlan_interfaces
def add_vlan_interfaces(cls, node):
"""Assign fixed_interfaces and vlan_interface.
They should be equal.
"""
net_manager = Node.get_network_manager(node)
fixed_interface = net_manager._get_interface_by_network_name(
node.id, 'fixed')
attrs = {'fixed_interface': fixed_interface.name,
'vlan_interface': fixed_interface.name}
return attrs
示例12: get_default_network_to_endpoint_mapping
def get_default_network_to_endpoint_mapping(cls, node):
mapping = {
consts.NETWORKS.fuelweb_admin: 'br-fw-admin',
consts.NETWORKS.storage: 'br-storage',
consts.NETWORKS.management: 'br-mgmt',
consts.NETWORKS.private: 'br-prv'}
if Node.should_have_public(node):
mapping[consts.NETWORKS.public] = 'br-ex'
return mapping
示例13: get_default_network_to_endpoint_mapping
def get_default_network_to_endpoint_mapping(cls, node):
mapping = {
consts.NETWORKS.fuelweb_admin: 'br-fw-admin',
consts.NETWORKS.storage: 'br-storage',
consts.NETWORKS.management: 'br-mgmt',
consts.NETWORKS.private: 'br-prv'}
# roles can be assigned to br-ex only in case it has a public IP
if Node.should_have_public_with_ip(node):
mapping[consts.NETWORKS.public] = 'br-ex'
return mapping
示例14: update_nodes_net_info
def update_nodes_net_info(cls, cluster, nodes):
"""Adds information about networks to each node."""
for node in Cluster.get_nodes_not_for_deletion(cluster):
netw_data = node.network_data
addresses = {}
for net in node.cluster.network_groups:
if net.name == "public" and not Node.should_have_public(node):
continue
if net.meta.get("render_addr_mask"):
addresses.update(cls.get_addr_mask(netw_data, net.name, net.meta.get("render_addr_mask")))
[n.update(addresses) for n in nodes if n["uid"] == str(node.uid)]
return nodes
示例15: get_admin_ip_w_prefix
def get_admin_ip_w_prefix(node):
"""Getting admin ip and assign prefix from admin network."""
network_manager = Node.get_network_manager(node)
admin_ip = network_manager.get_admin_ip_for_node(node.id)
admin_ip = IPNetwork(admin_ip)
# Assign prefix from admin network
admin_net = IPNetwork(
network_manager.get_admin_network_group(node.id).cidr
)
admin_ip.prefixlen = admin_net.prefixlen
return str(admin_ip)