Beispiel #1
0
def create_vm(idx, password):
    VM_NAME = INT_DNS_NAME.format(idx)

    IMAGE_NAME = "/subscriptions/" + utils.get_subscription_id() + \
                 "/resourceGroups/admin_resources/providers/Microsoft.Compute/images/ubuntu_gpu_image1_" + region
    data_disks = "255 255 255 255"

    user_pass = password
    cloud_init_fn = cloud_init_fill_template("configs/cloud_init_sirius_template.txt", user_pass, postfix=str(idx))
    utils.create_vm(VM_NAME, rg_name, region, IMAGE_NAME, NIC_NAME.format(idx), vm_size, None, OS_DISK_NAME.format(idx),
                    user_pass, cloud_init_fn, data_disks)

    print("{} public IP: {}".format(VM_NAME, utils.get_public_ip(IP_NAME.format(idx), rg_name)))
    def test_backward_merge_from_active(self):
        """
        Backward Merge One from Active Layer

        Create image chain: BASE---S1---S2
        Start VM
        Merge S1 << S2
        Final image chain:  BASE---S1
        """
        base_file = utils.create_image('BASE')
        s1_file = utils.create_image('S1', 'BASE')
        s2_file = utils.create_image('S2', 'S1')

        dom = utils.create_vm('livemerge-test', 'S2', block=False)
        try:
            dom.blockCommit(s2_file, s1_file, s2_file, 0, 0)
            flags = libvirt.VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT
            self.assertTrue(utils.wait_block_job(dom, s2_file, flags))
        finally:
            dom.destroy()

        self.assertTrue(utils.verify_backing_file(base_file, None))
        self.assertTrue(utils.verify_backing_file(s1_file, 'BASE',
                                                  relative=False,
                                                  block=False))
    def test_forward_merge_one_to_active(self, relPath, baseFmt, block):
        """
        Forward Merge One to Active Layer

        Create image chain: BASE---S1---S2
        Start VM
        Merge S1 >> S2
        Final image chain:  BASE---S2
        """
        base_file = utils.create_image('BASE', fmt=baseFmt, block=block)
        utils.write_image(base_file, 0, 3072, 1)
        s1_file = utils.create_image('S1', 'BASE', relative=relPath,
                                     backingFmt=baseFmt, block=block)
        utils.write_image(s1_file, 1024, 2048, 2)
        s2_file = utils.create_image('S2', 'S1', relative=relPath,
                                     block=block)
        utils.write_image(s2_file, 2048, 1024, 3)

        dom = utils.create_vm('livemerge-test', 'S2', block=block)
        try:
            dom.blockRebase(s2_file, base_file, 0, 0)
            flags = libvirt.VIR_DOMAIN_BLOCK_JOB_TYPE_PULL
            self.assertTrue(utils.wait_block_job(dom, s2_file, flags))
        finally:
            dom.destroy()

        self.assertTrue(utils.verify_image(s2_file, 0, 1024, 1))
        self.assertTrue(utils.verify_image(s2_file, 1024, 1024, 2))
        self.assertTrue(utils.verify_image(s2_file, 2048, 1024, 3))
        self.assertTrue(utils.verify_backing_file(base_file, None))
        self.assertTrue(utils.verify_backing_file(s2_file, 'BASE',
                                                  relative=relPath,
                                                  block=block))
        self.assertTrue(utils.verify_image_format(s1_file, 'qcow2'))
    def test_backward_merge_from_inactive(self, relPath, baseFmt, block):
        """
        Backward Merge One from Inactive Layer

        Create image chain: BASE---S1---S2
        Start VM
        Merge BASE << S1
        Final image chain:  BASE---S2
        """
        base_file = utils.create_image('BASE', fmt=baseFmt, block=block)
        s1_file = utils.create_image('S1', 'BASE', relative=relPath,
                                     backingFmt=baseFmt, block=block)
        s2_file = utils.create_image('S2', 'S1', relative=relPath,
                                     block=block)
        self.assertTrue(utils.verify_backing_file(base_file, None))
        self.assertTrue(utils.verify_backing_file(s1_file, 'BASE',
                                                  relative=relPath,
                                                  block=block))
        self.assertTrue(utils.verify_backing_file(s2_file, 'S1',
                                                  relative=relPath,
                                                  block=block))

        dom = utils.create_vm('livemerge-test', 'S2', block=block)
        try:
            dom.blockCommit('vda', base_file, s1_file, 0, 0)
            flags = libvirt.VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT
            self.assertTrue(utils.wait_block_job(dom, s2_file, flags))
        finally:
            dom.destroy()

        self.assertTrue(utils.verify_backing_file(base_file, None))
        self.assertTrue(utils.verify_backing_file(s2_file, 'BASE',
                                                  relative=relPath,
                                                  block=block))
        self.assertTrue(utils.verify_image_format(base_file, baseFmt))
    def do_restore_vm(self):
        """
        Create new vm instance with attache restored volumes from backup.

        :returns: returns new vm instance id
        :rtype: str
        """
        device_map = self.do_restore_backup()

        new_vm = utils.create_vm(self.server_id, device_map)

        return new_vm
Beispiel #6
0
def create_cluster_node(idx, user_pass):
    IP_NAME = "ip_cluster{0}".format(idx)
    NIC_NAME = "nic_cluster{0}".format(idx)
    INT_DNS_NAME = "cluster{0}".format(idx)
    OS_DISK_NAME = "cluster{0}_os_disk".format(idx)
    VM_NAME = INT_DNS_NAME
    IP = "10.0.1.2{0}".format(idx)

    if idx != 1:
        IP_NAME = None

    if args.create_aux:
        # create public IP
        if IP_NAME is not None:
            utils.create_public_ip(IP_NAME, rg_name)

        # Create network card with fixed private IP
        utils.create_nic_with_private_ip(NIC_NAME, rg_name, VNET_NAME,
                                         SUBNET_NAME, NSG_NAME, IP_NAME,
                                         INT_DNS_NAME, IP)

    # create VM https://docs.microsoft.com/en-us/azure/virtual-machines/virtual-machines-windows-sizes
    IMAGE_NAME = "/subscriptions/" + utils.get_subscription_id() + \
                 "/resourceGroups/admin_resources/providers/Microsoft.Compute/images/" + \
                 "cluster{0}".format(idx) + "_image1_" + region
    data_disks = "255 255 255 255"

    if idx == 1:
        cloud_init_fn = cloud_init_fill_template(
            "configs/cloud_init_cluster_master_template.txt", user_pass)
    else:
        cloud_init_fn = "configs/cloud_init_cluster_slave.txt"
    utils.create_vm(VM_NAME, rg_name, region, IMAGE_NAME, NIC_NAME, vm_size,
                    None, OS_DISK_NAME, user_pass, cloud_init_fn, data_disks,
                    "Standard_LRS")

    if RESIZE_OS_DISK:
        utils.deallocate_vm(VM_NAME, rg_name)
        utils.resize_managed_disk(rg_name, OS_DISK_NAME, OS_DISK_SIZE)
        utils.start_vm(VM_NAME, rg_name)
    def test_commit(self):
        print "Creating VM image"
        base_file = utils.get_image_path('BASE', False, False)
        utils.build_vm('BASE', touch_script, '10G')
        s1_file = utils.create_image('S1', 'BASE', size='10G')

        # Monitor the image sizes
        stats = {'BASE': [], 'S1': []}
        stopEvent = threading.Event()
        base_watcher = ImageWatcher(base_file, stats['BASE'], stopEvent)
        base_watcher.start()
        s1_watcher = ImageWatcher(s1_file, stats['S1'], stopEvent)
        s1_watcher.start()

        # Run the test
        print "Starting VM"
        dom = utils.create_vm('livemerge-test', 'S1')
        # TODO: Start a livemerge

        try:
            dom.blockCommit(s1_file, base_file, s1_file, 0, 0)
            flags = libvirt.VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT
            self.assertTrue(utils.wait_block_job(dom, s1_file, flags))
        finally:
            dom.destroy()


        ## Wait until image has grown enough
        #print "Sampling"
        #while True:
            #end = utils.get_image_end_offset(s1_file) / 1024 / 1024
            #print "S1 is using %i MB" % end
            #if end >= 5 * 1024:
                #break
            #time.sleep(5)

        # Stop the test
        print "Cleaning up"
        stopEvent.set()
        base_watcher.join()
        s1_watcher.join()

        # Print results
        self._print_results(stats)
    def test_forward_merge_all_to_active(self):
        """
        Forward Merge All to Active Layer

        Create image chain: BASE---S1---S2
        Start VM
        Merge (BASE + S1) >> S2
        Final image chain:  S2
        """
        utils.create_image('BASE')
        utils.create_image('S1', 'BASE')
        s2_file = utils.create_image('S2', 'S1')

        dom = utils.create_vm('livemerge-test', 'S2', block=False)
        try:
            dom.blockRebase(s2_file, None, 0, 0)
            flags = libvirt.VIR_DOMAIN_BLOCK_JOB_TYPE_PULL
            self.assertTrue(utils.wait_block_job(dom, s2_file, flags))
        finally:
            dom.destroy()

        self.assertTrue(utils.verify_backing_file(s2_file, None))
Beispiel #9
0
IP = "10.0.1.10"

if args.create_aux:
    # create public IP
    utils.create_public_ip(IP_NAME, RG_NAME)

    # Create network card with fixed private IP
    utils.create_nic_with_private_ip(NIC_NAME, RG_NAME, VNET_NAME, SUBNET_NAME,
                                     NSG_NAME, IP_NAME, INT_DNS_NAME, IP)

# create VM
VM_NAME = INT_DNS_NAME

IMAGE_NAME = "/subscriptions/" + utils.get_subscription_id() + \
             "/resourceGroups/" + RG_NAME + "/providers/Microsoft.Compute/images/" + UBUNTUGPU_IMAGE
data_disks = "255 255 255 255"

user_pass = utils.generate_pass()
cloud_init_fn = cloud_init_fill_template(
    "configs/cloud_init_ubuntugpu_template.txt", user_pass)
utils.create_vm(VM_NAME, RG_NAME, REGION, IMAGE_NAME, NIC_NAME, VM_SIZE, None,
                OS_DISK_NAME, user_pass, cloud_init_fn, data_disks)

if RESIZE_OS_DISK:
    utils.deallocate_vm(VM_NAME, RG_NAME)
    utils.resize_managed_disk(RG_NAME, OS_DISK_NAME, OS_DISK_SIZE)
    utils.start_vm(VM_NAME, RG_NAME)

print("ubuntugpu public IP: {}".format(utils.get_public_ip(IP_NAME, RG_NAME)))
print("password:", user_pass)
Beispiel #10
0
if args.create_aux:
    # create public IP
    utils.create_public_ip(IP_NAME, rg_name)

    # Create network card with fixed private IP
    utils.create_nic_with_private_ip(NIC_NAME, rg_name, VNET_NAME, SUBNET_NAME,
                                     NSG_NAME, IP_NAME, INT_DNS_NAME, IP)

# create VM
VM_NAME = INT_DNS_NAME

IMAGE_NAME = "/subscriptions/" + utils.get_subscription_id() + \
             "/resourceGroups/admin_resources/providers/Microsoft.Compute/images/ubuntu_gpu_image1_" + region
data_disks = "255 255 255 255"

user_pass = utils.generate_pass()
cloud_init_fn = cloud_init_fill_template(
    "configs/cloud_init_ubuntugpu_template.txt", user_pass)
utils.create_vm(VM_NAME, rg_name, region, IMAGE_NAME, NIC_NAME, vm_size, None,
                OS_DISK_NAME, user_pass, cloud_init_fn, data_disks)

if RESIZE_OS_DISK:
    utils.deallocate_vm(VM_NAME, rg_name)
    utils.resize_managed_disk(rg_name, OS_DISK_NAME, OS_DISK_SIZE)
    utils.start_vm(VM_NAME, rg_name)

print("ubuntugpu public IP: {}".format(
    utils.get_public_ip("ip_ubuntugpu", rg_name)))
print("password:", user_pass)