本文整理汇总了Python中vcloud_plugin_common.wait_for_task函数的典型用法代码示例。如果您正苦于以下问题:Python wait_for_task函数的具体用法?Python wait_for_task怎么用?Python wait_for_task使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wait_for_task函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: create_volume
def create_volume(vca_client, **kwargs):
"""
create new volume, e.g.:
{
'use_external_resource': False,
'volume': {
'name': 'some-other',
'size': 11
}
}
"""
if ctx.node.properties.get('use_external_resource'):
ctx.logger.info("External resource has been used")
return
vdc_name = get_vcloud_config()['vdc']
name = ctx.node.properties['volume']['name']
size = ctx.node.properties['volume']['size']
size_in_Mb = size * 1024 * 1024
success, disk = vca_client.add_disk(vdc_name, name, size_in_Mb)
if success:
wait_for_task(vca_client, disk.get_Tasks()[0])
ctx.logger.info("Volume node {} has been created".format(name))
else:
raise cfy_exc.NonRecoverableError(
"Disk creation error: {0}".format(disk))
开发者ID:jalopez11,项目名称:cloudify-dependencies,代码行数:25,代码来源:volume.py
示例2: delete
def delete(vca_client, **kwargs):
"""
delete vcloud air network
"""
if ctx.node.properties['use_external_resource'] is True:
del ctx.instance.runtime_properties[VCLOUD_NETWORK_NAME]
ctx.logger.info("Network was not deleted - external resource has"
" been used")
return
network_name = get_network_name(ctx.node.properties)
if not _dhcp_operation(vca_client, network_name, DELETE_POOL):
return set_retry(ctx)
ctx.logger.info("Delete network '{0}'".format(network_name))
success, task = vca_client.delete_vdc_network(
get_vcloud_config()['vdc'], network_name)
if success:
wait_for_task(vca_client, task)
ctx.logger.info(
"Network '{0}' has been successful deleted.".format(network_name))
else:
if task and CANT_DELETE in task:
ctx.logger.info("Network {} in use. Deleting the network skipped.".
format(network_name))
return
raise cfy_exc.NonRecoverableError(
"Could not delete network '{0}': {1}".format(network_name, task))
开发者ID:denismakogon,项目名称:tosca-vcloud-plugin,代码行数:26,代码来源:network.py
示例3: create
def create(vca_client, **kwargs):
"""create vdc"""
config = get_vcloud_config()
# Subscription service does not support vdc create,
# you must use predefined vdc only
if is_subscription(config['service_type']):
raise cfy_exc.NonRecoverableError(
"Unable create VDC on subscription service.")
if ctx.node.properties.get(USE_EXTERNAL_RESOURCE):
# use external resource, does not create anything
res_id = ctx.node.properties[RESOURCE_ID]
ctx.instance.runtime_properties[VDC_NAME] = res_id
vdc = vca_client.get_vdc(res_id)
if not vdc:
raise cfy_exc.NonRecoverableError(
"Unable to find external VDC {0}."
.format(res_id))
ctx.logger.info(
"External resource {0} has been used".format(res_id))
else:
# create new vdc
vdc_name = ctx.node.properties.get('name')
if not vdc_name:
raise cfy_exc.NonRecoverableError("'vdc_name' not specified.")
task = vca_client.create_vdc(vdc_name)
if not task:
raise cfy_exc.NonRecoverableError("Could not create VDC: {0}"
.format(error_response(vca_client)))
wait_for_task(vca_client, task)
开发者ID:pkdevboxy,项目名称:tosca-vcloud-plugin,代码行数:29,代码来源:vdc.py
示例4: start
def start(vca_client, **kwargs):
"""
power on server and wait network connection availability for host
"""
if ctx.node.properties.get('use_external_resource'):
ctx.logger.info('not starting server since an external server is '
'being used')
else:
vapp_name = get_vapp_name(ctx.instance.runtime_properties)
config = get_vcloud_config()
vdc = vca_client.get_vdc(config['vdc'])
vapp = vca_client.get_vapp(vdc, vapp_name)
if _vapp_is_on(vapp) is False:
ctx.logger.info("Power-on VApp {0}".format(vapp_name))
task = vapp.poweron()
if not task:
raise cfy_exc.NonRecoverableError(
"Could not power-on vApp. {0}".
format(error_response(vapp)))
wait_for_task(vca_client, task)
if not _get_state(vca_client):
return ctx.operation.retry(
message="Waiting for VM's configuration to complete",
retry_after=5)
开发者ID:jalopez11,项目名称:cloudify-dependencies,代码行数:25,代码来源:server.py
示例5: del_ondemand_public_ip
def del_ondemand_public_ip(vca_client, gateway, ip, ctx):
task = gateway.deallocate_public_ip(ip)
if task:
wait_for_task(vca_client, task)
ctx.logger.info("Public IP {0} deallocated".format(ip))
else:
raise cfy_exc.NonRecoverableError(
"Can't deallocate public ip {0} for ondemand service".format(ip))
开发者ID:nmishkin,项目名称:tosca-vcloud-plugin,代码行数:8,代码来源:__init__.py
示例6: _power_on_vm
def _power_on_vm(vca_client, vapp, vapp_name):
"""Poweron VM"""
if _vapp_is_on(vapp) is False:
ctx.logger.info("Power-on VApp {0}".format(vapp_name))
task = vapp.poweron()
if not task:
raise cfy_exc.NonRecoverableError(
"Could not power-on vApp. {0}".
format(error_response(vapp)))
wait_for_task(vca_client, task)
开发者ID:pkdevboxy,项目名称:tosca-vcloud-plugin,代码行数:10,代码来源:server.py
示例7: save_gateway_configuration
def save_gateway_configuration(gateway, vca_client):
task = gateway.save_services_configuration()
if task:
wait_for_task(vca_client, task)
return True
else:
error = taskType.parseString(gateway.response.content, True)
if BUSY_MESSAGE in error.message:
return False
else:
raise cfy_exc.NonRecoverableError(error.message)
开发者ID:nmishkin,项目名称:tosca-vcloud-plugin,代码行数:11,代码来源:__init__.py
示例8: del_ondemand_public_ip
def del_ondemand_public_ip(vca_client, gateway, ip, ctx):
"""
try to deallocate public ip
"""
ctx.logger.info("Try to deallocate public IP {0}".format(ip))
task = gateway.deallocate_public_ip(ip)
if task:
wait_for_task(vca_client, task)
ctx.logger.info("Public IP {0} was deallocated".format(ip))
else:
raise cfy_exc.NonRecoverableError(
"Can't deallocate public ip {0}. {1} for ondemand service".
format(ip, error_response(gateway)))
开发者ID:denismakogon,项目名称:tosca-vcloud-plugin,代码行数:13,代码来源:__init__.py
示例9: stop
def stop(vca_client, **kwargs):
if ctx.node.properties.get('use_external_resource'):
ctx.logger.info('not stopping server since an external server is '
'being used')
else:
vapp_name = get_vapp_name(ctx.instance.runtime_properties)
config = get_vcloud_config()
vdc = vca_client.get_vdc(config['vdc'])
vapp = vca_client.get_vapp(vdc, vapp_name)
ctx.logger.info("Power-off and undeploy VApp {0}".format(vapp_name))
task = vapp.undeploy()
if not task:
raise cfy_exc.NonRecoverableError("Could not undeploy vApp")
wait_for_task(vca_client, task)
开发者ID:nmishkin,项目名称:tosca-vcloud-plugin,代码行数:14,代码来源:server.py
示例10: delete_volume
def delete_volume(vca_client, **kwargs):
"""
drop volume
"""
if ctx.node.properties.get('use_external_resource'):
ctx.logger.info("External resource has been used")
return
vdc_name = get_vcloud_config()['vdc']
name = ctx.node.properties['volume']['name']
success, task = vca_client.delete_disk(vdc_name, name)
if success:
wait_for_task(vca_client, task)
ctx.logger.info("Volume node {} has been deleted".format(name))
else:
raise cfy_exc.NonRecoverableError(
"Disk deletion error: {0}".format(task))
开发者ID:jalopez11,项目名称:cloudify-dependencies,代码行数:16,代码来源:volume.py
示例11: delete
def delete(vca_client, **kwargs):
if ctx.node.properties.get('use_external_resource'):
ctx.logger.info('not deleting server since an external server is '
'being used')
else:
vapp_name = get_vapp_name(ctx.instance.runtime_properties)
config = get_vcloud_config()
vdc = vca_client.get_vdc(config['vdc'])
vapp = vca_client.get_vapp(vdc, vapp_name)
ctx.logger.info("Deleting VApp {0}".format(vapp_name))
task = vapp.delete()
if not task:
raise cfy_exc.NonRecoverableError("Could not delete vApp")
wait_for_task(vca_client, task)
del ctx.instance.runtime_properties[VCLOUD_VAPP_NAME]
开发者ID:nmishkin,项目名称:tosca-vcloud-plugin,代码行数:16,代码来源:server.py
示例12: save_gateway_configuration
def save_gateway_configuration(gateway, vca_client):
"""
save gateway configuration,
return everything successfully finished
raise NonRecoverableError - can't get task description
"""
task = gateway.save_services_configuration()
if task:
wait_for_task(vca_client, task)
return True
else:
error = taskType.parseString(gateway.response.content, True)
if BUSY_MESSAGE in error.message:
return False
else:
raise cfy_exc.NonRecoverableError(error.message)
开发者ID:kemiz,项目名称:tosca-vcloud-plugin,代码行数:16,代码来源:__init__.py
示例13: delete
def delete(vca_client, **kwargs):
"""
delete vcloud air network
"""
if ctx.node.properties["use_external_resource"] is True:
del ctx.instance.runtime_properties[VCLOUD_NETWORK_NAME]
ctx.logger.info("Network was not deleted - external resource has" " been used")
return
network_name = get_network_name(ctx.node.properties)
_dhcp_operation(vca_client, network_name, DELETE_POOL)
success, task = vca_client.delete_vdc_network(get_vcloud_config()["vdc"], network_name)
if success:
ctx.logger.info("Network {0} has been successful deleted.".format(network_name))
else:
raise cfy_exc.NonRecoverableError("Could not delete network {0}".format(network_name))
wait_for_task(vca_client, task)
开发者ID:rbramwell,项目名称:tosca-vcloud-plugin,代码行数:16,代码来源:network.py
示例14: delete
def delete(vca_client, **kwargs):
"""delete vdc"""
# external resource - no actions
if ctx.node.properties.get(USE_EXTERNAL_RESOURCE):
ctx.logger.info('Not deleting VDC since an external VDC is '
'being used')
else:
# created in our workflow
vdc_name = ctx.node.properties.get('name')
status, task = vca_client.delete_vdc(vdc_name)
if not status:
raise cfy_exc.NonRecoverableError("Could not delete VDC: {0}"
.format(error_response(vca_client)))
wait_for_task(vca_client, task)
# clean up runtime_properties
if VDC_NAME in ctx.instance.runtime_properties:
del ctx.instance.runtime_properties[VDC_NAME]
开发者ID:pkdevboxy,项目名称:tosca-vcloud-plugin,代码行数:17,代码来源:vdc.py
示例15: get_ondemand_public_ip
def get_ondemand_public_ip(vca_client, gateway, ctx):
old_public_ips = set(gateway.get_public_ips())
task = gateway.allocate_public_ip()
if task:
wait_for_task(vca_client, task)
else:
raise cfy_exc.NonRecoverableError(
"Can't get public ip for ondemand service")
# update gateway for new IP address
gateway = vca_client.get_gateways(get_vcloud_config()['vdc'])[0]
new_public_ips = set(gateway.get_public_ips())
new_ip = new_public_ips - old_public_ips
if new_ip:
ctx.logger.info("Assign public IP {0}".format(new_ip))
else:
raise cfy_exc.NonRecoverableError(
"Can't get new public IP address")
return list(new_ip)[0]
开发者ID:nmishkin,项目名称:tosca-vcloud-plugin,代码行数:18,代码来源:__init__.py
示例16: _volume_operation
def _volume_operation(vca_client, operation):
"""
attach/detach volume
"""
vdc_name = get_vcloud_config()['vdc']
vdc = vca_client.get_vdc(vdc_name)
vmName = get_vapp_name(ctx.target.instance.runtime_properties)
if ctx.source.node.properties.get('use_external_resource'):
volumeName = ctx.source.node.properties['resource_id']
else:
volumeName = ctx.source.node.properties['volume']['name']
vapp = vca_client.get_vapp(vdc, vmName)
for ref in vca_client.get_diskRefs(vdc):
if ref.name == volumeName:
if operation == 'ATTACH':
ctx.logger.info("Attach volume node '{0}'.".format(volumeName))
task = vapp.attach_disk_to_vm(vmName, ref)
if task:
wait_for_task(vca_client, task)
ctx.logger.info(
"Volume node '{0}' has been attached".format(volumeName))
else:
raise cfy_exc.NonRecoverableError(
"Can't attach disk: '{0}' with error: {1}".
format(volumeName, error_response(vapp)))
elif operation == 'DETACH':
ctx.logger.info("Detach volume node '{0}'.".format(volumeName))
task = vapp.detach_disk_from_vm(vmName, ref)
if task:
wait_for_task(vca_client, task)
ctx.logger.info(
"Volume node '{0}' has been detached.".
format(volumeName))
else:
raise cfy_exc.NonRecoverableError(
"Can't detach disk: '{0}'. With error: {1}".
format(volumeName, error_response(vapp)))
else:
raise cfy_exc.NonRecoverableError(
"Unknown operation '{0}'".format(operation))
开发者ID:pkdevboxy,项目名称:tosca-vcloud-plugin,代码行数:41,代码来源:volume.py
示例17: configure
def configure(vca_client, **kwargs):
ctx.logger.info("Configure server")
server = {'name': ctx.instance.id}
server.update(ctx.node.properties.get('server', {}))
vapp_name = server['name']
config = get_vcloud_config()
custom = server.get(GUEST_CUSTOMIZATION, {})
public_keys = _get_connected_keypairs()
if custom or public_keys:
vdc = vca_client.get_vdc(config['vdc'])
vapp = vca_client.get_vapp(vdc, vapp_name)
script = _build_script(custom, public_keys)
password = custom.get('admin_password')
computer_name = custom.get('computer_name')
task = vapp.customize_guest_os(
vapp_name,
customization_script=script,
computer_name=computer_name,
admin_password=password
)
if task is None:
raise cfy_exc.NonRecoverableError(
"Could not set guest customization parameters. {0}".
format(error_response(vapp)))
wait_for_task(vca_client, task)
if vapp.customize_on_next_poweron():
ctx.logger.info("Customizations successful")
else:
raise cfy_exc.NonRecoverableError(
"Can't run customization in next power on. {0}".
format(error_response(vapp)))
hardware = server.get('hardware')
if hardware:
cpu = hardware.get('cpu')
memory = hardware.get('memory')
_check_hardware(cpu, memory)
vapp = vca_client.get_vapp(
vca_client.get_vdc(config['vdc']), vapp_name
)
if memory:
try:
task = vapp.modify_vm_memory(vapp_name, memory)
wait_for_task(vca_client, task)
ctx.logger.info("Customize VM memory: '{0}'.".format(memory))
except Exception:
raise cfy_exc.NonRecoverableError(
"Customize VM memory failed: '{0}'. {1}".
format(task, error_response(vapp)))
if cpu:
try:
task = vapp.modify_vm_cpu(vapp_name, cpu)
wait_for_task(vca_client, task)
ctx.logger.info("Customize VM cpu: '{0}'.".format(cpu))
except Exception:
raise cfy_exc.NonRecoverableError(
"Customize VM cpu failed: '{0}'. {1}".
format(task, error_response(vapp)))
开发者ID:jalopez11,项目名称:cloudify-dependencies,代码行数:59,代码来源:server.py
示例18: get_ondemand_public_ip
def get_ondemand_public_ip(vca_client, gateway, ctx):
"""
try to allocate new public ip for ondemand service
"""
old_public_ips = set(gateway.get_public_ips())
allocated_ips = set([address.external
for address in collectAssignedIps(gateway)])
available_ips = old_public_ips - allocated_ips
if available_ips:
new_ip = list(available_ips)[0]
ctx.logger.info("Public IP {0} was reused.".format(new_ip))
return new_ip
for i in xrange(RETRY_COUNT):
ctx.logger.info("Try to allocate public IP")
wait_for_gateway(vca_client, gateway.get_name(), ctx)
task = gateway.allocate_public_ip()
if task:
try:
wait_for_task(vca_client, task)
break
except cfy_exc.NonRecoverableError:
continue
else:
raise cfy_exc.NonRecoverableError(
"Can't get public ip for ondemand service {0}".
format(error_response(gateway)))
# update gateway for new IP address
gateway = vca_client.get_gateways(get_vcloud_config()['vdc'])[0]
new_public_ips = set(gateway.get_public_ips())
new_ip = new_public_ips - old_public_ips
if new_ip:
ctx.logger.info("Public IP {0} was asigned.".format(new_ip))
else:
raise cfy_exc.NonRecoverableError(
"Can't get new public IP address")
return list(new_ip)[0]
开发者ID:pkdevboxy,项目名称:tosca-vcloud-plugin,代码行数:36,代码来源:__init__.py
示例19: test_wait_for_task
def test_wait_for_task(self):
fake_client = self.generate_client()
fake_ctx = self.generate_node_context()
# error in task
fake_task = self.generate_task(
vcloud_plugin_common.TASK_STATUS_ERROR
)
with mock.patch('vcloud_plugin_common.ctx', fake_ctx):
with self.assertRaises(cfy_exc.NonRecoverableError):
vcloud_plugin_common.wait_for_task(fake_client, fake_task)
# success in task
fake_task = self.generate_task(
vcloud_plugin_common.TASK_STATUS_SUCCESS
)
with mock.patch('vcloud_plugin_common.ctx', fake_ctx):
vcloud_plugin_common.wait_for_task(fake_client, fake_task)
# success after wait
fake_task = self.generate_task(
None
)
fake_task_after_wait = self.generate_task(
vcloud_plugin_common.TASK_STATUS_SUCCESS
)
sleep = mock.MagicMock(return_value=None)
response = mock.Mock()
response.content = 'Success'
with mock.patch(
'pyvcloud.schema.vcd.v1_5.schemas.vcloud.taskType.parseString',
mock.MagicMock(return_value=fake_task_after_wait)
):
with mock.patch(
'requests.get', mock.MagicMock(return_value=response)
):
with mock.patch(
'time.sleep',
sleep
):
with mock.patch('vcloud_plugin_common.ctx',
fake_ctx):
vcloud_plugin_common.wait_for_task(
fake_client, fake_task)
开发者ID:pkdevboxy,项目名称:tosca-vcloud-plugin,代码行数:41,代码来源:test_mock_vcloud_plugin_common.py
示例20: _create
def _create(vca_client, config, server):
"""
create server by template,
customize:
* hardware: memmory/cpu
* software: root password, computer internal hostname
connect vm to network
"""
vapp_name = server['name']
vapp_template = server['template']
vapp_catalog = server['catalog']
ctx.logger.info("Creating VApp with parameters: {0}".format(server))
task = vca_client.create_vapp(config['vdc'],
vapp_name,
vapp_template,
vapp_catalog,
vm_name=vapp_name)
if not task:
raise cfy_exc.NonRecoverableError("Could not create vApp: {0}"
.format(vca_client.response.content))
wait_for_task(vca_client, task)
hardware = server.get('hardware')
if hardware:
cpu = hardware.get('cpu')
memory = hardware.get('memory')
_check_hardware(cpu, memory)
vapp = vca_client.get_vapp(
vca_client.get_vdc(config['vdc']), vapp_name
)
if memory:
task = vapp.modify_vm_memory(vapp_name, memory)
if task:
wait_for_task(vca_client, task)
ctx.logger.info("Customize VM memory: {0}.".format(memory))
else:
raise cfy_exc.NonRecoverableError(
"Customize VM memory failed: {0}.".format(task)
)
if cpu:
task = vapp.modify_vm_cpu(vapp_name, cpu)
if task:
wait_for_task(vca_client, task)
ctx.logger.info("Customize VM cpu: {0}.".format(cpu))
else:
raise cfy_exc.NonRecoverableError(
"Customize VM cpu failed: {0}.".format(task)
)
ctx.instance.runtime_properties[VCLOUD_VAPP_NAME] = vapp_name
connections = _create_connections_list(vca_client)
# we allways have connection to management_network_name
if connections:
for index, connection in enumerate(connections):
vdc = vca_client.get_vdc(config['vdc'])
vapp = vca_client.get_vapp(vdc, vapp_name)
if vapp is None:
raise cfy_exc.NonRecoverableError(
"vApp '{0}' could not be found".format(vapp_name))
network_name = connection.get('network')
network = get_network(vca_client, network_name)
task = vapp.connect_to_network(network_name, network.get_href())
if not task:
raise cfy_exc.NonRecoverableError(
"Could not add network {0} to VApp {1}"
.format(network_name, vapp_name))
wait_for_task(vca_client, task)
connections_primary_index = None
if connection.get('primary_interface'):
connections_primary_index = index
ip_address = connection.get('ip_address')
mac_address = connection.get('mac_address')
ip_allocation_mode = connection.get('ip_allocation_mode',
'POOL').upper()
connection_args = {
'network_name': network_name,
'connection_index': index,
'connections_primary_index': connections_primary_index,
'ip_allocation_mode': ip_allocation_mode,
'mac_address': mac_address,
'ip_address': ip_address
}
ctx.logger.info("Connecting network with parameters {0}"
.format(str(connection_args)))
task = vapp.connect_vms(**connection_args)
if task is None:
raise cfy_exc.NonRecoverableError(
"Could not connect vApp {0} to network {1}"
.format(vapp_name, network_name))
wait_for_task(vca_client, task)
# customize root password and hostname
custom = server.get(GUEST_CUSTOMIZATION)
if custom:
vdc = vca_client.get_vdc(config['vdc'])
vapp = vca_client.get_vapp(vdc, vapp_name)
#.........这里部分代码省略.........
开发者ID:kemiz,项目名称:tosca-vcloud-plugin,代码行数:101,代码来源:server.py
注:本文中的vcloud_plugin_common.wait_for_task函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论