本文整理汇总了Python中devops.manager.Manager.network_create方法的典型用法代码示例。如果您正苦于以下问题:Python Manager.network_create方法的具体用法?Python Manager.network_create怎么用?Python Manager.network_create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类devops.manager.Manager
的用法示例。
在下文中一共展示了Manager.network_create方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: EnvironmentModel
# 需要导入模块: from devops.manager import Manager [as 别名]
# 或者: from devops.manager.Manager import network_create [as 别名]
#.........这里部分代码省略.........
cluster_id, self.get_host_node_ip(), port)
def bootstrap_nodes(self, devops_nodes, timeout=600):
"""Lists registered nailgun nodes
Start vms and wait until they are registered on nailgun.
:rtype : List of registered nailgun nodes
"""
for node in devops_nodes:
node.start()
wait(lambda: all(self.nailgun_nodes(devops_nodes)), 15, timeout)
for node in self.nailgun_nodes(devops_nodes):
self.sync_node_time(self.get_ssh_to_remote(node["ip"]))
return self.nailgun_nodes(devops_nodes)
def create_interfaces(self, networks, node,
model=settings.INTERFACE_MODEL):
for network in networks:
self.manager.interface_create(network, node=node, model=model)
def describe_environment(self):
"""Environment
:rtype : Environment
"""
environment = self.manager.environment_create(self.env_name)
networks = []
for name in settings.INTERFACE_ORDER:
ip_networks = [
IPNetwork(x) for x in settings.POOLS.get(name)[0].split(',')]
new_prefix = int(settings.POOLS.get(name)[1])
pool = self.manager.create_network_pool(networks=ip_networks,
prefix=int(new_prefix))
networks.append(self.manager.network_create(
name=name,
environment=environment,
pool=pool,
forward=settings.FORWARDING.get(name),
has_dhcp_server=settings.DHCP.get(name)))
for name in self.node_roles.admin_names:
self.describe_admin_node(name, networks)
for name in self.node_roles.other_names:
self.describe_empty_node(name, networks)
return environment
def devops_nodes_by_names(self, devops_node_names):
return map(
lambda name:
self.get_virtual_environment().node_by_name(name),
devops_node_names)
@logwrap
def describe_admin_node(self, name, networks):
node = self.add_node(
memory=settings.HARDWARE.get("admin_node_memory", 1024),
vcpu=settings.HARDWARE.get("admin_node_cpu", 1),
name=name,
boot=['hd', 'cdrom'])
self.create_interfaces(networks, node)
if self.os_image is None:
self.add_empty_volume(node, name + '-system')
self.add_empty_volume(
node,
name + '-iso',
示例2: EnvironmentModel
# 需要导入模块: from devops.manager import Manager [as 别名]
# 或者: from devops.manager.Manager import network_create [as 别名]
#.........这里部分代码省略.........
networks = []
interfaces = settings.INTERFACE_ORDER
if self.multiple_cluster_networks:
logger.info('Multiple cluster networks feature is enabled!')
if settings.BONDING:
interfaces = settings.BONDING_INTERFACES.keys()
for name in interfaces:
networks.append(self.create_networks(name, environment))
for name in self.node_roles.admin_names:
self.describe_admin_node(name, networks)
for name in self.node_roles.other_names:
if self.multiple_cluster_networks:
networks1 = [net for net in networks if net.name
in settings.NODEGROUPS[0]['pools']]
networks2 = [net for net in networks if net.name
in settings.NODEGROUPS[1]['pools']]
# If slave index is even number, then attach to
# it virtual networks from the second network group.
if int(name[-2:]) % 2 == 1:
self.describe_empty_node(name, networks1)
elif int(name[-2:]) % 2 == 0:
self.describe_empty_node(name, networks2)
else:
self.describe_empty_node(name, networks)
return environment
def create_networks(self, name, environment):
ip_networks = [
IPNetwork(x) for x in settings.POOLS.get(name)[0].split(',')]
new_prefix = int(settings.POOLS.get(name)[1])
pool = self.manager.create_network_pool(networks=ip_networks,
prefix=int(new_prefix))
return self.manager.network_create(
name=name,
environment=environment,
pool=pool,
forward=settings.FORWARDING.get(name),
has_dhcp_server=settings.DHCP.get(name))
def devops_nodes_by_names(self, devops_node_names):
return map(
lambda name:
self.get_virtual_environment().node_by_name(name),
devops_node_names)
@logwrap
def describe_admin_node(self, name, networks):
node = self.add_node(
memory=settings.HARDWARE.get("admin_node_memory", 1024),
vcpu=settings.HARDWARE.get("admin_node_cpu", 1),
name=name,
boot=['hd', 'cdrom'])
self.create_interfaces(networks, node)
if self.os_image is None:
self.add_empty_volume(node, name + '-system')
self.add_empty_volume(
node,
name + '-iso',
capacity=_get_file_size(settings.ISO_PATH),
format='raw',
device='cdrom',
bus='ide')
else:
volume = self.manager.volume_get_predefined(self.os_image)
示例3: EnvironmentModel
# 需要导入模块: from devops.manager import Manager [as 别名]
# 或者: from devops.manager.Manager import network_create [as 别名]
#.........这里部分代码省略.........
if settings.BONDING:
for network in networks:
self.manager.interface_create(
network, node=node, model=model,
interface_map=settings.BONDING_INTERFACES)
else:
for network in networks:
self.manager.interface_create(network, node=node, model=model)
def describe_environment(self):
"""Environment
:rtype : Environment
"""
environment = self.manager.environment_create(self.env_name)
networks = []
interfaces = settings.INTERFACE_ORDER
if settings.BONDING:
interfaces = settings.BONDING_INTERFACES.keys()
for name in interfaces:
networks.append(self.create_networks(name, environment))
for name in self.node_roles.admin_names:
self.describe_admin_node(name, networks)
for name in self.node_roles.other_names:
self.describe_empty_node(name, networks)
return environment
def create_networks(self, name, environment):
ip_networks = [
IPNetwork(x) for x in settings.POOLS.get(name)[0].split(',')]
new_prefix = int(settings.POOLS.get(name)[1])
pool = self.manager.create_network_pool(networks=ip_networks,
prefix=int(new_prefix))
return self.manager.network_create(
name=name,
environment=environment,
pool=pool,
forward=settings.FORWARDING.get(name),
has_dhcp_server=settings.DHCP.get(name))
def devops_nodes_by_names(self, devops_node_names):
return map(
lambda name:
self.get_virtual_environment().node_by_name(name),
devops_node_names)
@logwrap
def describe_admin_node(self, name, networks):
node = self.add_node(
memory=settings.HARDWARE.get("admin_node_memory", 1024),
vcpu=settings.HARDWARE.get("admin_node_cpu", 1),
name=name,
boot=['hd', 'cdrom'])
self.create_interfaces(networks, node)
if self.os_image is None:
self.add_empty_volume(node, name + '-system')
self.add_empty_volume(
node,
name + '-iso',
capacity=_get_file_size(settings.ISO_PATH),
format='raw',
device='cdrom',
bus='ide')
else:
volume = self.manager.volume_get_predefined(self.os_image)
示例4: EnvironmentModel
# 需要导入模块: from devops.manager import Manager [as 别名]
# 或者: from devops.manager.Manager import network_create [as 别名]
#.........这里部分代码省略.........
cluster_id, self.get_host_node_ip(), port)
def bootstrap_nodes(self, devops_nodes, timeout=600):
"""
Start vms and wait they are registered on nailgun.
:rtype : List of registered nailgun nodes
"""
for node in devops_nodes:
node.start()
wait(lambda: all(self.nailgun_nodes(devops_nodes)), 15, timeout)
for node in self.nailgun_nodes(devops_nodes):
self.sync_node_time(self.get_ssh_to_remote(node["ip"]))
return self.nailgun_nodes(devops_nodes)
def create_interfaces(self, networks, node,
model=settings.INTERFACE_MODEL):
for network in networks:
self.manager.interface_create(network, node=node, model=model)
def describe_environment(self):
"""
:rtype : Environment
"""
environment = self.manager.environment_create(self.env_name)
networks = []
for name in settings.INTERFACE_ORDER:
ip_networks = [
IPNetwork(x) for x in settings.POOLS.get(name)[0].split(',')]
new_prefix = int(settings.POOLS.get(name)[1])
pool = self.manager.create_network_pool(networks=ip_networks,
prefix=int(new_prefix))
networks.append(self.manager.network_create(
name=name,
environment=environment,
pool=pool,
forward=settings.FORWARDING.get(name),
has_dhcp_server=settings.DHCP.get(name)))
for name in self.node_roles.admin_names:
self.describe_admin_node(name, networks)
for name in self.node_roles.other_names:
self.describe_empty_node(name, networks)
return environment
def devops_nodes_by_names(self, devops_node_names):
return map(
lambda name:
self.get_virtual_environment().node_by_name(name),
devops_node_names)
@logwrap
def describe_admin_node(self, name, networks):
node = self.add_node(
memory=settings.HARDWARE.get("admin_node_memory", 1024),
vcpu=settings.HARDWARE.get("admin_node_cpu", 1),
name=name,
boot=['hd', 'cdrom'])
self.create_interfaces(networks, node)
self.add_empty_volume(node, name + '-system')
self.add_empty_volume(
node,
name + '-iso',
capacity=_get_file_size(settings.ISO_PATH),
format='raw',
示例5: __init__
# 需要导入模块: from devops.manager import Manager [as 别名]
# 或者: from devops.manager.Manager import network_create [as 别名]
class EnvManager:
"""
Class for create environment in puppet modules testing.
"""
env_name = os.environ.get("ENV_NAME", "puppet-integration")
env_node_name = "node"
env_net_public = NET_PUBLIC
env_net_internal = NET_INTERNAL
env_net_private = NET_PRIVATE
env_vol = "vol"
login = "root"
password = "r00tme"
def __init__(self, base_image=None):
"""
Constructor for create environment.
"""
self.manager = Manager()
self.base_image = base_image or BASE_IMAGE
self.environment = self.create_env()
def create_env(self):
try:
return self.manager.environment_get(self.env_name)
except:
return self._define_env()
def _define_env(self):
"""
Create environment with default settings.
"""
self.environment = self.manager.environment_create(self.env_name)
internal = self.manager.network_create(environment=self.environment, name=self.env_net_internal, pool=None)
external = self.manager.network_create(environment=self.environment, name=self.env_net_public, pool=None)
private = self.manager.network_create(environment=self.environment, name=self.env_net_private, pool=None)
node = self.manager.node_create(name=self.env_node_name, environment=self.environment)
self.manager.interface_create(node=node, network=internal)
self.manager.interface_create(node=node, network=external)
self.manager.interface_create(node=node, network=private)
volume = self.manager.volume_get_predefined(self.base_image)
v3 = self.manager.volume_create_child(self.env_vol, backing_store=volume, environment=self.environment)
self.manager.node_attach_volume(node=node, volume=v3)
self.environment.define()
self.environment.start()
return self.environment
def _get_public_ip(self):
return self.environment.node_by_name(self.env_node_name).get_ip_address_by_network_name(self.env_net_public)
def _ssh(self):
return ssh(self._get_public_ip(), username=self.login, password=self.password).sudo.ssh
def remote(self):
"""
Return remote access to node by name with default login/password.
"""
return self._ssh()
def snapshot_exist(self, snap_name="before_test"):
return self.environment.has_snapshot(name=snap_name)
def create_snapshot_env(self, snap_name="", description="", force=True):
"""
Create snapshot for environment.
"""
self.environment.snapshot(name=snap_name, description=description, force=force)
def revert_snapshot_env(self, snap_name="", destroy=True):
"""
Revert environment to snapshot by name.
"""
self.environment.revert(name=snap_name, destroy=destroy)
def erase_env(self):
"""
Erase environment.
"""
self.environment.erase()
def execute_cmd(self, command, debug=True):
"""
Execute command on node.
"""
return self.remote().execute(command, verbose=debug)["exit_code"]
def upload_files(self, source, dest):
"""
Upload file(s) to node.
"""
self.remote().upload(source, dest)
#.........这里部分代码省略.........
示例6: EnvironmentModel
# 需要导入模块: from devops.manager import Manager [as 别名]
# 或者: from devops.manager.Manager import network_create [as 别名]
class EnvironmentModel(object):
hostname = "nailgun"
domain = "test.domain.local"
installation_timeout = 1800
deployment_timeout = 1800
puppet_timeout = 1000
nat_interface = "" # INTERFACES.get('admin')
admin_net = "admin"
def __init__(self):
self._virtual_environment = None
self._keys = None
self.manager = Manager()
self._fuel_web = FuelWebClient(self.get_admin_node_ip(), self)
def _get_or_create(self):
try:
return self.manager.environment_get(self.env_name)
except:
self._virtual_environment = self.describe_environment()
self._virtual_environment.define()
return self._virtual_environment
def router(self, router_name=None):
router_name = router_name or self.admin_net
return str(IPNetwork(self.get_virtual_environment().network_by_name(router_name).ip_network)[1])
@property
def fuel_web(self):
"""
:rtype: FuelWebClient
"""
return self._fuel_web
@property
def node_roles(self):
return NodeRoles(admin_names=["admin"], other_names=["slave-%02d" % x for x in range(1, 10)])
@property
def env_name(self):
return ENV_NAME
def add_empty_volume(
self, node, name, capacity=NODE_VOLUME_SIZE * 1024 * 1024 * 1024, device="disk", bus="virtio", format="qcow2"
):
self.manager.node_attach_volume(
node=node,
volume=self.manager.volume_create(
name=name, capacity=capacity, environment=self.get_virtual_environment(), format=format
),
device=device,
bus=bus,
)
def add_node(self, memory, name, vcpu=1, boot=None):
return self.manager.node_create(
name=name, memory=memory, vcpu=vcpu, environment=self.get_virtual_environment(), boot=boot
)
@logwrap
def add_syslog_server(self, cluster_id, port=5514):
self.fuel_web.add_syslog_server(cluster_id, self.get_host_node_ip(), port)
def bootstrap_nodes(self, devops_nodes, timeout=600):
"""
Start vms and wait they are registered on nailgun.
:rtype : List of registered nailgun nodes
"""
for node in devops_nodes:
node.start()
wait(lambda: all(self.nailgun_nodes(devops_nodes)), 15, timeout)
for node in self.nailgun_nodes(devops_nodes):
self.sync_node_time(self.get_ssh_to_remote(node["ip"]))
return self.nailgun_nodes(devops_nodes)
def create_interfaces(self, networks, node, model=INTERFACE_MODEL):
for network in networks:
self.manager.interface_create(network, node=node, model=model)
def describe_environment(self):
"""
:rtype : Environment
"""
environment = self.manager.environment_create(self.env_name)
networks = []
for name in INTERFACE_ORDER:
ip_networks = [IPNetwork(x) for x in POOLS.get(name)[0].split(",")]
new_prefix = int(POOLS.get(name)[1])
pool = self.manager.create_network_pool(networks=ip_networks, prefix=int(new_prefix))
networks.append(
self.manager.network_create(
name=name,
environment=environment,
pool=pool,
forward=FORWARDING.get(name),
has_dhcp_server=DHCP.get(name),
)
)
#.........这里部分代码省略.........
示例7: Environment
# 需要导入模块: from devops.manager import Manager [as 别名]
# 或者: from devops.manager.Manager import network_create [as 别名]
class Environment(object):
capacity = 20 * 1024 * 1024 * 1024
boot = ['hd', 'cdrom']
login = "root"
password = "r00tme"
name = 'fuel'
def __init__(self, name=name, base_image=None):
self.manager = Manager()
self.name = name
self.base_image = base_image
self.environment = self._get_or_create()
def _get_or_create(self):
try:
return self.manager.environment_get(self.name)
except:
self.environment = self._create()
self.environment.define()
return self.environment
def nodes(self):
return Nodes(self.environment, self._node_roles())
def get_empty_state(self):
if self.environment.has_snapshot(EMPTY_SNAPSHOT):
self.environment.revert(EMPTY_SNAPSHOT)
return True
return None
def get_env(self):
return self.environment
def add_empty_volume(self, node, name, capacity=capacity, device='disk', bus='virtio', format='qcow2'):
self.manager.node_attach_volume(node=node,
volume=self.manager.volume_create(name=name,
capacity=capacity,
environment=self.environment,
format=format),
device=device,
bus=bus)
def add_node(self, name, memory, boot=None):
return self.manager.node_create(name=name,
memory=memory,
environment=self.environment,
boot=boot)
def create_interfaces(self, node, networks):
for network in networks:
self.manager.interface_create(network, node=node)
def describe_admin_node(self, name, networks, memory=DEFAULT_RAM_SIZE, boot=boot):
node = self.add_node(memory=memory, name=name, boot=boot)
self.create_interfaces(node, networks)
if self.base_image is None:
self.add_empty_volume(node, name + '-system')
self.add_empty_volume(node, name + '-iso', capacity=_get_file_size(ISO_PATH), format='raw', device='cdrom', bus='ide')
else:
volume = self.manager.volume_get_predefined(self.base_image)
v = self.manager.volume_create_child(name + '-system', backing_store=volume, environment=self.environment)
self.manager.node_attach_volume(node=node, volume=v)
return node
def describe_node(self, name, networks, memory=DEFAULT_RAM_SIZE):
node = self.add_node(name, memory)
self.create_interfaces(node, networks)
self.add_empty_volume(node, name + '-system')
# self.add_empty_volume(node, name + '-cinder')
#self.add_empty_volume(node, name + '-swift')
return node
def _node_roles(self):
controllers = ['fuel-controller-%02d' % x for x in range(1, 1 + COUNT_NODES[DEPLOYMENT_MODE]['CONTROLLERS'])]
computes = ['fuel-compute-%02d' % x for x in range(1, 1 + COUNT_NODES[DEPLOYMENT_MODE]['COMPUTES'])]
storages = ['fuel-swift-%02d' % x for x in range(1, 1 + COUNT_NODES[DEPLOYMENT_MODE]['STORAGES'])]
proxies = ['fuel-swift-proxy-%02d' % x for x in range(1, 1 + COUNT_NODES[DEPLOYMENT_MODE]['PROXIES'])]
quantums = ['fuel-quantum-%02d' % x for x in range(1, 1 + COUNT_NODES[DEPLOYMENT_MODE]['QUANTUMS'])]
return NodeRoles(admin_names=['master'],
other_names=controllers + computes + storages + proxies + quantums
)
def _create(self):
self.environment = self.manager.environment_create(self.name)
networks = []
for name in INTERFACE_ORDER:
ip_networks = [IPNetwork(x) for x in POOLS.get(name)[0].split(',')]
new_prefix = int(POOLS.get(name)[1])
pool = self.manager.create_network_pool(networks=ip_networks, prefix=int(new_prefix))
networks.append(self.manager.network_create(name=name,
environment=self.environment,
pool=pool,
forward=FORWARDING.get(name),
has_dhcp_server=DHCP.get(name)))
#.........这里部分代码省略.........