Example #1
0
def vm_vlandel():
    #Need power off the related vms firstly
    vm = VMware()
    vlan_list = str2list(vm.connect.value("vm.vlan"))
    vswitch = vm.connect.value("vm.vswitch")
    for vlan in vlan_list:
        vm.del_vswitch_portgroup(vswitch, vlan)
Example #2
0
def vm_vlanadd():
    vm = VMware()
    vlan_list = str2list(vm.connect.value("vm.vlan"))
    vswitch = vm.connect.value("vm.vswitch")
    int_reg = re.compile('\d+')
    for vlan in vlan_list:
        vm.add_vswitch_portgroup(vswitch, vlan)
        vlan_id = int(int_reg.search(vlan).group())
        vm.bind_portgroup_vlan(vlan, vlan_id)
Example #3
0
def vm_sub():
    vm = VMware()
    folder_path = vm.connect.value("vm.folder_path")
    name_list = str2list(vm.connect.value("vm.name"))
    is_serial = vm.connect.value("vm.is_serial")
    ser_list = str2list(vm.connect.value("vm.serial"))
    is_eth0 = vm.connect.value("vm.is_eth0")
    eth0_list = str2list(vm.connect.value("vm.eth0"))
    is_eth1 = vm.connect.value("vm.is_eth1")
    eth1_list = str2list(vm.connect.value("vm.eth1"))
    if len(name_list) != len(ser_list):
        raise ValueError, '''The length of vm.name "%s" and vm.serial "%s" is not the same''' % (
            str(name_list), str(ser_list))
    for name in name_list:
        vmx = (folder_path + '/' + name + '/' + name + '.vmx').replace(
            '//', '/')
        if is_serial != "false":
            ser = ser_list[name_list.index(name)]
            vm.sub_vm(vmx, sernum=ser)
        if is_eth0 != "false":
            if is_eth0 == "fix":
                eth0_list = [eth0_list[0]] * len(name_list)
            eth0 = eth0_list[name_list.index(name)]
            vm.sub_vm(vmx, eth0net=eth0)
        if is_eth1 != "false":
            if is_eth1 == "fix":
                eth1_list = [eth1_list[0]] * len(name_list)
            eth1 = eth1_list[name_list.index(name)]
            vm.sub_vm(vmx, eth1net=eth1)
Example #4
0
def vm_sub():
    vm = VMware()
    folder_path = vm.connect.value("vm.folder_path")
    name_list = str2list(vm.connect.value("vm.name"))
    is_serial = vm.connect.value("vm.is_serial")
    ser_list = str2list(vm.connect.value("vm.serial"))
    is_eth0 = vm.connect.value("vm.is_eth0")
    eth0_list = str2list(vm.connect.value("vm.eth0"))
    is_eth1 = vm.connect.value("vm.is_eth1")
    eth1_list = str2list(vm.connect.value("vm.eth1"))
    if len(name_list) != len(ser_list):
        raise ValueError, '''The length of vm.name "%s" and vm.serial "%s" is not the same''' % (str(name_list), str(ser_list))
    for name in name_list:
        vmx = (folder_path + '/' + name + '/' + name + '.vmx').replace('//', '/')
        if is_serial != "false": 
            ser = ser_list[name_list.index(name)]
            vm.sub_vm(vmx, sernum=ser)
        if is_eth0 != "false":
            if is_eth0 == "fix":
                eth0_list = [eth0_list[0]] * len(name_list)
            eth0 = eth0_list[name_list.index(name)]
            vm.sub_vm(vmx, eth0net=eth0)
        if is_eth1 != "false":
            if is_eth1 == "fix":
                eth1_list = [eth1_list[0]] * len(name_list)
            eth1 = eth1_list[name_list.index(name)]
            vm.sub_vm(vmx, eth1net=eth1)
Example #5
0
def vm_copy():
    vm = VMware()
    folder_path = vm.connect.value("vm.folder_path")
    src = vm.connect.value("vm.src")
    dst_list = str2list(vm.connect.value("vm.dst"))
    is_poweron = vm.connect.value("vm.is_poweron")
    for dst in dst_list:
        vm.copy_vm(folder_path, src, dst)
        vm.reg_vm(folder_path, dst + '/' + dst + '.vmx')
        if is_poweron == "true":
            vm.power_on_vm_via_vmname(dst)
Example #6
0
def vm_copy():
    vm = VMware()
    folder_path = vm.connect.value("vm.folder_path")
    src = vm.connect.value("vm.src")
    dst_list = str2list(vm.connect.value("vm.dst"))
    is_poweron = vm.connect.value("vm.is_poweron")
    for dst in dst_list:
        vm.copy_vm(folder_path, src, dst)
        vm.reg_vm(folder_path , dst + '/' + dst + '.vmx')
        if is_poweron == "true":
            vm.power_on_vm_via_vmname(dst)
Example #7
0
def vm_poweroff():
    vm = VMware()
    is_all = vm.connect.value("vm.is_all")
    is_id = vm.connect.value("vm.is_id")
    name_list = str2list(vm.connect.value("vm.name"))
    id_list = str2list(vm.connect.value("vm.id"))
    if is_all == "true":
        vm.power_off_vm_all()
    else:
        if is_id == "false":
            for vmname in name_list:
                vm.power_off_vm_via_vmname(vmname)
        elif is_id == "true":
            for vmid in id_list:
                vm.power_off_vm_via_vmid(vmid)
Example #8
0
def vm_vlanadd():
    vm = VMware()
    vlan_list = str2list(vm.connect.value("vm.vlan"))
    vswitch = vm.connect.value("vm.vswitch")
    int_reg = re.compile('\d+')
    for vlan in vlan_list:
        vm.add_vswitch_portgroup(vswitch, vlan)
        vlan_id = int(int_reg.search(vlan).group())
        vm.bind_portgroup_vlan(vlan, vlan_id)
Example #9
0
def vm_poweroff():
    vm = VMware()
    is_all = vm.connect.value("vm.is_all")
    is_id = vm.connect.value("vm.is_id")
    name_list = str2list(vm.connect.value("vm.name"))
    id_list = str2list(vm.connect.value("vm.id"))
    if is_all == "true":
        vm.power_off_vm_all()
    else:
        if is_id == "false":
            for vmname in name_list:
                vm.power_off_vm_via_vmname(vmname)
        elif is_id == "true":
            for vmid in id_list:
                vm.power_off_vm_via_vmid(vmid)
Example #10
0
def vm_db():
    vm = VMware()
    ip = vm.connect.ip
    sql_name = vm.connect.value("sql.name")
    sql_ip = vm.connect.value("sql.ip")
    sql_user = vm.connect.value("sql.user")
    sql_passwd = vm.connect.value("sql.passwd")
    con = MySQLdb.connect(host=sql_ip, user=sql_user, passwd=sql_passwd)
    cursor = con.cursor()
    cursor.execute("create database if not exists vmware")
    con.select_db('vmware')
    '''
    power:   0/1 off/on
    flag:    0/1 unactive/active
    '''
    create_table_cli = "create table if not exists %s (vmid char(10) not null primary key,\
                      display varchar(200),register varchar(200),power char(1),flag char(1))" % sql_name
    cursor.execute(create_table_cli)
    db_sync(vm, con, cursor, sql_name)
    cursor.close()
Example #11
0
def vm_del():
    vm = VMware()
    folder_path = vm.connect.value("vm.folder_path")
    name_list = str2list(vm.connect.value("vm.name"))
    is_all = vm.connect.value("vm.is_all")
    if is_all == "true":
        vm.power_off_vm_all()
        vm.unreg_vm_all(folder_path)
        vm.del_vm_all(folder_path)
    else:
        for name in name_list:
            vm.power_off_vm_via_vmname(name)
            #disname will transfer to regname in back
            vm.unreg_vm(folder_path, name)
            vm.del_vm(folder_path, name)