Ejemplo n.º 1
0
    def load_vm(self, name, vm=None, start=True, interactive=True, update=True):
        if not vm:
            vm = self.get_vm(name)
        if start:
            vm = self.start(name, vm)

        # 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.')
        if start:
            max_counter = 120
        else:
            max_counter = 2
        counter = 0
        ip = self.get_ip(vm)
        try:
            while ip is None:
                vm = self.get_vm(name)
                ip = self.get_ip(vm)
                counter = counter + 1
                if counter > max_counter:
                    break
                sleep(15)
        except KeyboardInterrupt:
            counter = 100000

        if counter <= max_counter:
            fqdn = vm.get_guest_info().fqdn
            show("IP address of the VM is %s" % ip)
            show("FQDN of the VM is %s" % fqdn)
        else:
            if interactive:
                notify('Enter the IP manually.')
                fqdn = ''
                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
            else:
                ip = ''
                fqdn = ''

        # Set the VM's description so that it can be identified in WebAdmin
        if fqdn and update:
            vm.set_description(fqdn)
            vm.update()
            show("Description set to %s" % fqdn)

        # 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=fqdn,
                  domain=locals.DOMAIN, ip=ip)
Ejemplo n.º 2
0
    def load_vm(self, name, vm=None):
        if not vm:
            vm = self.get_vm(name)
        vm = self.start(name, vm)

        # 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
        ip = self.get_ip(vm)
        try:
            while ip is None:
                vm = self.get_vm(name)
                ip = self.get_ip(vm)
                counter = counter + 1
                if counter > 40:
                    break
                sleep(15)
        except KeyboardInterrupt:
            counter = 100000

        if counter <= 40:
            fqdn = vm.get_guest_info().fqdn
            show("IP address of the VM is %s" % ip)
            show("FQDN of the VM is %s" % fqdn)
        else:
            notify('Enter the IP manually.')
            fqdn = ''
            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

        # Set the VM's description so that it can be identified in WebAdmin
        if fqdn:
            vm.set_description(fqdn)
            vm.update()
            show("Description set to %s" % fqdn)

        # 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=fqdn,
                  domain=locals.DOMAIN,
                  ip=ip)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
                clients[i].set_format(dest='vm-%s' % args.source)
            elif args.build:
                clients[i].set_format(dest=vm.hostname)

            clients[i].install_packages(args.install)

            if args.trust:
                clients[i].set_hostname(subdomain=vm.hostname)

            clients[i].install_client(vm.hostname)

            show.untab()


if __name__ == '__main__':
    args = parse_options()

    try:
        main(args)
    except Exception, e:
        print '***The command above has FAILED***'
        print 'You can find the logs in ~/<hostname>.log on the VM'
        print ''
        print str(e)

        notify('Scripts on %s failed?!' % args.name)

        sys.exit(1)

    notify('Scripts on %s finished :-)' % args.name)
Ejemplo n.º 5
0
                clients[i].set_format(dest='vm-%s' % args.source)
            elif args.build:
                clients[i].set_format(dest=vm.hostname)

            clients[i].install_packages(args.install)

            if args.trust:
                clients[i].set_hostname(subdomain=vm.hostname)

            clients[i].install_client(vm.hostname)

            show.untab()


if __name__ == '__main__':
    args = parse_options()

    try:
        main(args)
    except Exception, e:
        print '***The command above has FAILED***'
        print 'You can find the logs in ~/<hostname>.log on the VM'
        print ''
        print str(e)

        notify('Scripts on %s failed?!' % args.name)

        sys.exit(1)

    notify('Scripts on %s finished :-)' % args.name)