本文整理汇总了Python中vcloud_plugin_common.get_vcloud_config函数的典型用法代码示例。如果您正苦于以下问题:Python get_vcloud_config函数的具体用法?Python get_vcloud_config怎么用?Python get_vcloud_config使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_vcloud_config函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_vcloud_config
def test_get_vcloud_config(self):
# context.NODE_INSTANCE
fake_ctx = self.generate_node_context(
properties={
'vcloud_config': {
'vdc': 'vdc_name'
}
}
)
fake_ctx._instance = mock.Mock()
with mock.patch(
'vcloud_plugin_common.ctx', fake_ctx
):
self.assertEqual(
vcloud_plugin_common.get_vcloud_config(),
{
'vdc': 'vdc_name'
}
)
# context.RELATIONSHIP_INSTANCE
fake_ctx = self.generate_relation_context()
fake_ctx._source.node.properties = {
'vcloud_config': {
'vdc': 'vdc_name'
}
}
with mock.patch(
'vcloud_plugin_common.ctx', fake_ctx
):
self.assertEqual(
vcloud_plugin_common.get_vcloud_config(),
{
'vdc': 'vdc_name'
}
)
# context.DEPLOYMENT
fake_ctx = self.generate_node_context(
properties={
'vcloud_config': {
'vdc': 'vdc_name'
}
}
)
fake_ctx._source = None
fake_ctx._instance = None
with mock.patch(
'vcloud_plugin_common.ctx', fake_ctx
):
with self.assertRaises(cfy_exc.NonRecoverableError):
vcloud_plugin_common.get_vcloud_config()
示例2: _get_state
def _get_state(vca_client):
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)
nw_connections = _get_vm_network_connections(vapp)
if len(nw_connections) == 0:
ctx.logger.info("No networks connected")
ctx.instance.runtime_properties['ip'] = None
ctx.instance.runtime_properties['networks'] = {}
return True
management_network_name = _get_management_network_from_node()
if not all([connection['ip'] for connection in nw_connections]):
ctx.logger.info("Network configuration is not finished yet.")
return False
ctx.instance.runtime_properties['networks'] = {
connection['network_name']: connection['ip']
for connection in nw_connections}
for connection in nw_connections:
if connection['network_name'] == management_network_name:
ctx.logger.info("Management network ip address {0}"
.format(connection['ip']))
ctx.instance.runtime_properties['ip'] = connection['ip']
return True
return False
示例3: 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))
示例4: get_gateway
def get_gateway(vca_client, gateway_name):
gateway = vca_client.get_gateway(get_vcloud_config()['vdc'],
gateway_name)
if not gateway:
raise cfy_exc.NonRecoverableError(
"Gateway {0} not found".format(gateway_name))
return gateway
示例5: 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)
示例6: get_vm_ip
def get_vm_ip(vca_client, ctx, gateway):
"""
get ip assigned to current vm from connected primary network.
"""
try:
vappName = get_vapp_name(ctx.source.instance.runtime_properties)
vdc = vca_client.get_vdc(get_vcloud_config()['vdc'])
vapp = vca_client.get_vapp(vdc, vappName)
if not vapp:
raise cfy_exc.NonRecoverableError(
"Could not find vApp {0}".format(vappName))
vm_info = vapp.get_vms_network_info()
# assume that we have 1 vm per vApp
for connection in vm_info[0]:
if connection['is_connected'] and connection['is_primary']:
if is_network_routed(vca_client,
connection['network_name'],
gateway):
return connection['ip']
else:
raise cfy_exc.NonRecoverableError(
"Primary network {0} not routed"
.format(connection['network_name']))
raise cfy_exc.NonRecoverableError("No connected primary network")
except IndexError:
raise cfy_exc.NonRecoverableError("Could not get vm IP address")
示例7: 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))
示例8: 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)
示例9: _dhcp_operation
def _dhcp_operation(vca_client, network_name, operation):
"""
update dhcp setting for network
"""
dhcp_settings = ctx.node.properties["network"].get("dhcp")
if dhcp_settings is None:
return
gateway_name = ctx.node.properties["network"]["edge_gateway"]
gateway = vca_client.get_gateway(get_vcloud_config()["vdc"], gateway_name)
if not gateway:
raise cfy_exc.NonRecoverableError("Gateway {0} not found!".format(gateway_name))
if operation == ADD_POOL:
ip = _split_adresses(dhcp_settings["dhcp_range"])
low_ip_address = check_ip(ip.start)
hight_ip_address = check_ip(ip.end)
default_lease = dhcp_settings.get("default_lease")
max_lease = dhcp_settings.get("max_lease")
gateway.add_dhcp_pool(network_name, low_ip_address, hight_ip_address, default_lease, max_lease)
ctx.logger.info("DHCP rule successful created for network {0}".format(network_name))
if operation == DELETE_POOL:
gateway.delete_dhcp_pool(network_name)
ctx.logger.info("DHCP rule successful deleted for network {0}".format(network_name))
if not save_gateway_configuration(gateway, vca_client):
return ctx.operation.retry(message="Waiting for gateway.", retry_after=10)
示例10: _save_configuration
def _save_configuration(gateway, vca_client, operation, public_ip):
"""
save/refresh nat rules on gateway
"""
ctx.logger.info("Save NAT configuration.")
success = save_gateway_configuration(gateway, vca_client, ctx)
if not success:
return False
ctx.logger.info("NAT configuration has been saved.")
if operation == CREATE:
ctx.target.instance.runtime_properties[PUBLIC_IP] = public_ip
else:
service_type = get_vcloud_config().get('service_type')
if is_ondemand(service_type):
if not ctx.target.node.properties['nat'].get(PUBLIC_IP):
del_ondemand_public_ip(
vca_client, gateway,
ctx.target.instance.runtime_properties[PUBLIC_IP],
ctx
)
if PUBLIC_IP in ctx.target.instance.runtime_properties:
del ctx.target.instance.runtime_properties[PUBLIC_IP]
if PORT_REPLACEMENT in ctx.target.instance.runtime_properties:
del ctx.target.instance.runtime_properties[PORT_REPLACEMENT]
if SSH_PORT in ctx.target.instance.runtime_properties:
del ctx.target.instance.runtime_properties[SSH_PORT]
if SSH_PUBLIC_IP in ctx.target.instance.runtime_properties:
del ctx.target.instance.runtime_properties[SSH_PUBLIC_IP]
return True
示例11: create
def create(vca_client, **kwargs):
"""
create server by template,
if external_resource set return without creation,
e.g.:
{
'management_network': '_management_network',
'server': {
'template': 'template',
'catalog': 'catalog',
'guest_customization': {
'pre_script': 'pre_script',
'post_script': 'post_script',
'admin_password': 'pass',
'computer_name': 'computer'
}
}
}
"""
config = get_vcloud_config()
server = {
'name': ctx.instance.id,
}
server.update(ctx.node.properties.get('server', {}))
transform_resource_name(server, ctx)
if ctx.node.properties.get('use_external_resource'):
res_id = ctx.node.properties['resource_id']
ctx.instance.runtime_properties[VCLOUD_VAPP_NAME] = res_id
ctx.logger.info(
"External resource {0} has been used".format(res_id))
else:
_create(vca_client, config, server)
示例12: _get_gateway_name
def _get_gateway_name(properties):
security_group = properties.get('security_group')
if security_group and 'edge_gateway' in security_group:
getaway_name = security_group.get('edge_gateway')
else:
getaway_name = get_vcloud_config()['edge_gateway']
return getaway_name
示例13: _get_state
def _get_state(vca_client):
"""
check network connection availability for host
"""
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)
nw_connections = _get_vm_network_connections(vapp)
if len(nw_connections) == 0:
ctx.logger.info("No networks connected")
ctx.instance.runtime_properties['ip'] = None
ctx.instance.runtime_properties['networks'] = {}
return True
if not all([connection['ip'] for connection in nw_connections]):
ctx.logger.info("Network configuration is not finished yet.")
return False
ctx.instance.runtime_properties['networks'] = {
connection['network_name']: connection['ip']
for connection in nw_connections}
for connection in nw_connections:
if connection['is_primary']:
ctx.logger.info("Primary network ip address '{0}' for"
" network '{1}'."
.format(connection['ip'],
connection['network_name']))
ctx.instance.runtime_properties['ip'] = connection['ip']
return True
return False
示例14: 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)))
示例15: _floatingip_operation
def _floatingip_operation(operation, vca_client, ctx):
"""
create/release floating ip by nat rules for this ip with
relation to internal ip for current node,
save selected public_ip in runtime properties
"""
service_type = get_vcloud_config().get('service_type')
gateway = get_gateway(
vca_client, ctx.target.node.properties['floatingip']['edge_gateway'])
internal_ip = get_vm_ip(vca_client, ctx, gateway)
nat_operation = None
public_ip = (ctx.target.instance.runtime_properties.get(PUBLIC_IP)
or ctx.target.node.properties['floatingip'].get(PUBLIC_IP))
if operation == CREATE:
CheckAssignedInternalIp(internal_ip, gateway)
if public_ip:
CheckAssignedExternalIp(public_ip, gateway)
else:
public_ip = get_public_ip(vca_client, gateway, service_type, ctx)
nat_operation = _add_nat_rule
elif operation == DELETE:
if not public_ip:
ctx.logger.info("Can't get external IP".format(public_ip))
return True
nat_operation = _del_nat_rule
else:
raise cfy_exc.NonRecoverableError(
"Unknown operation {0}".format(operation)
)
external_ip = check_ip(public_ip)
nat_operation(gateway, "SNAT", internal_ip, external_ip)
nat_operation(gateway, "DNAT", external_ip, internal_ip)
success = save_gateway_configuration(gateway, vca_client, ctx)
if not success:
return False
if operation == CREATE:
ctx.target.instance.runtime_properties[PUBLIC_IP] = external_ip
save_ssh_parameters(ctx, '22', external_ip)
else:
if is_ondemand(service_type):
if not ctx.target.node.properties['floatingip'].get(PUBLIC_IP):
del_ondemand_public_ip(
vca_client,
gateway,
ctx.target.instance.runtime_properties[PUBLIC_IP],
ctx)
if PUBLIC_IP in ctx.target.instance.runtime_properties:
del ctx.target.instance.runtime_properties[PUBLIC_IP]
if SSH_PUBLIC_IP in ctx.source.instance.runtime_properties:
del ctx.source.instance.runtime_properties[SSH_PUBLIC_IP]
if SSH_PORT in ctx.target.instance.runtime_properties:
del ctx.source.instance.runtime_properties[SSH_PORT]
return True