本文整理汇总了Python中devops.manager.Manager类的典型用法代码示例。如果您正苦于以下问题:Python Manager类的具体用法?Python Manager怎么用?Python Manager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Manager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
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()
示例2: CiBase
class CiBase(object):
def __init__(self):
self._environment = None
self.manager = Manager()
# self.base_image = self.manager.volume_get_predefined(BASE_IMAGE)
def get_or_create(self):
try:
return self.manager.environment_get(self.env_name())
except:
self._environment = self.describe_environment()
self._environment.define()
return self._environment
def get_empty_state(self):
if self.environment().has_snapshot(EMPTY_SNAPSHOT):
self.environment().revert(EMPTY_SNAPSHOT)
else:
self.setup_environment()
def environment(self):
"""
:rtype : devops.models.Environment
"""
self._environment = self._environment or self.get_or_create()
return self._environment
@abstractproperty
def env_name(self):
"""
:rtype : string
"""
pass
@abstractmethod
def define(self):
"""
:rtype : devops.models.Environment
"""
pass
@abstractmethod
def describe_environment(self):
"""
:rtype : devops.models.Environment
"""
pass
@abstractproperty
def node_roles(self):
"""
:rtype : NodeRoles
"""
pass
def add_empty_volume(self, node, name, capacity=20 * 1024 * 1024 * 1024, format="qcow2", device="disk", bus='virtio'):
self.manager.node_attach_volume(
node=node,
device=device,
bus=bus,
volume=self.manager.volume_create(
name=name, capacity=capacity, format=format,
environment=self.environment()))
def add_node(self, memory, name, boot=None):
return self.manager.node_create(
name=name,
memory=memory,
environment=self.environment())
def describe_master_node(self, name, networks, memory=1024):
node = self.add_node(memory, name, boot=['cdrom', 'hd'])
for network in networks:
self.manager.interface_create(network, node=node)
self.add_empty_volume(node, name + '-system')
self.add_empty_volume(node, name + '-iso', capacity=_get_file_size(ISO_IMAGE), format='raw', device='cdrom', bus='ide')
return node
def describe_empty_node(self, name, networks, memory=1024):
node = self.add_node(memory, name)
for network in networks:
self.manager.interface_create(network, node=node)
self.add_empty_volume(node, name + '-system')
self.add_empty_volume(node, name + '-cinder')
return node
def nodes(self):
return Nodes(self.environment(), self.node_roles())
def add_nodes_to_hosts(self, remote, nodes):
for node in nodes:
add_to_hosts(remote,
node.get_ip_address_by_network_name('internal'), node.name,
node.name + '.localdomain')
def setup_master_node(self, master_remote, nodes):
setup_puppet_master(master_remote)
add_nmap(master_remote)
switch_off_ip_tables(master_remote)
self.add_nodes_to_hosts(master_remote, nodes)
#.........这里部分代码省略.........
示例3: CiBase
class CiBase(object):
def __init__(self):
self.manager = Manager()
self._environment = None
def _get_or_create(self):
try:
return self.manager.environment_get(self.env_name())
except:
self._environment = self.describe_environment()
self._environment.define()
return self._environment
def get_empty_state(self):
return self.get_state(EMPTY_SNAPSHOT)
def get_state(self, name):
if self.environment().has_snapshot(name):
self.environment().revert(name)
return True
return False
def environment(self):
"""
:rtype : devops.models.Environment
"""
self._environment = self._environment or self._get_or_create()
return self._environment
@abstractproperty
def env_name(self):
"""
:rtype : string
"""
pass
@abstractmethod
def describe_environment(self):
"""
:rtype : devops.models.Environment
"""
pass
@abstractproperty
def node_roles(self):
"""
:rtype : NodeRoles
"""
pass
def nodes(self):
return Nodes(self.environment(), self.node_roles())
# noinspection PyShadowingBuiltins
def add_empty_volume(self, node, name, capacity=20 * 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.environment(),
format=format),
device=device, bus=bus)
def add_node(self, memory, name, boot=None):
return self.manager.node_create(
name=name,
memory=memory,
environment=self.environment(),
boot=boot)
def create_interfaces(self, networks, node):
for network in networks:
if network.name == 'internal':
self.manager.interface_create(network, node=node)
self.manager.interface_create(network, node=node)
self.manager.interface_create(network, node=node)
def describe_admin_node(self, name, networks, memory=1024):
node = self.add_node(memory=memory, 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(ISO_PATH),
format='raw', device='cdrom', bus='ide')
return node
def describe_empty_node(self, name, networks, memory=1024):
node = self.add_node(memory, name)
self.create_interfaces(networks, node)
self.add_empty_volume(node, name + '-system')
self.add_empty_volume(node, name + '-cinder')
self.add_empty_volume(node, name + '-swift')
return node
@abstractmethod
def setup_environment(self):
"""
:rtype : None
"""
#.........这里部分代码省略.........
示例4: Shell
class Shell(object):
def __init__(self):
super(Shell, self).__init__()
self.params = self.get_params()
self.manager = Manager()
def execute(self):
self.commands.get(self.params.command)(self)
def do_list(self):
env_list = self.manager.environment_list().values('name')
for env in env_list:
print(env['name'])
return env_list
def node_dict(self, node):
return {'name': node.name,
'vnc': node.get_vnc_port()}
def do_show(self):
environment = self.manager.environment_get(self.params.name)
print('%5s %25s' % ("VNC", "NODE-NAME"))
for item in map(lambda x: self.node_dict(x), environment.nodes):
print ('%5s %25s' % (item['vnc'], item['name']))
def do_erase(self):
self.manager.environment_get(self.params.name).erase()
def do_start(self):
self.manager.environment_get(self.params.name).start()
def do_destroy(self):
self.manager.environment_get(self.params.name).destroy(verbose=False)
def do_suspend(self):
self.manager.environment_get(self.params.name).suspend(verbose=False)
def do_resume(self):
self.manager.environment_get(self.params.name).resume(verbose=False)
def do_revert(self):
self.manager.environment_get(self.params.name).revert(
self.params.snapshot_name)
def do_snapshot(self):
self.manager.environment_get(self.params.name).snapshot(
self.params.snapshot_name)
def do_synchronize(self):
self.manager.synchronize_environments()
def do_snapshot_list(self):
environment = self.manager.environment_get(self.params.name)
snap_nodes = {}
max_len = 0
for node in environment.nodes:
snaps = sorted(node.get_snapshots())
for snap in snaps:
if len(snap) > max_len:
max_len = len(snap)
if snap in snap_nodes:
snap_nodes[snap].append(node.name)
else:
snap_nodes[snap] = [node.name, ]
print("%*s %50s" % (max_len, "SNAPSHOT", "NODES-NAME"))
for snap in snap_nodes:
print("%*s %50s" % (max_len, snap,
', '.join(snap_nodes[snap])))
def do_snapshot_delete(self):
environment = self.manager.environment_get(self.params.name)
for node in environment.nodes:
snaps = sorted(node.get_snapshots())
if self.params.snapshot_name in snaps:
node.erase_snapshot(name=self.params.snapshot_name)
def do_net_list(self):
environment = self.manager.environment_get(self.params.name)
networks = environment.networks
print("%15s %10s" % ("NETWORK NAME", "IP NET"))
for network in networks:
print("%15s %10s" % (network.name, network.ip_network))
def do_timesync(self):
env = self.manager.environment_get(self.params.name)
if not self.params.node_name:
_nodes = {node.name: node.get_vnc_port() for node in env.nodes}
for node_name in sorted(_nodes.keys()):
if _nodes[node_name] != '-1':
sync_node_time(env, node_name)
else:
sync_node_time(env, self.params.node_name)
def do_revert_resume(self):
self.manager.environment_get(self.params.name).revert(
self.params.snapshot_name)
#.........这里部分代码省略.........
示例5: __init__
def __init__(self):
self.manager = Manager()
self.base_image = self.manager.volume_get_predefined(BASE_IMAGE)
self._environment = None
示例6: EnvironmentModel
class EnvironmentModel(object):
hostname = 'nailgun'
domain = 'test.domain.local'
installation_timeout = 1800
deployment_timeout = 1800
puppet_timeout = 2000
nat_interface = '' # INTERFACES.get('admin')
admin_net = 'admin'
admin_net2 = 'admin2'
multiple_cluster_networks = settings.MULTIPLE_NETWORKS
def __init__(self, os_image=None):
self._virtual_environment = None
self._keys = None
self.manager = Manager()
self.os_image = os_image
self._fuel_web = FuelWebClient(self.get_admin_node_ip(), self)
@property
def nailgun_actions(self):
return FuelActions.Nailgun(self.get_admin_remote())
@property
def postgres_actions(self):
return FuelActions.Postgres(self.get_admin_remote())
def _get_or_create(self):
try:
return self.manager.environment_get(self.env_name)
except Exception:
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
if router_name == self.admin_net2:
return str(IPNetwork(self.get_virtual_environment().
network_by_name(router_name).ip_network)[2])
return str(
IPNetwork(
self.get_virtual_environment().network_by_name(router_name).
ip_network)[1])
@property
def fuel_web(self):
"""FuelWebClient
:rtype: FuelWebClient
"""
return self._fuel_web
@property
def admin_node_ip(self):
return self.fuel_web.admin_node_ip
@property
def node_roles(self):
return NodeRoles(
admin_names=['admin'],
other_names=['slave-%02d' % x for x in range(1, int(
settings.NODES_COUNT))]
)
@property
def env_name(self):
return settings.ENV_NAME
def add_empty_volume(self, node, name,
capacity=settings.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):
"""Lists registered nailgun nodes
Start vms and wait until they are registered on nailgun.
:rtype : List of registered nailgun nodes
"""
# self.dhcrelay_check()
#.........这里部分代码省略.........
示例7: CiBase
class CiBase(object):
"""
Base class for creating environment -- deploy openstack in various mode.
"""
def __init__(self):
"""
Constructor. Define environment and manager for manipulation with it.
"""
self._environment = None
self.manager = Manager()
def get_or_create(self):
"""
Get prepared environment or create it.
"""
try:
return self.manager.environment_get(self.env_name())
except:
self._environment = self.describe_environment()
self._environment.define()
return self._environment
def get_empty_state(self):
"""
Get 'empty' snapshot for virtual machines.
"""
if self.environment().has_snapshot(EMPTY_SNAPSHOT):
self.environment().revert(EMPTY_SNAPSHOT)
else:
self.setup_environment()
def environment(self):
"""
:rtype : devops.models.Environment
"""
self._environment = self._environment or self.get_or_create()
return self._environment
@abstractproperty
def env_name(self):
"""
:rtype : string
"""
pass
@abstractmethod
def define(self):
"""
:rtype : devops.models.Environment
"""
pass
@abstractmethod
def describe_environment(self):
"""
:rtype : devops.models.Environment
"""
pass
@abstractproperty
def node_roles(self):
"""
:rtype : NodeRoles
"""
pass
def add_empty_volume(self, node, name, capacity=20 * 1024 * 1024 * 1024, format="qcow2", device="disk", bus='virtio'):
"""
Attach a empty volume to virtual machine.
"""
self.manager.node_attach_volume(node=node,
device=device,
bus=bus,
volume=self.manager.volume_create(
name=name,
capacity=capacity,
format=format,
environment=self.environment()))
def add_node(self, memory, name, boot=None):
"""
Create a virtual machine in environment.
"""
return self.manager.node_create(name=name,
memory=memory,
environment=self.environment())
def describe_master_node(self, name, networks, memory=DEFAULT_RAM_SIZE):
"""
Define master node.
"""
node = self.add_node(memory, name, boot=['cdrom', 'hd'])
for network in networks:
self.manager.interface_create(network, node=node)
self.add_empty_volume(node, name + '-system')
self.add_empty_volume(node, name + '-iso', capacity=_get_file_size(ISO_IMAGE), format='raw', device='cdrom', bus='ide')
return node
def describe_empty_node(self, name, networks, memory=DEFAULT_RAM_SIZE):
"""
#.........这里部分代码省略.........
示例8: Shell
class Shell(object):
def __init__(self):
super(Shell, self).__init__()
self.params = self.get_params()
self.manager = Manager()
def execute(self):
self.commands.get(self.params.command)(self)
def do_list(self):
env_list = self.manager.environment_list().values('name')
for env in env_list:
print env['name']
return env_list
def node_dict(self, node):
return {'name': node.name,
'vnc': node.get_vnc_port()}
def do_show(self):
environment = self.manager.environment_get(self.params.name)
print '%5s %25s' % ("VNC", "NODE-NAME")
for item in map(lambda x: self.node_dict(x), environment.nodes):
print '%5s %25s' % (item['vnc'], item['name'])
def do_erase(self):
self.manager.environment_get(self.params.name).erase()
def do_start(self):
self.manager.environment_get(self.params.name).start()
def do_destroy(self):
self.manager.environment_get(self.params.name).destroy(verbose=False)
def do_suspend(self):
self.manager.environment_get(self.params.name).suspend(verbose=False)
def do_resume(self):
self.manager.environment_get(self.params.name).resume(verbose=False)
def do_revert(self):
self.manager.environment_get(self.params.name).revert(
self.params.snapshot_name)
def do_snapshot(self):
self.manager.environment_get(self.params.name).snapshot(
self.params.snapshot_name)
def do_synchronize(self):
self.manager.synchronize_environments()
commands = {
'list': do_list,
'show': do_show,
'erase': do_erase,
'start': do_start,
'destroy': do_destroy,
'suspend': do_suspend,
'resume': do_resume,
'revert': do_revert,
'snapshot': do_snapshot,
'sync': do_synchronize
}
def get_params(self):
name_parser = argparse.ArgumentParser(add_help=False)
name_parser.add_argument('name', help='environment name',
default=environ.get('ENV_NAME'))
snapshot_name_parser = argparse.ArgumentParser(add_help=False)
snapshot_name_parser.add_argument('--snapshot-name',
help='snapshot name',
default=environ.get('SNAPSHOT_NAME'))
parser = argparse.ArgumentParser(
description="Manage virtual environments")
subparsers = parser.add_subparsers(help='commands', dest='command')
subparsers.add_parser('list')
subparsers.add_parser('show', parents=[name_parser])
subparsers.add_parser('erase', parents=[name_parser])
subparsers.add_parser('start', parents=[name_parser])
subparsers.add_parser('destroy', parents=[name_parser])
subparsers.add_parser('suspend', parents=[name_parser])
subparsers.add_parser('resume', parents=[name_parser])
subparsers.add_parser('revert',
parents=[name_parser, snapshot_name_parser])
subparsers.add_parser('snapshot',
parents=[name_parser, snapshot_name_parser])
subparsers.add_parser('sync')
return parser.parse_args()
示例9: EnvironmentModel
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, int(
settings.NODES_COUNT))]
)
@property
def env_name(self):
return settings.ENV_NAME
def add_empty_volume(self, node, name,
capacity=settings.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=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 = []
#.........这里部分代码省略.........
示例10: CiBase
class CiBase(object):
def __init__(self):
self.manager = Manager()
self._environment = None
self.saved_environment_states = {}
def _get_or_create(self):
try:
return self.manager.environment_get(self.env_name())
except:
self._environment = self.describe_environment()
self._environment.define()
return self._environment
def get_state(self, name):
if self.environment().has_snapshot(name):
self.environment().revert(name)
return True
return False
def environment(self):
"""
:rtype : devops.models.Environment
"""
self._environment = self._environment or self._get_or_create()
return self._environment
@abstractproperty
def env_name(self):
"""
:rtype : string
"""
pass
@abstractmethod
def describe_environment(self):
"""
:rtype : devops.models.Environment
"""
pass
@abstractproperty
def node_roles(self):
"""
:rtype : NodeRoles
"""
pass
def nodes(self):
return Nodes(self.environment(), self.node_roles())
# noinspection PyShadowingBuiltins
def add_empty_volume(
self, node, name, capacity=20 * 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.environment(), format=format
),
device=device,
bus=bus,
)
def add_node(self, memory, name, boot=None):
return self.manager.node_create(name=name, memory=memory, environment=self.environment(), boot=boot)
def create_interfaces(self, networks, node):
for network in networks:
self.manager.interface_create(network, node=node)
def describe_admin_node(self, name, networks, memory=1024):
node = self.add_node(memory=memory, 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(ISO_PATH), format="raw", device="cdrom", bus="ide"
)
return node
def describe_empty_node(self, name, networks, memory=1024):
node = self.add_node(memory, name)
self.create_interfaces(networks, node)
self.add_empty_volume(node, name + "-system")
if USE_ALL_DISKS:
self.add_empty_volume(node, name + "-cinder")
self.add_empty_volume(node, name + "-swift")
return node
@abstractmethod
def setup_environment(self):
"""
:rtype : None
"""
pass
def get_empty_environment(self):
if not (self.get_state(EMPTY_SNAPSHOT)):
#.........这里部分代码省略.........
示例11: EnvironmentModel
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),
)
)
#.........这里部分代码省略.........
示例12: __init__
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()
示例13: Environment
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)))
#.........这里部分代码省略.........
示例14: __init__
def __init__(self):
self._environment = None
self.manager = Manager()
示例15: Shell
class Shell(object):
def __init__(self):
super(Shell, self).__init__()
self.params = self.get_params()
self.manager = Manager()
def execute(self):
self.commands.get(self.params.command)(self)
def do_list(self):
print self.manager.environment_list().values('name')
def node_dict(self, node):
return {'name': node.name,
'vnc': node.get_vnc_port(),
}
def do_show(self):
environment = self.manager.environment_get(self.params.name)
print {
'name': environment.name,
'nodes': map(lambda x: {'node': self.node_dict(x)},
environment.nodes)
}
def do_erase(self):
self.manager.environment_get(self.params.name).erase()
def do_start(self):
self.manager.environment_get(self.params.name).start()
def do_destroy(self):
self.manager.environment_get(self.params.name).destroy(verbose=False)
def do_suspend(self):
self.manager.environment_get(self.params.name).suspend()
def do_resume(self):
self.manager.environment_get(self.params.name).resume()
def do_revert(self):
self.manager.environment_get(self.params.name).revert(
self.params.snapshot_name)
def do_snapshot(self):
self.manager.environment_get(self.params.name).snapshot(
self.params.snapshot_name)
commands = {
'list': do_list,
'show': do_show,
'erase': do_erase,
'start': do_start,
'destroy': do_destroy,
'suspend': do_suspend,
'resume': do_resume,
'revert': do_revert,
'snapshot': do_snapshot
}
def get_params(self):
name_parser = argparse.ArgumentParser(add_help=False)
name_parser.add_argument('name', help='environment name',
default=os.getenv('ENV_NAME'))
snapshot_name_parser = argparse.ArgumentParser(add_help=False)
snapshot_name_parser.add_argument('--snapshot-name',
help='snapshot name',
default=os.getenv('SNAPSHOT_NAME'))
parser = argparse.ArgumentParser(
description="Manage virtual environments")
subparsers = parser.add_subparsers(help='commands', dest='command')
subparsers.add_parser('list')
subparsers.add_parser('show', parents=[name_parser])
subparsers.add_parser('erase', parents=[name_parser])
subparsers.add_parser('start', parents=[name_parser])
subparsers.add_parser('destroy', parents=[name_parser])
subparsers.add_parser('suspend', parents=[name_parser])
subparsers.add_parser('resume', parents=[name_parser])
subparsers.add_parser('revert',
parents=[name_parser, snapshot_name_parser])
subparsers.add_parser('snapshot',
parents=[name_parser, snapshot_name_parser])
return parser.parse_args()