def load_vm(self, name): show('Loading VM %s' % name) self.get_domain(name) # this fails if VM does not exist # TODO: check that it started, if not, wait self.start(name) # TODO: need a proper retry function ip = None timeout = 0 while ip is None: ip = self.get_ip(name) sleep(2) timeout += 2 if timeout > 20: raise RuntimeError("Could not determine IP of VM %s" % name) hostname = util.normalize_hostname(ip) show('IP determined: %s' % ip) return VM(name=name, backend=self, hostname=hostname, domain=locals.DOMAIN, ip=ip)
def create_vm(self, name, template=locals.TEMPLATE_NAME): # TODO: check if the VM with the name of name exists # Check whether template VM exists show('Checking for existence of template') template_domain = self.get_domain(template) # TODO: check if it is running, if is, print down warning and shut # it down if template_domain: show('Cloning..') # Find out next available MAC address in the pool new_mac = self.get_next_free_mac() output, errors, rc = util.run([ 'virt-clone', '-o', template, '--auto-clone', '-n', name, '-m', new_mac, ]) if rc != 0: raise RuntimeError("Could not clone VM %s" % template) show('Cloning successful') # TODO: check that it started, if not, wait show('Starting..') self.start(name) sleep(10) # Macs are tied to the IPs last_mac_segment = new_mac.split(':')[-1] ip = locals.IP_BASE + '%s' % int(last_mac_segment) show('IP determined: %s' % ip) hostname = util.normalize_hostname(ip) return VM(name=name, backend=self, hostname=hostname, domain=locals.DOMAIN, ip=ip)
def load_vm(self, name): self.start(name) # Obtain the IP address. It can take a while for the guest agent # to start, so we wait 2 minutes here before giving up. show('Waiting to obtain IP address') show('Press CTRL+C to interrupt and enter manually.') counter = 0 try: while self.get_ip(name) is None: counter = counter + 1 if counter > 120: break sleep(1) except KeyboardInterrupt: counter = 100000 if counter <= 120: ip = self.get_ip(name) last_ip_segment = ip.split('.')[-1] show("IP address of the VM is %s" % ip) else: notify('Enter the IP manually.') last_ip_segment = '' while not (len(last_ip_segment) > 0 and len(last_ip_segment) < 4): last_ip_segment = raw_input("IP address could not be " "determined. Enter the VM number (no leading zeros):") ip = locals.IP_BASE + last_ip_segment # Update the description hostname = util.normalize_hostname(ip) # Set the VM's description so that it can be identified in WebAdmin vm = self.api.vms.get(name) vm.set_description(hostname) vm.update() show("Description set to %s" % hostname) # Necessary because of RHEV bug show("Pinging the VM") output, errors, rc = util.run(['ping', '-c', '3', ip]) show.untab() return VM(name=name, backend=self, hostname=hostname, domain=locals.DOMAIN, ip=ip)
def create_vm(self, name, template=locals.TEMPLATE_NAME): # TODO: check if the VM with the name of name exists # Check whether template VM exists show('Checking for existence of template') template_domain = self.get_domain(template) # TODO: check if it is running, if is, print down warning and shut # it down if template_domain: show('Cloning..') # Find out next available MAC address in the pool new_mac = self.get_next_free_mac() output, errors, rc = util.run(['virt-clone', '-o', template, '--auto-clone', '-n', name, '-m', new_mac, ]) if rc != 0: raise RuntimeError("Could not clone VM %s" % template) show('Cloning successful') # TODO: check that it started, if not, wait show('Starting..') self.start(name) sleep(10) # Macs are tied to the IPs last_mac_segment = new_mac.split(':')[-1] ip = locals.IP_BASE + '%s' % int(last_mac_segment) show('IP determined: %s' % ip) hostname = util.normalize_hostname(ip) return VM(name=name, backend=self, hostname=hostname, domain=locals.DOMAIN, ip=ip)