def run(self, params, args): file, = self.fillParams([("file", None)]) hosts = self.getHostnames(args) if len(hosts) < 1: self.abort("must supply host") if file and len(hosts) > 1: self.abort('if you supply the "file" parameter, ' + "then you only can specify one VM host") vm = rocks.vm.VM(self.db) for host in hosts: physhost = vm.getPhysHost(host) if not file: diskprefix = vm.getLargestPartition(physhost) if diskprefix: file = os.path.join(diskprefix, "xen/disks/%s.saved" % host) if physhost and file: # # send the restore command to the physical node # import rocks.vmconstant hipervisor = libvirt.open(rocks.vmconstant.connectionURL % physhost) hipervisor.restore(file)
def run(self, params, args): file, = self.fillParams( [('file', None)] ) hosts = self.getHostnames(args) if len(hosts) < 1: self.abort('must supply host') if file and len(hosts) > 1: self.abort('if you supply the "file" parameter, ' + 'then you only can specify one VM host') vm = rocks.vm.VM(self.db) for host in hosts: physhost = vm.getPhysHost(host) if not file: diskprefix = vm.getLargestPartition(physhost) if diskprefix: file = os.path.join(diskprefix, 'xen/disks/%s.saved' % host) if physhost and file: # # send the restore command to the physical node # import rocks.vmconstant hipervisor = libvirt.open( rocks.vmconstant.connectionURL % physhost) hipervisor.restore(file)
def run(self, params, args): file, = self.fillParams( [('file', None)] ) hosts = self.getHostnames(args) if len(hosts) < 1: self.abort('must supply host') if file and len(hosts) > 1: self.abort('if you supply the "file" parameter, ' + 'then you only can specify one VM host') import rocks.vm vm = rocks.vm.VM(self.db) for host in hosts: physhost = vm.getPhysHost(host) if not file: diskprefix = vm.getLargestPartition(physhost) if diskprefix: file = os.path.join(diskprefix, 'kvm/disks/%s.saved' % host) # # we need to start vlan interface if any # self.command('sync.host.vlan', [host]) if physhost and file: # # send the restore command to the physical node # import rocks.vmconstant hipervisor = libvirt.open( rocks.vmconstant.connectionURL % physhost) hipervisor.restore(file)
def run(self, params, args): file, = self.fillParams( [('file', None)] ) hosts = self.getHostnames(args) if len(hosts) < 1: self.abort('must supply host') if file and len(hosts) > 1: self.abort('if you supply the "file" parameter, ' + 'then you only can specify one VM host') import rocks.vm vm = rocks.vm.VM(self.db) for host in hosts: physhost = vm.getPhysHost(host) if not physhost: continue if not file: diskprefix = vm.getLargestPartition(physhost) if diskprefix: # # create a default file name # file = os.path.join(os.path.join( diskprefix, 'kvm/disks'), '%s.saved' % host) if physhost and file: # # send the save command to the physical node # import rocks.vmconstant hipervisor = libvirt.open( rocks.vmconstant.connectionURL % physhost) domU = hipervisor.lookupByName(host) domU.save(file)
def run(self, params, args): file, = self.fillParams([('file', None)]) hosts = self.getHostnames(args) if len(hosts) < 1: self.abort('must supply host') if file and len(hosts) > 1: self.abort('if you supply the "file" parameter, ' + 'then you only can specify one VM host') import rocks.vm vm = rocks.vm.VM(self.db) for host in hosts: physhost = vm.getPhysHost(host) if not physhost: continue if not file: diskprefix = vm.getLargestPartition(physhost) if diskprefix: # # create a default file name # file = os.path.join(os.path.join(diskprefix, 'kvm/disks'), '%s.saved' % host) if physhost and file: # # send the save command to the physical node # import rocks.vmconstant hipervisor = libvirt.open(rocks.vmconstant.connectionURL % physhost) domU = hipervisor.lookupByName(host) domU.save(file)
def run(self, params, args): (args, tophyshost) = self.fillPositionalArgs(('physhost', )) file, = self.fillParams([('file', None)]) if len(args) != 1: self.abort('must supply only one VM host') vm = rocks.vm.VM(self.db) # # validate the 'to' physical host name # h = self.getHostnames([tophyshost]) hosts = self.getHostnames(args) host = hosts[0] fromphyshost = vm.getPhysHost(host) if tophyshost == fromphyshost: self.abort("The source physical host, and the destination " + "host are the same: " + tophyshost) if not file: filename = '%s.saved' % host fromdiskprefix = vm.getLargestPartition(fromphyshost) fromdir = os.path.join(fromdiskprefix, 'kvm/disks') fromsavefile = os.path.join(fromdir, filename) else: fromsavefile = file print "Saving the VM's current state." # # save the VM's running state # self.command('save.host.vm', [host, "file=%s" % fromsavefile]) # # copy the VM save file to the physical node # running state # todiskprefix = vm.getLargestPartition(tophyshost) todir = os.path.join(todiskprefix, 'kvm/disks') tosavefile = os.path.join(todir, filename) #make the directory #I can not use run.command cos it doesn't return the exit status cmd = preparedir % (tophyshost, tosavefile) debug = os.system(cmd) if debug != 0: self.abort( "Unabled to create destination directory on physical host, " + tophyshost) #copy the file cmd = copycmd % (fromphyshost, fromsavefile, tophyshost, tosavefile) debug = os.system(cmd) if debug != 0: self.abort("Unabled to copy vm state on the new physical host, " + tophyshost) # # copy the VMs disks to the 'from' host # rows = self.db.execute("""select vn.id from vm_nodes vn, nodes n where n.name = "%s" and vn.node = n.id""" % host) if rows < 1: return vmnodeid, = self.db.fetchone() rows = self.db.execute("""select vbd_type, prefix, name from vm_disks where vm_node = %s""" % vmnodeid) if rows > 0: for vbd_type, prefix, name in self.db.fetchall(): if vbd_type not in ['tap:aio', 'file']: continue print "Copying VM disk file to %s." % tophyshost filename = os.path.join(prefix, name) print "Moving virtual disk (%s) to %s" % \ (filename, tophyshost) toprefix = vm.getLargestPartition(tophyshost) todir = os.path.join(toprefix, 'kvm/disks') tofile = os.path.join(todir, name) #make the directory cmd = preparedir % (tophyshost, tofile) debug = os.system(cmd) if debug != 0: self.abort("Unabled to create destination " + "directory on physical host, " + tophyshost) #copy the file cmd = copycmd % (fromphyshost, filename, tophyshost, tofile) debug = os.system(cmd) if debug != 0: self.abort("Unabled to copy vm state on the new " + "physical host, " + tophyshost) # # update the disk specification in the database # self.db.execute("""update vm_disks set prefix = "%s" where vm_node = %s""" % (todir, vmnodeid)) # # update which physical node now houses this VM # rows = self.db.execute("""select id from nodes where name = "%s" """ % (tophyshost)) if rows < 1: return physhostid, = self.db.fetchone() self.db.execute("""update vm_nodes set physnode = %s where id = %s """ % (physhostid, vmnodeid)) # # update vlan on physhostid if it is not already present # rows = self.db.execute( """select vlanid from networks as net, nodes as n where n.id = net.node and n.name='%s'""" % host) if rows < 1: self.abort("Unable to find vlanid for host " + host) vlanid, = self.db.fetchone() if vlanid != None: # we are moving a virtual cluster node # hence we need to move its' vlan as well rows = self.db.execute("""select sub.name from networks as net, nodes as n, subnets sub where n.name='%s' and net.vlanid=%s and n.id=net.node and sub.id=net.subnet""" % (tophyshost, vlanid)) if rows < 1: self.abort("Unable to find subnet for host migration") subnet, = self.db.fetchone() self.addVlanToHost(tophyshost, vlanid, subnet) # # restore the VM's running state # print "Restarting the VM on %s." % (tophyshost) self.command('restore.host.vm', [host, "file=%s" % tosavefile])
def run(self, params, args): (args, tophyshost) = self.fillPositionalArgs(('physhost', )) file, = self.fillParams( [('file', None)] ) if len(args) != 1: self.abort('must supply only one VM host') vm = rocks.vm.VM(self.db) # # validate the 'to' physical host name # h = self.getHostnames([ tophyshost ]) hosts = self.getHostnames(args) host = hosts[0] fromphyshost = vm.getPhysHost(host) if tophyshost == fromphyshost: self.abort("The source physical host, and the destination " + "host are the same: " + tophyshost) if not file: filename = '%s.saved' % host fromdiskprefix = vm.getLargestPartition(fromphyshost) fromdir = os.path.join(fromdiskprefix, 'kvm/disks') fromsavefile = os.path.join(fromdir, filename) else: fromsavefile = file print "Saving the VM's current state." # # save the VM's running state # self.command('save.host.vm', [ host, "file=%s" % fromsavefile] ) # # copy the VM save file to the physical node # running state # todiskprefix = vm.getLargestPartition(tophyshost) todir = os.path.join(todiskprefix, 'kvm/disks') tosavefile = os.path.join(todir, filename) #make the directory #I can not use run.command cos it doesn't return the exit status cmd = preparedir % (tophyshost, tosavefile) debug = os.system(cmd) if debug != 0 : self.abort("Unabled to create destination directory on physical host, " + tophyshost) #copy the file cmd = copycmd % (fromphyshost, fromsavefile, tophyshost, tosavefile) debug = os.system(cmd) if debug != 0 : self.abort("Unabled to copy vm state on the new physical host, " + tophyshost) # # copy the VMs disks to the 'from' host # rows = self.db.execute("""select vn.id from vm_nodes vn, nodes n where n.name = "%s" and vn.node = n.id""" % host) if rows < 1: return vmnodeid, = self.db.fetchone() rows = self.db.execute("""select vbd_type, prefix, name from vm_disks where vm_node = %s""" % vmnodeid) if rows > 0: for vbd_type, prefix, name in self.db.fetchall(): if vbd_type not in [ 'tap:aio', 'file' ]: continue print "Copying VM disk file to %s." % tophyshost filename = os.path.join(prefix, name) print "Moving virtual disk (%s) to %s" % \ (filename, tophyshost) toprefix = vm.getLargestPartition(tophyshost) todir = os.path.join(toprefix, 'kvm/disks') tofile = os.path.join(todir, name) #make the directory cmd = preparedir % (tophyshost, tofile) debug = os.system(cmd) if debug != 0 : self.abort("Unabled to create destination " +"directory on physical host, " + tophyshost) #copy the file cmd = copycmd % (fromphyshost, filename, tophyshost, tofile) debug = os.system(cmd) if debug != 0 : self.abort("Unabled to copy vm state on the new " + "physical host, " + tophyshost) # # update the disk specification in the database # self.db.execute("""update vm_disks set prefix = "%s" where vm_node = %s""" % (todir, vmnodeid)) # # update which physical node now houses this VM # rows = self.db.execute("""select id from nodes where name = "%s" """ % (tophyshost)) if rows < 1: return physhostid, = self.db.fetchone() self.db.execute("""update vm_nodes set physnode = %s where id = %s """ % (physhostid, vmnodeid)) # # update vlan on physhostid if it is not already present # rows = self.db.execute("""select vlanid from networks as net, nodes as n where n.id = net.node and n.name='%s'""" % host) if rows < 1: self.abort("Unable to find vlanid for host " + host) vlanid, = self.db.fetchone() if vlanid != None: # we are moving a virtual cluster node # hence we need to move its' vlan as well rows = self.db.execute("""select sub.name from networks as net, nodes as n, subnets sub where n.name='%s' and net.vlanid=%s and n.id=net.node and sub.id=net.subnet""" % (tophyshost, vlanid)) if rows < 1: self.abort("Unable to find subnet for host migration") subnet, = self.db.fetchone() self.addVlanToHost(tophyshost, vlanid, subnet) # # restore the VM's running state # print "Restarting the VM on %s." % (tophyshost) self.command('restore.host.vm', [ host, "file=%s" % tosavefile])
def run(self, params, args): (args, tophyshost) = self.fillPositionalArgs(('physhost', )) file, = self.fillParams( [('file', None)] ) if len(args) != 1: self.abort('must supply only one VM host') vm = rocks.vm.VM(self.db) # # validate the 'to' physical host name # h = self.getHostnames([ tophyshost ]) hosts = self.getHostnames(args) host = hosts[0] fromphyshost = vm.getPhysHost(host) if not file: filename = '%s.saved' % host fromdiskprefix = vm.getLargestPartition(fromphyshost) fromdir = os.path.join(fromdiskprefix, 'xen/disks') fromsavefile = os.path.join(fromdir, filename) else: fromsavefile = file print "Saving the VM's current state." # # save the VM's running state # self.command('save.host.vm', [ host, "file=%s" % fromsavefile] ) fromsavefilestat = self.command('run.host', [ fromphyshost, statcmd % fromsavefile ]).strip() print "Copying the VM's current state to %s." % (tophyshost) # # copy the VM save file to the physical node # running state # todiskprefix = vm.getLargestPartition(tophyshost) todir = os.path.join(todiskprefix, 'xen/disks') tosavefile = os.path.join(todir, filename) cmd = copyfile % (fromphyshost, fromsavefile, fromsavefilestat, tosavefile) debug = self.command('run.host', [ tophyshost, 'command=%s' % cmd ]) # # copy the VMs disks to the 'from' host # rows = self.db.execute("""select vn.id from vm_nodes vn, nodes n where n.name = "%s" and vn.node = n.id""" % host) if rows < 1: return vmnodeid, = self.db.fetchone() rows = self.db.execute("""select vbd_type, prefix, name from vm_disks where vm_node = %s""" % vmnodeid) if rows > 0: for vbd_type, prefix, name in self.db.fetchall(): if vbd_type not in [ 'tap:aio', 'file' ]: continue print "Copying VM disk file to %s." % tophyshost filename = os.path.join(prefix, name) filestat = self.command('run.host', [ fromphyshost, statcmd % filename ]).strip() print "Moving virtual disk (%s) to %s" % \ (filename, tophyshost) toprefix = vm.getLargestPartition(tophyshost) todir = os.path.join(toprefix, 'xen/disks') tofile = os.path.join(todir, name) cmd = copyfile % (fromphyshost, filename, filestat, tofile) debug = self.command('run.host', [ tophyshost, 'command=%s' % cmd ]) # print 'run.host output: ', debug # # update the disk specification in the database # self.db.execute("""update vm_disks set prefix = "%s" where vm_node = %s""" % (todir, vmnodeid)) # # update which physical node now houses this VM # rows = self.db.execute("""select id from nodes where name = "%s" """ % (tophyshost)) if rows < 1: return physhostid, = self.db.fetchone() self.db.execute("""update vm_nodes set physnode = %s where id = %s """ % (physhostid, vmnodeid)) # # remove the VM configuration file on the 'from' physical host # cmd = 'rm -f /etc/xen/rocks/%s' % host self.command('run.host', [ fromphyshost, 'command=%s' % cmd ]) # # restore the VM's running state # print "Restarting the VM on %s." % (tophyshost) self.command('restore.host.vm', [ host, "file=%s" % tosavefile])