本文整理汇总了Python中devops.models.Environment类的典型用法代码示例。如果您正苦于以下问题:Python Environment类的具体用法?Python Environment怎么用?Python Environment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Environment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_object_not_found_exceptions
def test_object_not_found_exceptions(self):
with self.assertRaises(DevopsObjNotFound):
Environment.get(name='other-env')
with self.assertRaises(DevopsObjNotFound):
self.env.get_group(name='other-rack')
with self.assertRaises(DevopsObjNotFound):
self.env.get_address_pool(name='other-pool')
with self.assertRaises(DevopsObjNotFound):
self.env.get_node(name='other-node')
group = self.env.get_group(name='rack-01')
with self.assertRaises(DevopsObjNotFound):
group.get_l2_network_device(name='other-device')
with self.assertRaises(DevopsObjNotFound):
group.get_network_pool(name='other-pool')
with self.assertRaises(DevopsObjNotFound):
group.get_node(name='other-node')
with self.assertRaises(DevopsObjNotFound):
Group.get(name='other-group')
node = self.env.get_node(name='slave-01')
with self.assertRaises(DevopsObjNotFound):
node.get_volume(name='other-volume')
示例2: d_env
def d_env(self):
if self._virtual_environment is None:
try:
return Environment.get(name=settings.ENV_NAME)
except Exception:
self._virtual_environment = Environment.describe_environment(
boot_from=settings.ADMIN_BOOT_DEVICE)
self._virtual_environment.define()
return self._virtual_environment
示例3: _create_env_from_config
def _create_env_from_config(self, config):
env_name = config['template']['devops_settings']['env_name']
for env in Environment.list_all():
if env.name == env_name:
print("Please, set another environment name")
raise SystemExit()
self.env = Environment.create_environment(config)
self.env.define()
# Start all l2 network devices
for group in self.env.get_groups():
for net in group.get_l2_network_devices():
net.start()
示例4: test_network_pool
def test_network_pool(self):
environment = Environment.create('test_env2')
self.assertEqual('10.0.0.0/24', str(Network.network_create(
environment=environment, name='internal', pool=None).ip_network))
self.assertEqual('10.0.1.0/24', str(Network.network_create(
environment=environment, name='external', pool=None).ip_network))
self.assertEqual('10.0.2.0/24', str(Network.network_create(
environment=environment, name='private', pool=None).ip_network))
environment = Environment.create('test_env2')
self.assertEqual('10.0.3.0/24', str(Network.network_create(
environment=environment, name='internal', pool=None).ip_network))
self.assertEqual('10.0.4.0/24', str(Network.network_create(
environment=environment, name='external', pool=None).ip_network))
self.assertEqual('10.0.5.0/24', str(Network.network_create(
environment=environment, name='private', pool=None).ip_network))
示例5: d_env
def d_env(self):
if self._virt_env is None:
if not self._config:
try:
return Environment.get(name=settings.ENV_NAME)
except Exception:
self._virt_env = Environment.describe_environment(boot_from=settings.ADMIN_BOOT_DEVICE)
self._virt_env.define()
else:
try:
return Environment.get(name=self._config["template"]["devops_settings"]["env_name"])
except Exception:
self._virt_env = Environment.create_environment(full_config=self._config)
self._virt_env.define()
return self._virt_env
示例6: test_external_snapshot_revert_with_children_revert_present
def test_external_snapshot_revert_with_children_revert_present(
self, mock_revert_snapshot_recreate_disks,
mock_revert_snapshot, mock_get_snapshot, mock_has_snapshot,
mock_destroy, mock_update_disks_from_snapshot):
revert_postfix = '-revert3'
def get_snapshot(node, snapname):
if snapname.endswith(revert_postfix):
return mock.Mock(get_type='external', children_num=0)
else:
return mock.Mock(get_type='external', children_num=1)
mock_has_snapshot.return_value = True
mock_get_snapshot.side_effect = get_snapshot
environment = Environment.create('test_env_extsnap')
node = Node.node_create(name='test_node', environment=environment)
environment.define()
snapshot_name = factories.fuzzy_string('snap_')
node.revert(name=snapshot_name, destroy=False)
revert_snapshot_name = '{0}{1}'.format(snapshot_name, revert_postfix)
mock_update_disks_from_snapshot.assert_called_with(
revert_snapshot_name)
mock_revert_snapshot_recreate_disks.assert_called_with(
node, revert_snapshot_name)
mock_revert_snapshot.assert_called_with(node=node,
name=revert_snapshot_name)
示例7: test_external_snapshot_volume_creation
def test_external_snapshot_volume_creation(self, mock_volume_define):
mock_volume_define.return_value = None
environment = Environment.create('test_env_extsnap')
node = Node.node_create(name='test_node', environment=environment)
vol_volume_name = factories.fuzzy_string()
vol = Volume.volume_create(vol_volume_name,
capacity=1000000000,
format='qcow2',
environment=environment)
DiskDevice.node_attach_volume(node=node, volume=vol)
environment.define()
snapshot_name = factories.fuzzy_string('snap_')
snapshot_volume_name = '{0}.{1}'.format(vol_volume_name,
snapshot_name)
node.snapshot_create_volume(snapshot_name)
vol1 = environment.get_volume(name=snapshot_volume_name)
self.assertEqual(len(node.disk_devices), 1)
self.assertEqual(vol1.name, snapshot_volume_name)
self.assertEqual(vol1.format, 'qcow2')
self.assertEqual(vol1.environment, environment)
self.assertEqual(vol1.backing_store, vol)
self.assertEqual(vol1, node.disk_devices[0].volume)
mock_volume_define.assert_called_with(vol1)
示例8: setUp
def setUp(self):
super(TestCloudImage, self).setUp()
self.open_mock = mock.mock_open(read_data='image_data')
self.patch('devops.driver.libvirt.libvirt_driver.open',
self.open_mock, create=True)
self.os_mock = self.patch('devops.helpers.helpers.os')
# noinspection PyPep8Naming
Size = collections.namedtuple('Size', ['st_size'])
self.file_sizes = {
'/tmp/test/cloud_settings.iso': Size(st_size=1 * 1024 ** 3),
}
self.os_mock.stat.side_effect = self.file_sizes.get
self.generate_cloud_image_settings_mock = self.patch(
'devops.helpers.cloud_image_settings'
'.generate_cloud_image_settings')
self.volume_upload_mock = self.patch(
'devops.driver.libvirt.Volume.upload')
# Environment with a 'public' network
self.env = Environment.create('test')
self.group = self.env.add_group(
group_name='test_group',
driver_name='devops.driver.libvirt',
connection_string='test:///default',
storage_pool_name='default-pool')
self.pub_ap = self.env.add_address_pool(
name='public-pool01', net='10.109.0.0/16:24', tag=0,
ip_reserved=dict(gateway=1, l2_network_device=1),
ip_ranges=dict(default=[2, -2]))
self.group.add_l2_network_device(
name='public', address_pool='public-pool01')
# Node connected to the 'public' network
self.node = self.group.add_node(
name='test-node',
role='cloud-node',
architecture='x86_64',
hypervisor='test',
cloud_init_volume_name='iso',
cloud_init_iface_up='enp0s3')
self.system_volume = self.node.add_volume(name='system', capacity=10)
self.iso_volume = self.node.add_volume(name='iso', capacity=5)
self.adm_iface = self.node.add_interface(
label='enp0s3',
l2_network_device_name='public',
mac_address='64:b6:87:44:14:17',
interface_model='e1000')
self.node.add_network_config(
label='enp0s3',
networks=['public'])
示例9: test_external_snapshot
def test_external_snapshot(
self, mock_has_snapshot, mock_create_volume,
mock_libvirt_version, mock_create_snapshot):
mock_has_snapshot.return_value = False
mock_libvirt_version.return_value = 1002012
environment = Environment.create('test_env_extsnap')
node = Node.node_create(name='test_node', environment=environment)
vol_volume_name = factories.fuzzy_string()
vol = Volume.volume_create(vol_volume_name,
capacity=1000000000,
format='qcow2',
environment=environment)
DiskDevice.node_attach_volume(node=node, volume=vol)
environment.define()
snap_name = factories.fuzzy_string('snap_')
snap_description = factories.fuzzy_string('description_')
node.snapshot(name=snap_name, description=snap_description,
external=True)
mock_create_volume.assert_called_with(snap_name)
mock_create_snapshot.assert_called_with(
node=node, name=snap_name, description=snap_description,
disk_only=False, external=True)
示例10: do_list
def do_list(self):
env_list = Environment.list_all().values("name", "created")
columns = []
for env in env_list:
column = collections.OrderedDict({"NAME": env["name"]})
if self.params.list_ips:
cur_env = Environment.get(name=env["name"])
admin_ip = ""
if "admin" in [node.name for node in cur_env.get_nodes()]:
admin_ip = cur_env.get_node(name="admin").get_ip_address_by_network_name("admin")
column["ADMIN IP"] = admin_ip
if self.params.timestamps:
column["CREATED"] = env["created"].strftime("%Y-%m-%d_%H:%M:%S")
columns.append(column)
self.print_table(headers="keys", columns=columns)
示例11: do_create
def do_create(self):
env_name = self.params.name
for env in Environment.list_all():
if env.name == env_name:
print("Please, set another environment name")
raise SystemExit()
self.env = Environment.create(env_name)
networks, prefix = self.params.net_pool.split(":")
Network.default_pool = Network.create_network_pool(networks=[ipaddr.IPNetwork(networks)], prefix=int(prefix))
networks = Network.create_networks(environment=self.env)
admin_node = self.admin_add(networks=networks)
self.do_slave_add(force_define=False)
self.env.define()
admin_node.disk_devices.get(device="cdrom").volume.upload(self.params.iso_path)
for net in self.env.get_networks():
net.start()
示例12: setUp
def setUp(self):
super(TestLibvirtL2NetworkDevice, self).setUp()
self.env = Environment.create('test_env')
self.group = self.env.add_group(
group_name='test_group',
driver_name='devops.driver.libvirt',
connection_string='test:///default')
self.ap = self.env.add_address_pool(
name='test_ap',
net='172.0.0.0/16:24',
tag=0,
ip_reserved=dict(l2_network_device='172.0.0.1'),
)
self.net_pool = self.group.add_network_pool(
name='fuelweb_admin',
address_pool_name='test_ap',
)
self.l2_net_dev = self.group.add_l2_network_device(
name='test_l2_net_dev',
forward=dict(mode='nat'),
address_pool='test_ap',
)
self.d = self.group.driver
示例13: test_snapshot_with_existing_name_force_delete
def test_snapshot_with_existing_name_force_delete(self, mock_has_snapshot,
mock_delete_snapshot,
mock_create_snapshot):
mock_has_snapshot.return_value = True
environment = Environment.create('test_env_extsnap')
node = Node.node_create(name='test_node', environment=environment)
environment.define()
snap_name = factories.fuzzy_string('snap_')
snap_description = factories.fuzzy_string('description_')
node.snapshot(
name=snap_name,
force=True,
description=snap_description,
disk_only=True)
self.assertEqual(mock_delete_snapshot.called, True)
mock_delete_snapshot.assert_called_with(node=node, name=snap_name)
mock_create_snapshot.assert_called_with(
node=node,
name=snap_name,
description=snap_description,
disk_only=True,
external=False)
示例14: test_node_creation
def test_node_creation(self):
environment = Environment.create('test_env3')
internal = Network.network_create(
environment=environment, name='internal', pool=None)
node = Node.node_create(name='test_node', environment=environment)
Interface.interface_create(node=node, network=internal)
environment.define()
示例15: setUp
def setUp(self):
super(TestLibvirtVolume, self).setUp()
self.sleep_mock = self.patch('devops.helpers.retry.sleep')
self.open_mock = mock.mock_open(read_data='image_data')
self.patch('devops.driver.libvirt.libvirt_driver.open',
self.open_mock, create=True)
self.os_mock = self.patch('devops.helpers.helpers.os')
Size = collections.namedtuple('Size', ['st_size'])
self.file_sizes = {
'/tmp/admin.iso': Size(st_size=500),
}
self.os_mock.stat.side_effect = self.file_sizes.get
self.env = Environment.create('test_env')
self.group = self.env.add_group(
group_name='test_group',
driver_name='devops.driver.libvirt.libvirt_driver',
connection_string='test:///default',
storage_pool_name='default-pool')
self.node = self.group.add_node(
name='test_node',
role='default',
architecture='i686',
hypervisor='test',
)
self.d = self.group.driver