def vm_ipaddress(args, session): u"""Show ipaddress. @param args Commandline argument @param session Session """ # Import import lib import time vm = lib.get_vm(args.vm_name, session) vm_record = session.xenapi.VM.get_record(vm) if vm_record['is_a_template']: # Check template raise Exception('%s is template.' % args.vm_name) if vm_record['power_state'] != 'Running': # Check power state. raise Exception('Power state is %s.' % vm_record['power_state']) if vm_record['guest_metrics'].split(':')[1] == 'NULL': # Check xen tools raise Exception('Xen tools is not installed.') # Getting IP address. while lib.get_ip_address(vm, session): print 'wait...', time.sleep(args.wait_time) print '' print 'IP address : %s' % lib.get_ip_address(vm, session) print 'Done.'
def show_vm_list(args, session): u"""Show vm list @param args Commandline argumetn @param session Session """ # Import import lib # Get VMs vms = session.xenapi.VM.get_all() print print '| Name | Power | IP Address |' print '-------------------------------------------------------' for vm in vms: record = session.xenapi.VM.get_record(vm) condition = 'template' if args.template else 'plain' if vm_is_condition(record, condition, session): # Print VM print "| %20s " % record['name_label'], print "| %7s " % record['power_state'], tool_state = record['guest_metrics'].split(':')[1] print "| %16s |" % lib.get_ip_address(vm, session)