本文整理汇总了Python中cfme.cloud.instance.Instance.factory方法的典型用法代码示例。如果您正苦于以下问题:Python Instance.factory方法的具体用法?Python Instance.factory怎么用?Python Instance.factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cfme.cloud.instance.Instance
的用法示例。
在下文中一共展示了Instance.factory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testing_instance
# 需要导入模块: from cfme.cloud.instance import Instance [as 别名]
# 或者: from cfme.cloud.instance.Instance import factory [as 别名]
def testing_instance(setup_provider, provider):
""" Fixture to provision instance on the provider
"""
instance = Instance.factory(random_vm_name('pwr-c'), provider)
if not provider.mgmt.does_vm_exist(instance.name):
instance.create_on_provider(allow_skip="default")
elif instance.provider.type == "ec2" and \
provider.mgmt.is_vm_state(instance.name, provider.mgmt.states['deleted']):
provider.mgmt.set_name(
instance.name, 'test_terminated_{}'.format(fauxfactory.gen_alphanumeric(8)))
instance.create_on_provider(allow_skip="default", find_in_cfme=True)
provider.refresh_provider_relationships()
# Make sure the instance shows up
try:
wait_for(lambda: instance.exists,
fail_condition=False,
num_sec=600,
delay=15,
fail_func=provider.refresh_provider_relationships)
except TimedOutError:
pytest.fail('Failed to find instance in CFME after creating on provider: {}'
.format(instance.name))
yield instance
logger.info('Fixture cleanup, deleting test instance: %s', instance.name)
try:
provider.mgmt.delete_vm(instance.name)
except Exception:
logger.exception('Exception when deleting testing_instance: %s', instance.name)
示例2: testing_instance
# 需要导入模块: from cfme.cloud.instance import Instance [as 别名]
# 或者: from cfme.cloud.instance.Instance import factory [as 别名]
def testing_instance(request, setup_provider, provider, provisioning, vm_name):
""" Fixture to prepare instance parameters for provisioning
"""
image = provisioning["image"]["name"]
note = "Testing provisioning from image {} to vm {} on provider {}".format(image, vm_name, provider.key)
instance = Instance.factory(vm_name, provider, image)
request.addfinalizer(instance.delete_from_provider)
inst_args = {
"email": "[email protected]",
"first_name": "Image",
"last_name": "Provisioner",
"notes": note,
"instance_type": provisioning["instance_type"] if provider.type != "azure" else provisioning["vm_size"],
"availability_zone": provisioning["availability_zone"] if provider.type != "azure" else None,
"security_groups": [provisioning["security_group"]]
if provider.type != "azure"
else provisioning["network_nsg"],
"guest_keypair": provisioning["guest_keypair"] if provider.type != "azure" else None,
}
if isinstance(provider, OpenStackProvider):
inst_args["cloud_network"] = provisioning["cloud_network"]
if isinstance(provider, AzureProvider):
inst_args["cloud_network"] = provisioning["virtual_net"]
inst_args["cloud_subnet"] = provisioning["subnet_range"]
inst_args["security_groups"] = provisioning["network_nsg"]
inst_args["resource_groups"] = provisioning["resource_group"]
inst_args["instance_type"] = provisioning["vm_size"]
inst_args["admin_username"] = provisioning["vm_user"]
inst_args["admin_password"] = provisioning["vm_password"]
return instance, inst_args
示例3: test_provision_from_template
# 需要导入模块: from cfme.cloud.instance import Instance [as 别名]
# 或者: from cfme.cloud.instance.Instance import factory [as 别名]
def test_provision_from_template(request, setup_provider, provider, vm_name, provisioning):
""" Tests instance provision from template
Metadata:
test_flag: provision
"""
image = provisioning['image']['name']
note = ('Testing provisioning from image {} to vm {} on provider {}'.format(
image, vm_name, provider.key))
instance = Instance.factory(vm_name, provider, image)
request.addfinalizer(instance.delete_from_provider)
inst_args = {
'email': '[email protected]',
'first_name': 'Image',
'last_name': 'Provisioner',
'notes': note,
'instance_type': provisioning['instance_type'],
'availability_zone': provisioning['availability_zone'],
'security_groups': [provisioning['security_group']],
'guest_keypair': provisioning['guest_keypair']
}
if isinstance(provider, OpenStackProvider):
inst_args['cloud_network'] = provisioning['cloud_network']
sel.force_navigate("clouds_instances_by_provider")
instance.create(**inst_args)
示例4: test_instance
# 需要导入模块: from cfme.cloud.instance import Instance [as 别名]
# 或者: from cfme.cloud.instance.Instance import factory [as 别名]
def test_instance(setup_provider_modscope, request, delete_instances_fin, provider, vm_name):
""" Fixture to provision instance on the provider
"""
instance = Instance.factory(vm_name, provider)
if not provider.mgmt.does_vm_exist(vm_name):
delete_instances_fin[provider.key] = instance
instance.create_on_provider(allow_skip="default")
return instance
示例5: new_vm
# 需要导入模块: from cfme.cloud.instance import Instance [as 别名]
# 或者: from cfme.cloud.instance.Instance import factory [as 别名]
def new_vm(provider, request):
if provider.one_of(CloudProvider):
vm = Instance.factory(random_vm_name(context='cockpit'), provider)
else:
vm = InfraVm.factory(random_vm_name(context='cockpit'), provider)
if not provider.mgmt.does_vm_exist(vm.name):
vm.create_on_provider(find_in_cfme=True, allow_skip="default")
request.addfinalizer(vm.cleanup_on_provider)
return vm
示例6: new_instance
# 需要导入模块: from cfme.cloud.instance import Instance [as 别名]
# 或者: from cfme.cloud.instance.Instance import factory [as 别名]
def new_instance(provider):
inst = Instance.factory(random_vm_name('cloud-timeline', max_length=20), provider)
logger.debug('Fixture new_instance set up! Name: %r Provider: %r', inst.name,
inst.provider.name)
inst.create_on_provider(allow_skip="default", find_in_cfme=True)
yield inst
logger.debug('Fixture new_vm teardown! Name: %r Provider: %r', inst.name, inst.provider.name)
if inst.provider.mgmt.does_vm_exist(inst.name):
inst.provider.mgmt.delete_vm(inst.name)
示例7: create_instance
# 需要导入模块: from cfme.cloud.instance import Instance [as 别名]
# 或者: from cfme.cloud.instance.Instance import factory [as 别名]
def create_instance(provider):
instance = Instance.factory(random_vm_name('pwr-c'), provider)
if not provider.mgmt.does_vm_exist(instance.name):
instance.create_on_provider(allow_skip="default", find_in_cfme=True)
elif instance.provider.type == "ec2" and \
provider.mgmt.is_vm_state(instance.name, provider.mgmt.states['deleted']):
provider.mgmt.set_name(
instance.name, 'test_terminated_{}'.format(fauxfactory.gen_alphanumeric(8)))
instance.create_on_provider(allow_skip="default", find_in_cfme=True)
return instance
示例8: new_instance
# 需要导入模块: from cfme.cloud.instance import Instance [as 别名]
# 或者: from cfme.cloud.instance.Instance import factory [as 别名]
def new_instance(request, provider):
instance = Instance.factory(random_vm_name("timelines", max_length=16), provider)
request.addfinalizer(instance.delete_from_provider)
if not provider.mgmt.does_vm_exist(instance.name):
logger.info("deploying %s on provider %s", instance.name, provider.key)
instance.create_on_provider(allow_skip="default", find_in_cfme=True)
if instance.provider.one_of(EC2Provider):
ec2_sleep()
return instance
示例9: test_provision_cloud_init
# 需要导入模块: from cfme.cloud.instance import Instance [as 别名]
# 或者: from cfme.cloud.instance.Instance import factory [as 别名]
def test_provision_cloud_init(request, setup_provider, provider, provisioning,
setup_ci_template, vm_name):
""" Tests provisioning from a template with cloud_init
Metadata:
test_flag: cloud_init, provision
"""
image = provisioning.get('ci-image') or provisioning['image']['name']
note = ('Testing provisioning from image {} to vm {} on provider {}'.format(
image, vm_name, provider.key))
logger.info(note)
mgmt_system = provider.mgmt
instance = Instance.factory(vm_name, provider, image)
request.addfinalizer(instance.cleanup_on_provider)
# TODO: extend inst_args for other providers except EC2 if needed
inst_args = {
'request': {'email': '[email protected]',
'first_name': 'Image',
'last_name': 'Provisioner',
'notes': note},
'catalog': {'vm_name': vm_name},
'properties': {'instance_type': provisioning['instance_type'],
'guest_keypair': provisioning['guest_keypair']},
'environment': {'availability_zone': provisioning['availability_zone'],
'cloud_network': provisioning['cloud_network'],
'security_groups': [provisioning['security_group']]},
'customize': {'custom_template': {'name': provisioning['ci-template']}}
}
if provider.one_of(OpenStackProvider):
floating_ip = mgmt_system.get_first_floating_ip()
inst_args['environment']['public_ip_address'] = floating_ip
logger.info('Instance args: {}'.format(inst_args))
instance.create(**inst_args)
provision_request = provider.appliance.collections.requests.instantiate(vm_name,
partial_check=True)
provision_request.wait_for_request()
connect_ip = mgmt_system.get_ip_address(vm_name)
# Check that we can at least get the uptime via ssh this should only be possible
# if the username and password have been set via the cloud-init script so
# is a valid check
with ssh.SSHClient(hostname=connect_ip, username=provisioning['ci-username'],
password=provisioning['ci-pass']) as ssh_client:
wait_for(ssh_client.uptime, num_sec=200, handle_exception=True)
示例10: testing_instance
# 需要导入模块: from cfme.cloud.instance import Instance [as 别名]
# 或者: from cfme.cloud.instance.Instance import factory [as 别名]
def testing_instance(request, setup_provider, provider):
""" Fixture to provision instance on the provider
"""
instance = Instance.factory("test_inst_pwrctl_{}".format(fauxfactory.gen_alpha(8)), provider)
if not provider.mgmt.does_vm_exist(instance.name):
instance.create_on_provider(allow_skip="default", find_in_cfme=True)
request.addfinalizer(instance.delete_from_provider)
elif instance.provider.type == "ec2" and \
provider.mgmt.is_vm_state(instance.name, provider.mgmt.states['deleted']):
provider.mgmt.set_name(
instance.name, 'test_terminated_{}'.format(fauxfactory.gen_alphanumeric(8)))
instance.create_on_provider(allow_skip="default", find_in_cfme=True)
request.addfinalizer(instance.delete_from_provider)
return instance
示例11: test_provision_cloud_init
# 需要导入模块: from cfme.cloud.instance import Instance [as 别名]
# 或者: from cfme.cloud.instance.Instance import factory [as 别名]
def test_provision_cloud_init(request, setup_provider, provider, provisioning,
setup_ci_template, vm_name):
""" Tests provisioning from a template with cloud_init
Metadata:
test_flag: cloud_init, provision
"""
image = provisioning.get('ci-image', None) or provisioning['image']['name']
note = ('Testing provisioning from image {} to vm {} on provider {}'.format(
image, vm_name, provider.key))
logger.info(note)
mgmt_system = provider.mgmt
instance = Instance.factory(vm_name, provider, image)
request.addfinalizer(instance.delete_from_provider)
inst_args = {
'email': '[email protected]',
'first_name': 'Image',
'last_name': 'Provisioner',
'notes': note,
'instance_type': provisioning['instance_type'],
'availability_zone': provisioning['availability_zone'],
'security_groups': [provisioning['security_group']],
'guest_keypair': provisioning['guest_keypair'],
'custom_template': {'name': [provisioning['ci-template']]},
}
if provider.type == "openstack":
floating_ip = mgmt_system.get_first_floating_ip()
inst_args['cloud_network'] = provisioning['cloud_network']
inst_args['public_ip_address'] = floating_ip
logger.info('Instance args: {}'.format(inst_args))
instance.create(**inst_args)
connect_ip, tc = wait_for(mgmt_system.get_ip_address, [vm_name], num_sec=300,
handle_exception=True)
# Check that we can at least get the uptime via ssh this should only be possible
# if the username and password have been set via the cloud-init script so
# is a valid check
sshclient = ssh.SSHClient(hostname=connect_ip, username=provisioning['ci-username'],
password=provisioning['ci-pass'])
wait_for(sshclient.uptime, num_sec=200, handle_exception=True)
示例12: testing_instance
# 需要导入模块: from cfme.cloud.instance import Instance [as 别名]
# 或者: from cfme.cloud.instance.Instance import factory [as 别名]
def testing_instance(request, setup_provider, provider):
""" Fixture to provision instance on the provider
"""
instance = Instance.factory(random_vm_name('pwr-c'), provider)
if not provider.mgmt.does_vm_exist(instance.name):
instance.create_on_provider(timeout=1000, allow_skip="default", find_in_cfme=True)
request.addfinalizer(instance.delete_from_provider)
provider.refresh_provider_relationships()
elif instance.provider.type == "ec2" and \
provider.mgmt.is_vm_state(instance.name, provider.mgmt.states['deleted']):
provider.mgmt.set_name(
instance.name, 'test_terminated_{}'.format(fauxfactory.gen_alphanumeric(8)))
instance.create_on_provider(allow_skip="default", find_in_cfme=True)
request.addfinalizer(instance.delete_from_provider)
provider.refresh_provider_relationships()
instance.wait_to_appear()
return instance
示例13: testing_instance
# 需要导入模块: from cfme.cloud.instance import Instance [as 别名]
# 或者: from cfme.cloud.instance.Instance import factory [as 别名]
def testing_instance(setup_provider, provider):
""" Fixture to provision instance on the provider
"""
instance = Instance.factory(random_vm_name('pwr-c'), provider)
if not provider.mgmt.does_vm_exist(instance.name):
instance.create_on_provider(allow_skip="default", find_in_cfme=True)
elif instance.provider.type == "ec2" and \
provider.mgmt.is_vm_state(instance.name, provider.mgmt.states['deleted']):
provider.mgmt.set_name(
instance.name, 'test_terminated_{}'.format(fauxfactory.gen_alphanumeric(8)))
instance.create_on_provider(allow_skip="default", find_in_cfme=True)
yield instance
logger.info('Fixture cleanup, deleting test instance: %s', instance.name)
try:
provider.mgmt.delete_vm(instance.name)
except Exception:
logger.exception('Exception when deleting testing_instance: %s', instance.name)
示例14: test_tenant_quota_enforce_via_lifecycle_cloud
# 需要导入模块: from cfme.cloud.instance import Instance [as 别名]
# 或者: from cfme.cloud.instance.Instance import factory [as 别名]
def test_tenant_quota_enforce_via_lifecycle_cloud(request, appliance, provider, setup_provider,
set_roottenant_quota, extra_msg, custom_prov_data,
approve, prov_data, vm_name, template_name):
"""Test Tenant Quota in UI"""
prov_data.update(custom_prov_data)
prov_data['catalog']['vm_name'] = vm_name
prov_data.update({
'request': {'email': 'test_{}@example.com'.format(fauxfactory.gen_alphanumeric())}})
instance = Instance.factory(vm_name, provider, template_name)
instance.create(**prov_data)
# nav to requests page to check quota validation
request_description = 'Provision from [{}] to [{}{}]'.format(template_name, vm_name, extra_msg)
provision_request = appliance.collections.requests.instantiate(request_description)
if approve:
provision_request.approve_request(method='ui', reason="Approved")
provision_request.wait_for_request(method='ui')
assert provision_request.row.reason.text == "Quota Exceeded"
request.addfinalizer(provision_request.remove_request)
示例15: testing_instance
# 需要导入模块: from cfme.cloud.instance import Instance [as 别名]
# 或者: from cfme.cloud.instance.Instance import factory [as 别名]
def testing_instance(request, setup_provider, provider, provisioning, vm_name):
""" Fixture to prepare instance parameters for provisioning
"""
image = provisioning['image']['name']
note = ('Testing provisioning from image {} to vm {} on provider {}'.format(
image, vm_name, provider.key))
instance = Instance.factory(vm_name, provider, image)
request.addfinalizer(instance.delete_from_provider)
inst_args = {
'email': '[email protected]',
'first_name': 'Image',
'last_name': 'Provisioner',
'notes': note,
}
if not isinstance(provider, AzureProvider):
inst_args['instance_type'] = provisioning['instance_type']
inst_args['availability_zone'] = provisioning['availability_zone']
inst_args['security_groups'] = [provisioning['security_group']]
inst_args['guest_keypair'] = provisioning['guest_keypair']
if isinstance(provider, OpenStackProvider):
inst_args['cloud_network'] = provisioning['cloud_network']
if isinstance(provider, GCEProvider):
inst_args['cloud_network'] = provisioning['cloud_network']
inst_args['boot_disk_size'] = provisioning['boot_disk_size']
inst_args['is_preemtible'] = True if current_version() >= "5.7" else None
if isinstance(provider, AzureProvider):
inst_args['cloud_network'] = provisioning['virtual_net']
inst_args['cloud_subnet'] = provisioning['subnet_range']
inst_args['security_groups'] = provisioning['network_nsg']
inst_args['resource_groups'] = provisioning['resource_group']
inst_args['instance_type'] = provisioning['vm_size'].lower() \
if current_version() >= "5.7" else provisioning['vm_size']
inst_args['admin_username'] = provisioning['vm_user']
inst_args['admin_password'] = provisioning['vm_password']
return instance, inst_args