예제 #1
0
 def aruba(cls, dc, username, password, netname, attach=None, servername=None):
     global token
     if dc in range(1, 6, 1):
         token = CloudInterface(dc=dc)
     token.login(username=username, password=password, load=True)
     vlan = token.purchase_vlan(vlan_name=netname)
     if attach:
         vmid = token.vmlist.find(servername)[0]
         netif = token.get_server_detail(server_id=vmid)['NetworkAdapters'][1]
         token.attach_vlan(network_adapter_id=netif['id'], vlan_resource_id=vlan.resource_id)
예제 #2
0
    parser.add_argument('-d', '--datacenter', help='Specify datacenter to login.', action='store', dest='dc')
    parser.add_argument('-u', '--username', help='Specify username.', action='store', dest='username')
    parser.add_argument('-w', '--password', help='Specify password.', action='store', dest='password')
    parser.add_argument('-t', '--template', help='Specify template.', action='store', dest='template')
    parser.add_argument('--vlan-name', help='Specify vSwitch Name.', action='store', dest='vlan_name')
    parser.add_argument('--vm-name', help='Name of the VM to attach the new VLAN.', action='store', dest='vm_name')
    p = parser.parse_args()

    i = CloudInterface(dc=p.dc)
    i.login(username=p.username, password=p.password, load=True)

    # create new vlan (virtual switch)
    vlan = i.purchase_vlan(p.vlan_name)

    # find the vm object
    vm = i.vmlist.find(p.vm_name)[0]
    # find the network adapter object
    network_adapter = i.get_server_detail(server_id=vm.sid)['NetworkAdapters'][1]
    # attach the network adapter to the created vlan
    i.attach_vlan(network_adapter_id=network_adapter['Id'], vlan_resource_id=vlan.resource_id)

    # retrieve every vlan in the datacenter and remove them
    raw_input(
        "You are going to delete every VLAN in Datacenter: {}, press any key to continue (CTRL+C to abort)".format(
            p.dc
        )
    )
    vlans = i.get_vlan()
    for vlan in vlans:
        i.remove_vlan(vlan.resource_id)
예제 #3
0
import time

from ArubaCloud.PyArubaAPI import CloudInterface

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("-d", "--datacenter", help="Specify datacenter to login.", action="store", type=int, dest="dc")
    parser.add_argument("-p", "--pattern", help="Specify pattern to search.", action="store", dest="pattern")
    parser.add_argument("-u", "--username", help="Specify username.", action="store", dest="username")
    parser.add_argument("-w", "--password", help="Specify password.", action="store", dest="password")
    p = parser.parse_args()

    i = CloudInterface(dc=p.dc)
    i.login(username=p.username, password=p.password, load=True)

    i.get_servers()

    maxretries = 5
    for vm in i.vmlist.find(name=p.pattern):
        if vm.status == 3:
            vm.poweroff()
        for w in range(maxretries):
            server_detail = i.get_server_detail(server_id=vm.sid)
            if server_detail["ServerStatus"] == 2:
                break
            else:
                print("Waiting shutdown")
                time.sleep(5)

        i.delete_vm(server_id=vm.sid)
예제 #4
0
                        action='store',
                        dest='vlan_name')
    parser.add_argument('--vm-name',
                        help='Name of the VM to attach the new VLAN.',
                        action='store',
                        dest='vm_name')
    p = parser.parse_args()

    i = CloudInterface(dc=p.dc)
    i.login(username=p.username, password=p.password, load=True)

    # create new vlan (virtual switch)
    vlan = i.purchase_vlan(p.vlan_name)

    # find the vm object
    vm = i.vmlist.find(p.vm_name)[0]
    # find the network adapter object
    network_adapter = i.get_server_detail(
        server_id=vm.sid)['NetworkAdapters'][0]
    # attach the network adapter to the created vlan
    i.attach_vlan(network_adapter_id=network_adapter['Id'],
                  vlan_resource_id=vlan.resource_id)

    # retrieve every vlan in the datacenter and remove them
    raw_input(
        "You are going to delete every VLAN in Datacenter: {}, press any key to continue (CTRL+C to abort)"
        .format(p.dc))
    vlans = i.get_vlan()
    for vlan in vlans:
        i.remove_vlan(vlan.resource_id)
예제 #5
0
    i.get_servers()

    poweroff_check = 0
    maxretries = 5
    sleep_for = 5
    attempts = 0
    for vm in i.vmlist.find(name=p.pattern):
        if vm.status == 3:
            print('Turn off VM: %s' % vm.vm_name)
            vm.poweroff()
            poweroff_check = 1
            time.sleep(sleep_for)
            for w in range(maxretries):
                attempts += 1
                server_detail = i.get_server_detail(server_id=vm.sid)
                if server_detail['ServerStatus'] == 2:
                    break
                else:
                    print('Waiting shutdown for other %s seconds' % sleep_for)
                    time.sleep(sleep_for)

        if attempts < maxretries:
            if poweroff_check == 0:
                print('VM %s is already Off. Starting...' % vm.vm_name)
            else:
                print('Restarting VM %s' % vm.vm_name)
            attempts = 0
            vm.poweron()
            time.sleep(sleep_for)
            for w in range(maxretries):