本文整理汇总了Python中utils.providers.get_mgmt函数的典型用法代码示例。如果您正苦于以下问题:Python get_mgmt函数的具体用法?Python get_mgmt怎么用?Python get_mgmt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_mgmt函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_mgmt_system
def get_mgmt_system(self):
""" Returns the mgmt_system using the :py:func:`utils.providers.get_mgmt` method.
"""
# gotta stash this in here to prevent circular imports
from utils.providers import get_mgmt
if self.key:
return get_mgmt(self.key)
elif getattr(self, 'provider_data', None):
return get_mgmt(self.provider_data)
else:
raise ProviderHasNoKey('Provider %s has no key, so cannot get mgmt system')
示例2: run
def run(**kwargs):
"""Calls the functions needed to cleanup templates on RHEVM providers.
This is called either by template_upload_all script, or by main
function.
Args:
**kwargs: Kwargs generated from
cfme_data['template_upload']['template_upload_rhevm'].
"""
providers = cfme_data["management_systems"]
for provider in providers:
if cfme_data["management_systems"][provider]["type"] != "rhevm":
continue
if args.provider:
if args.provider != provider:
continue
mgmt_sys = cfme_data["management_systems"][provider]
ssh_rhevm_creds = mgmt_sys["hosts"][0]["credentials"]
sshname = credentials[ssh_rhevm_creds]["username"]
sshpass = credentials[ssh_rhevm_creds]["password"]
api = get_mgmt(provider)
edomain = get_edomain(api)
if args.edomain:
edomain = args.edomain
path, edomain_ip = get_edomain_path(api, edomain)
try:
print "\n--------Start of {}--------".format(provider)
change_edomain_state(api, "maintenance", edomain)
cleanup_templates(api, edomain, args.days_old, args.max_templates)
finally:
cleanup_empty_dir_on_edomain(path, edomain_ip, sshname, sshpass)
change_edomain_state(api, "active", edomain)
print "--------End of {}--------\n".format(provider)
示例3: process_provider_vms
def process_provider_vms(provider_key, matchers, delta, vms_to_delete):
with lock:
print '{} processing'.format(provider_key)
try:
now = datetime.datetime.now()
with lock:
# Known conf issue :)
provider = get_mgmt(provider_key)
for vm_name in provider.list_vm():
if not match(matchers, vm_name):
continue
try:
vm_creation_time = provider.vm_creation_time(vm_name)
except:
logger.error('Failed to get creation/boot time for %s on %s' % (
vm_name, provider_key))
continue
if vm_creation_time + delta < now:
vm_delta = now - vm_creation_time
with lock:
vms_to_delete[provider_key].add((vm_name, vm_delta))
with lock:
print '{} finished'.format(provider_key)
except Exception as ex:
with lock:
# Print out the error message too because logs in the job get deleted
print '{} failed ({}: {})'.format(provider_key, type(ex).__name__, str(ex))
logger.error('failed to process vms from provider %s', provider_key)
logger.exception(ex)
示例4: get_datastores_per_host
def get_datastores_per_host(provider_key):
print('{} processing to get datastores per host'.format(provider_key))
try:
provider = get_mgmt(provider_key)
vm_registered_files = get_registered_vm_files(provider_key)
hosts = provider.list_host()
host_datastore_url = {host: provider.list_host_datastore_url(host) for host in hosts}
unregistered_files = []
print("\n*********************UNREGISTERED FILES ON: {}**********************\n".format(
provider_key))
print('HOST_NAME\t\tFILE_PATH\t\tTEMPLATE_VM_ISO\t\tNUMBER_OF_FILES\n')
for host in host_datastore_url:
try:
list_orphaned_files_per_host(host, host_datastore_url[host],
provider_key, vm_registered_files,
unregistered_files)
except Exception as e:
logger.error(e)
continue
except Exception as ex:
# Print out the error message too because logs in the job get deleted
print('{} failed ({}: {})'.format(provider_key, type(ex).__name__, str(ex)))
logger.error('failed to process vms from provider {}'.format(provider_key))
logger.exception(ex)
示例5: scan_provider
def scan_provider(provider_key, matchers, match_queue, scan_failure_queue):
"""
Process the VMs on a given provider, comparing name and creation time.
Append vms meeting criteria to vms_to_delete
Args:
provider_key (string): the provider key from yaml
matchers (list): A list of regex objects with match() method
match_queue (Queue.Queue): MP queue to hold VMs matching age requirement
scan_failure_queue (Queue.Queue): MP queue to hold vms that we could not compare age
Returns:
None: Uses the Queues to 'return' data
"""
logger.info('%s: Start scan for vm text matches', provider_key)
try:
vm_list = get_mgmt(provider_key).list_vm()
except Exception: # noqa
scan_failure_queue.put(VmReport(provider_key, FAIL, NULL, NULL, NULL))
logger.exception('%s: Exception listing vms', provider_key)
return
text_matched_vms = [name for name in vm_list if match(matchers, name)]
for name in text_matched_vms:
match_queue.put(VmProvider(provider_key, name))
non_text_matching = set(vm_list) - set(text_matched_vms)
logger.info('%s: NOT matching text filters: %s', provider_key, non_text_matching)
logger.info('%s: MATCHED text filters: %s', provider_key, text_matched_vms)
示例6: cu_vm
def cu_vm(provider, vm_name, template):
"""
Deploys CU VM
"""
provider_dict = cfme_data['management_systems'][provider]
# TODO this key isn't in cfme qe yamls
datastore = provider_dict['cap_and_util']['allowed_datastores']
resource_pool = provider_dict['cap_and_util']['resource_pool']
# TODO methods deploy_template calls don't accept resourcepool and allowed_datastores as kwargs
deploy_template(provider, vm_name, template,
resourcepool=resource_pool, allowed_datastores=datastore)
prov_mgmt = get_mgmt(provider)
vm_running(prov_mgmt, vm_name)
ip = prov_mgmt.get_ip_address(vm_name)
# TODO this key isn't in cfme qe yamls
vm_ssh_creds = provider_dict['capandu_vm_creds']
sshname = credentials[vm_ssh_creds]['username']
sshpass = credentials[vm_ssh_creds]['password']
# Create cron jobs to generate disk and network activity on the CU VM.
with make_ssh_client(ip, sshname, sshpass) as ssh_client:
try:
config_cu_vm(ssh_client)
except CUCommandException:
_vm_cleanup(prov_mgmt, vm_name)
raise
vm_running(prov_mgmt, vm_name)
示例7: get_registered_vm_files
def get_registered_vm_files(provider_key):
try:
print("{} processing all the registered files..".format(provider_key))
vm_registered_files = defaultdict(set)
provider = get_mgmt(provider_key)
for vm_name in provider.list_vm():
try:
vm_file_path = provider.get_vm_config_files_path(vm_name)
vm_directory_name = re.findall(r'\s(.*)/\w*', vm_file_path)
vm_registered_files[vm_directory_name[0]] = vm_name
except Exception as e:
logger.error(e)
logger.error('Failed to get creation/boot time for {} on {}'.format(
vm_name, provider_key))
continue
print("\n**************************REGISTERED FILES ON {}***********************\n".format(
provider_key))
for k, v in vm_registered_files.items():
print('FILE_NAME: {}\nVM_NAME: {}\n'.format(k, v))
return vm_registered_files
except Exception as ex:
# Print out the error message too because logs in the job get deleted
print('{} failed ({}: {})'.format(provider_key, type(ex).__name__, str(ex)))
logger.error('failed to process vms from provider {}'.format(provider_key))
logger.exception(ex)
示例8: power_state
def power_state(request, current_provider):
if not request.user.is_authenticated() or not request.user.is_superuser:
return go_home(request)
vm_name = request.POST["vm_name"]
manager = get_mgmt(current_provider)
state = Appliance.POWER_STATES_MAPPING.get(manager.vm_status(vm_name), "unknown")
return HttpResponse(state, content_type="text/plain")
示例9: process_provider_vms
def process_provider_vms(provider_key, matchers, delta, vms_to_delete):
with lock:
print "%s processing" % provider_key
try:
now = datetime.datetime.now()
provider = get_mgmt(provider_key)
for vm_name in provider.list_vm():
if not match(matchers, vm_name):
continue
try:
vm_creation_time = provider.vm_creation_time(vm_name)
except:
logger.error("Failed to get creation/boot time for %s on %s" % (vm_name, provider_key))
continue
if vm_creation_time + delta < now:
vm_delta = now - vm_creation_time
with lock:
vms_to_delete[provider_key].add((vm_name, vm_delta))
with lock:
print "%s finished" % provider_key
except Exception as ex:
with lock:
print "%s failed" % provider_key
logger.error("failed to process vms from provider %s", provider_key)
logger.exception(ex)
示例10: cu_vm
def cu_vm(provider, vm_name, template):
"""
Deploys CU VM
"""
provider_dict = cfme_data["management_systems"][provider]
datastore = provider_dict["cap_and_util"]["allowed_datastores"]
resource_pool = provider_dict["cap_and_util"]["resource_pool"]
deploy_template(provider, vm_name, template, resourcepool=resource_pool, allowed_datastores=datastore)
prov_mgmt = get_mgmt(provider)
vm_running(prov_mgmt, vm_name)
ip = prov_mgmt.get_ip_address(vm_name)
vm_ssh_creds = provider_dict["capandu_vm_creds"]
sshname = credentials[vm_ssh_creds]["username"]
sshpass = credentials[vm_ssh_creds]["password"]
# Create cron jobs to generate disk and network activity on the CU VM.
ssh_client = make_ssh_client(ip, sshname, sshpass)
try:
config_cu_vm(ssh_client)
except CUCommandException:
_vm_cleanup(prov_mgmt, vm_name)
raise
vm_running(prov_mgmt, vm_name)
示例11: power_state_buttons
def power_state_buttons(request, current_provider):
manager = get_mgmt(current_provider)
vm_name = request.POST["vm_name"]
power_state = request.POST["power_state"]
can_power_on = power_state in {Appliance.Power.SUSPENDED, Appliance.Power.OFF}
can_power_off = power_state in {Appliance.Power.ON}
can_suspend = power_state in {Appliance.Power.ON} and manager.can_suspend
can_delete = power_state in {Appliance.Power.OFF}
return render(request, 'appliances/vms/_buttons.html', locals())
示例12: vms_table
def vms_table(request, current_provider=None):
if not request.user.is_authenticated() or not request.user.is_superuser:
return go_home(request)
try:
manager = get_mgmt(current_provider)
vms = sorted(manager.list_vm())
return render(request, 'appliances/vms/_list.html', locals())
except Exception as e:
return HttpResponse('{}: {}'.format(type(e).__name__, str(e)), content_type="text/plain")
示例13: list_vms
def list_vms(provider_key, output_queue):
"""
List all the vms/instances on the given provider key
Build list of lists with basic vm info: [[provider, vm, status, age, type], [etc]]
:param provider_key: string provider key
:param output_queue: a multiprocessing.Queue object to add results to
:return: list of lists of vms and basic statistics
"""
output_list = []
print('Listing VMS on provider {}'.format(provider_key))
provider = get_mgmt(provider_key)
try:
vm_list = provider.list_vm()
except NotImplementedError:
print('Provider does not support list_vm: {}'.format(provider_key))
output_list.append([provider_key, 'Not Supported', NULL, NULL, NULL])
return
else:
# TODO thread metadata collection for further speed improvements
for vm_name in vm_list:
# Init these meta values in case they fail to query
status, creation, vm_type = None, None, None
try:
print('Collecting metadata for VM {} on provider {}'.format(vm_name, provider_key))
# VMError raised for some vms in bad status
# exception message contains useful information about VM status
try:
status = provider.vm_status(vm_name)
except VMError as ex:
status = ex.message
creation = provider.vm_creation_time(vm_name)
# different provider types implement different methods to get instance type info
try:
vm_type = provider.vm_type(vm_name)
except (AttributeError, NotImplementedError):
vm_type = provider.vm_hardware_configuration(vm_name)
finally:
vm_type = vm_type or '--'
output_list.append([provider_key, vm_name, status, creation, str(vm_type)])
except Exception as ex:
print('Exception during provider processing on {}: {}'
.format(provider_key, ex.message))
# Add the VM to the list anyway, we just might not have all metadata
output_list.append([provider_key,
vm_name,
status or NULL,
creation or NULL,
str(vm_type) or NULL])
continue
output_queue.put(output_list)
return
示例14: call_provider
def call_provider(provider_name, action, *args, **kwargs):
# Given a provider class, find the named method and call it with
# *args. This could possibly be generalized for other CLI tools.
provider = get_mgmt(provider_name)
try:
call = getattr(provider, action)
except AttributeError:
raise Exception('Action {} not found'.format(repr(action)))
return call(*args, **kwargs)
示例15: main
def main():
parser = argparse.ArgumentParser(epilog=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('--provider', dest='provider_name', help='provider name in cfme_data')
parser.add_argument('--vm_name', help='the name of the VM on which to act')
parser.add_argument('--remove', help='remove disk from vm', action="store_true")
args = parser.parse_args()
provider = get_mgmt(args.provider_name)
provider.connect_direct_lun_to_appliance(args.vm_name, args.remove)