Exemplo n.º 1
0
    def vmware_migrate(self, msg, args):
        """ Vmotion vm to a specific esx host
        Example:
            vmware migrate server1 esxhost2 
        """
        username = self.config['user']
        password = self.config['pass']
        vcenter = self.config['vcenter']
        vmname = args.pop(0)

        try:
            hostname = args.pop(0)
        except IndexError:
            hostname = None

        try:
            si = SmartConnect(host=vcenter, user=username, pwd=password, port=443)
        except:
            err_text = 'Error connecting to {0}'.format(vcenter)
            logging.info(err_text)
            return err_text

        if hostname:
            try:
                host = vmutils.get_host_by_name(si, hostname)
                hostname = host.name
            except:
                return '{0} not found'.format(hostname)
        else:
            # hostname was not passed
            all_hosts = vmutils.get_hosts(si)
            host = vmutils.get_host_by_name(si, random.choice(all_hosts.values()))
            hostname = host.name

        # Finding source VM
        try:
            vm = vmutils.get_vm_by_name(si, vmname)
        except:
            return '{0} not found.'.format(vmname)

        # relocate spec, to migrate to another host
        # this can do other things, like storage and resource pool
        # migrations
        relocate_spec = vim.vm.RelocateSpec(host=host)

        # does the actual migration to host
        vm.Relocate(relocate_spec)
        Disconnect(si)
        return 'Migrating {0} to {1}'.format(vmname, hostname)
Exemplo n.º 2
0
from pyVmomi import vim
import vmutils
import random

si = vmutils.connect()

vm_name = raw_input('test2')
esx_host = raw_input('192.168.50.14')

if esx_host == '':
    all_hosts = vmutils.get_hosts(si)
    esx_host = vmutils.get_host_by_name(si, random.choice(all_hosts.values()))
else:
    esx_host = vmutils.get_host_by_name(si, esx_host)

# Finding source VM
vm = vmutils.get_vm_by_name(si, vm_name)

# relocate spec, to migrate to another host
# this can do other things, like storage and resource pool
# migrations
relocate_spec = vim.vm.RelocateSpec(host=esx_host)

# does the actual migration to host
print vm.Relocate(relocate_spec)

#print "Vm Migrated Successfully"

vmutils.disconnect(si)
Exemplo n.º 3
0
import vmutils

# Connect to Vcenter
si = vmutils.connect()

host_name = raw_input("Enter the Host name: ")
host = vmutils.get_host_by_name(si, host_name)


def enter_maintanence_mode(host):
    host.EnterMaintenanceMode_Task(3000)
    print "Enter maintanence mode successfully"


def exit_maintanence_mode(host):
    host.ExitMaintenanceMode_Task(10)
    print "Exit maintanence mode successfully"


if __name__ == "__main__":
    exit_maintanence_mode(host)

# Disconnecting Vcenter
vmutils.disconnect(si)
Exemplo n.º 4
0
si = None
username = raw_input('Username: '******'Password: '******'vcenter: ')
vm_name = raw_input('VM: ')
esx_host = raw_input('ESX Host: ')

try:
    si = SmartConnect(host=vcenter, user=username, pwd=password, port=443)
except IOError, e:
    pass

if esx_host == '':
    all_hosts = vmutils.get_hosts(si)
    esx_host = vmutils.get_host_by_name(si, random.choice(all_hosts.values()))
else:
    esx_host = vmutils.get_host_by_name(si, esx_host)

# Finding source VM
vm = vmutils.get_vm_by_name(si, vm_name)

# relocate spec, to migrate to another host
# this can do other things, like storage and resource pool
# migrations
relocate_spec = vim.vm.RelocateSpec(host=esx_host)

# does the actual migration to host
vm.Relocate(relocate_spec)

Disconnect(si)
Exemplo n.º 5
0
    def vmware_migrate(self, msg, args):
        """ Vmotion vm to a specific esx host
        Example:
            vmware migrate server1 esxhost2
        """
        username = self.config['user']
        password = self.config['pass']
        vcenter = self.config['vcenter']
        vmname = args.pop(0)

        try:
            hostname = args.pop(0)
        except IndexError:
            hostname = None

        try:
            si = SmartConnect(host=vcenter,
                              user=username,
                              pwd=password,
                              port=443)
        except:
            err_text = 'Error connecting to {0}'.format(vcenter)
            log.info(err_text)
            self.send(msg.frm,
                      err_text,
                      message_type=msg.type,
                      in_reply_to=msg,
                      groupchat_nick_reply=True)
            return

        if hostname:
            try:
                host = vmutils.get_host_by_name(si, hostname)
                hostname = host.name
            except:
                self.send(msg.frm,
                          '{0} not found'.format(hostname),
                          message_type=msg.type,
                          in_reply_to=msg,
                          groupchat_nick_reply=True)
                return
        else:
            # hostname was not passed
            all_hosts = vmutils.get_hosts(si)
            host = vmutils.get_host_by_name(si,
                                            random.choice(all_hosts.values()))
            hostname = host.name

        # Finding source VM
        try:
            vm = vmutils.get_vm_by_name(si, vmname)
        except:
            self.send(msg.frm,
                      '{0} not found.'.format(vmname),
                      message_type=msg.type,
                      in_reply_to=msg,
                      groupchat_nick_reply=True)
            return

        # relocate spec, to migrate to another host
        # this can do other things, like storage and resource pool
        # migrations
        relocate_spec = vim.vm.RelocateSpec(host=host)

        # does the actual migration to host
        vm.Relocate(relocate_spec)
        Disconnect(si)
        self.send(msg.frm,
                  'Migrating {0} to {1}'.format(vmname, hostname),
                  message_type=msg.type,
                  in_reply_to=msg,
                  groupchat_nick_reply=True)