Exemplo n.º 1
0
def destroy(args, session):
    u"""Destroying VM

    @param args    Commandline argument
    @param session Session
    """
    # Import
    import lib

    vm_names = args.vm_names
    for vm_name in vm_names:
        # Set VM name
        vm = lib.get_vm(vm_name, session)
        if vm:
            try:
                print 'Destroying...'
                vdis = lib.get_storage_vdis(vm, session)
                if vdis:
                    for vdi in vdis:
                        try:
                            session.xenapi.VDI.destroy(vdi)
                            print 'VDI Done.'
                        except:
                            print 'Cannot destroy VDI.'

                session.xenapi.VM.destroy(vm)
                print '%s Done.' % vm_name
            except Exception, e:
                print 'Please shutdown for VM.'
        else:
            print 'Not found VM.'
Exemplo n.º 2
0
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.'
Exemplo n.º 3
0
def vm_install(args, session):
    u"""Install VM(use template)

    @param args    CommandLien argument
    @param session Session
    """
    # Import
    import lib

    vm_names = args.vm_names
    for vm_name in vm_names:
        if lib.get_vm(vm_name, session):
            print 'Already exist VM.'
        else:
            # Instal
            vm = lib.install(vm_name,
                             args.temp_name,
                             session)

            print '%s Done.' % vm_name

            # VM start
            print 'Starting...'
            try:
                session.xenapi.VM.start(vm, False, True)
            except:
                print 'Cannot started VM.'
Exemplo n.º 4
0
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.'
Exemplo n.º 5
0
def destroy(args, session):
    u"""Destroying VM

    @param args    Commandline argument
    @param session Session
    """
    # Import
    import lib

    vm_names = args.vm_names
    for vm_name in vm_names:
        # Set VM name
        vm = lib.get_vm(vm_name, session)
        if vm:
            try:
                print 'Destroying...'
                vdis = lib.get_storage_vdis(vm, session)
                if vdis:
                    for vdi in vdis:
                        try:
                            session.xenapi.VDI.destroy(vdi)
                            print 'VDI Done.'
                        except:
                            print 'Cannot destroy VDI.'

                session.xenapi.VM.destroy(vm)
                print '%s Done.' % vm_name
            except Exception, e:
                print 'Please shutdown for VM.'
        else:
            print 'Not found VM.'
Exemplo n.º 6
0
def vm_install(args, session):
    u"""Install VM(use template)

    @param args    CommandLien argument
    @param session Session
    """
    # Import
    import lib

    vm_names = args.vm_names
    for vm_name in vm_names:
        if lib.get_vm(vm_name, session):
            print 'Already exist VM.'
        else:
            # Instal
            vm = lib.install(vm_name, args.temp_name, session)

            print '%s Done.' % vm_name

            # VM start
            print 'Starting...'
            try:
                session.xenapi.VM.start(vm, False, True)
            except:
                print 'Cannot started VM.'
Exemplo n.º 7
0
def power(args, session):
    u"""Powered Management

    @param args    Commandline argument
    @param session Session
    """
    # Import
    import sys
    import lib

    vm_names = args.vm_names
    for vm_name in vm_names:
        # Get VM
        vm = lib.get_vm(vm_name, session)

        if vm:
            try:
                if args.power == 'ON':
                    # Powered on
                    lib.powered_on(vm, session)
                elif args.power == 'OFF':
                    # Powered off
                    lib.powered_off(vm, session)
                elif args.power == 'Reboot':
                    # Reboot
                    lib.reboot(vm, session)
                elif args.power == 'Suspend':
                    # Suspend
                    lib.suspend(vm, session)
                else:
                    # Pause
                    lib.pause(vm, session)
            except:
                print 'Power Error for VM.'
        else:
            print 'Not found VM.'
Exemplo n.º 8
0
def power(args, session):
    u"""Powered Management

    @param args    Commandline argument
    @param session Session
    """
    # Import
    import sys
    import lib

    vm_names = args.vm_names
    for vm_name in vm_names:
        # Get VM
        vm = lib.get_vm(vm_name, session)

        if vm:
            try:
                if args.power == 'ON':
                    # Powered on
                    lib.powered_on(vm, session)
                elif args.power == 'OFF':
                    # Powered off
                    lib.powered_off(vm, session)
                elif args.power == 'Reboot':
                    # Reboot
                    lib.reboot(vm, session)
                elif args.power == 'Suspend':
                    # Suspend
                    lib.suspend(vm, session)
                else:
                    # Pause
                    lib.pause(vm, session)
            except:
                print 'Power Error for VM.'
        else:
            print 'Not found VM.'