Example #1
0
def snapshot(name, vmname, ipaddr, resolution, ramsize, cpus, hostname,
             adapter, vm_visible, count, vrde, vrde_port, interactive, debug):
    if debug:
        log.setLevel(logging.DEBUG)

    session = Session()

    if adapter:
        log.error(
            "Specifying a different adapter is not yet supported for "
            "snapshots (this will require detaching the current adapter and "
            "attaching a new one after the static IP address has been "
            "updated or so)."
        )
        exit(1)

    image = session.query(Image).filter_by(name=name).first()
    if not image:
        log.error("Image not found: %s", name)
        exit(1)

    # From now on this image is multiattach.
    image.mode = "multiattach"
    session.commit()

    if not count:
        snapshot = do_snapshot(
            image, vmname, ipaddr, resolution, ramsize, cpus,
            hostname or random_string(8, 16), adapter, vm_visible,
            vrde, vrde_port, interactive
        )
        session.add(snapshot)
    else:
        if hostname:
            log.error(
                "You specified a hostname, but this is not supported when "
                "creating multiple snapshots at once."
            )
            exit(1)

        for x in xrange(count):
            snapshot = do_snapshot(
                image, "%s%d" % (vmname, x + 1), ipaddr, resolution,
                ramsize, cpus, hostname, adapter, vm_visible,
                vrde, vrde_port, interactive
            )
            session.add(snapshot)

            # TODO Implement some limits to make sure that the IP address does
            # not "exceed" its provided subnet (and thus also require the user
            # to specify an IP range, rather than an IP address).
            ipaddr = ipaddr_increase(ipaddr)
            hostname = random_string(8, 16)

    session.commit()
Example #2
0
def snapshot(name, vmname, ipaddr, resolution, ramsize, cpus, hostname,
             adapter, vm_visible, count, vrde, vrde_port, interactive, debug):
    if debug:
        log.setLevel(logging.DEBUG)

    session = Session()

    if adapter:
        log.error(
            "Specifying a different adapter is not yet supported for "
            "snapshots (this will require detaching the current adapter and "
            "attaching a new one after the static IP address has been "
            "updated or so)."
        )
        exit(1)

    image = session.query(Image).filter_by(name=name).first()
    if not image:
        log.error("Image not found: %s", name)
        exit(1)

    # From now on this image is multiattach.
    image.mode = "multiattach"
    session.commit()

    if not count:
        snapshot = do_snapshot(
            image, vmname, ipaddr, resolution, ramsize, cpus,
            hostname or random_string(8, 16), adapter, vm_visible,
            vrde, vrde_port, interactive
        )
        session.add(snapshot)
    else:
        if hostname:
            log.error(
                "You specified a hostname, but this is not supported when "
                "creating multiple snapshots at once."
            )
            exit(1)

        for x in xrange(count):
            snapshot = do_snapshot(
                image, "%s%d" % (vmname, x + 1), ipaddr, resolution,
                ramsize, cpus, hostname, adapter, vm_visible,
                vrde, vrde_port, interactive
            )
            session.add(snapshot)

            # TODO Implement some limits to make sure that the IP address does
            # not "exceed" its provided subnet (and thus also require the user
            # to specify an IP range, rather than an IP address).
            ipaddr = ipaddr_increase(ipaddr)
            hostname = random_string(8, 16)

    session.commit()
Example #3
0
def snapshot(name, vmname, ipaddr, resolution, ramsize, cpus, hostname,
             adapter, vm_visible, count):
    session = Session()

    image = session.query(Image).filter_by(name=name).first()
    if not image:
        log.error("Image not found: %s", name)
        exit(1)

    # From now on this image is multiattach.
    image.mode = "multiattach"
    session.commit()

    if not count:
        snapshot = do_snapshot(
            image, vmname, ipaddr, resolution, ramsize, cpus,
            hostname or random_string(8, 16), adapter, vm_visible
        )
        session.add(snapshot)
    else:
        if hostname:
            log.error(
                "You specified a hostname, but this is not supported when "
                "creating multiple snapshots at once."
            )
            exit(1)

        for x in xrange(count):
            snapshot = do_snapshot(
                image, "%s%d" % (vmname, x + 1), ipaddr, resolution,
                ramsize, cpus, hostname, adapter, vm_visible
            )
            session.add(snapshot)

            # TODO Implement some limits to make sure that the IP address does
            # not "exceed" its provided subnet (and thus also require the user
            # to specify an IP range, rather than an IP address).
            ipaddr = ipaddr_increase(ipaddr)
            hostname = random_string(8, 16)

    session.commit()
Example #4
0
def test_winxp_many():
    ip, port, count = "192.168.56.201", 13400, 10

    name, snapshot = genname("winxp"), genname("winxp-snapshot")
    call(
        main.init, name, "--winxp",
        "--ip", "192.168.56.4", "--port", port,
        "--tempdir", dirpath, "--serial-key", config["winxp"]["serialkey"]
    )
    call(main.snapshot, name, snapshot, ip, "--count", count)

    snapshots = []
    for x in range(count):
        snapshots.append([
            "%s%d" % (snapshot, x + 1),
            ip, port,
        ])

        ip = misc.ipaddr_increase(ip)

    # We have to remove the VMs in reverse because of VirtualBox dependencies.
    for snapshot, ip, port in snapshots[::-1]:
        m = vm.VirtualBox(snapshot)
        m.restore_snapshot()
        m.start_vm()

        misc.wait_for_host(ip, port)

        # Very basic integrity checking of the VM.
        a = agent.Agent(ip, port)
        assert a.environ()["SYSTEMDRIVE"] == "C:"

        a.shutdown()
        m.wait_for_state(shutdown=True)

        m.delete_snapshot("vmcloak")
        m.remove_hd()
        m.delete_vm()

    image = session.query(Image).filter_by(name=name).first()
    os.remove(image.path)
Example #5
0
def test_winxp_many():
    ip, port, count = "192.168.56.201", 13400, 10

    name, snapshot = genname("winxp"), genname("winxp-snapshot")
    call(main.init, name, "--winxp", "--ip", "192.168.56.4", "--port", port,
         "--tempdir", dirpath, "--serial-key", config["winxp"]["serialkey"])
    call(main.snapshot, name, snapshot, ip, "--count", count)

    snapshots = []
    for x in range(count):
        snapshots.append([
            "%s%d" % (snapshot, x + 1),
            ip,
            port,
        ])

        ip = misc.ipaddr_increase(ip)

    # We have to remove the VMs in reverse because of VirtualBox dependencies.
    for snapshot, ip, port in snapshots[::-1]:
        m = vm.VirtualBox(snapshot)
        m.restore_snapshot()
        m.start_vm()

        misc.wait_for_host(ip, port)

        # Very basic integrity checking of the VM.
        a = agent.Agent(ip, port)
        assert a.environ()["SYSTEMDRIVE"] == "C:"

        a.shutdown()
        m.wait_for_state(shutdown=True)

        m.delete_snapshot("vmcloak")
        m.remove_hd()
        m.delete_vm()

    image = session.query(Image).filter_by(name=name).first()
    os.remove(image.path)
Example #6
0
def test_ipaddr_increase():
    assert misc.ipaddr_increase("1.2.3.4") == "1.2.3.5"
    assert misc.ipaddr_increase("192.168.56.101") == "192.168.56.102"
Example #7
0
def test_ipaddr_increase():
    assert misc.ipaddr_increase("1.2.3.4") == "1.2.3.5"
    assert misc.ipaddr_increase("192.168.56.101") == "192.168.56.102"