static void Test_CreateVmExisting(Host host) { //Get vm iso XenConnect conn = new XenConnect(host, testServerId, testip); List <VirtualDisk> disks = conn.getISOStorageList(); string filename = null; //check if the disk exists foreach (VirtualDisk disk in disks) { if (disk.NameCanonical.Contains("Ubuntu14")) { filename = disk.Name; break; } } string vmName = "SeniorBuntu"; int memory = 2000000; int vcpus = 1; VirtualMachineBuilder.DomainType domType = VirtualMachineBuilder.DomainType.TRANSIENT; VirtualMachineBuilder builder = new VirtualMachineBuilder(vmName, memory, vcpus, VirtualMachineBuilder.XEN_PATH_DEFAULT_ISO + filename, domType); //builder.setHardDrive(20000, true); //set hard drive size to 20 GB (20k MB) builder.setHardDriveExisting(true, false, VirtualMachineBuilder.XEN_PATH_DEFAULT_DISK + "BuntuMaster.img"); conn.createVm(builder); //string xml = builder.toXMLString(); }
static void Test_CreateVmExisting2(Host host) { //Get vm iso XenConnect conn = new XenConnect(host, testServerId, testip); string vmName = "IntrospectionTestBuntu"; int memory = 2000000; int vcpus = 1; VirtualMachineBuilder.DomainType domType = VirtualMachineBuilder.DomainType.TRANSIENT; VirtualMachineBuilder builder = new VirtualMachineBuilder(vmName, "Ubuntu14-04", memory, vcpus, domType); //builder.setHardDrive(20000, true); //set hard drive size to 20 GB (20k MB) builder.setHardDriveExisting(true, false, ""); string xml = builder.toXMLString(); conn.createVm(builder); //string xml = builder.toXMLString(); }
private void btn_create_vm_Click(object sender, RoutedEventArgs e) { XenConnect conn = new XenConnect(_selectedHost, _settings.SystemIdentifier, _settings.SystemIp); string iso = (string)combobox_os_image.SelectedItem; string vmName = textbox_vm_name.Text; int memory = int.Parse(textbox_vm_memory.Text.Replace(",", "")); int vcpus = int.Parse(textbox_vm_vcpu.Text.Replace(",", "")); int diskMem = int.Parse(textbox_vm_hd.Text.Replace(",", "")); VirtualMachineBuilder builder = null; if (!(bool)checkbox_existing.IsChecked) { VirtualMachineBuilder.DomainType domType = VirtualMachineBuilder.DomainType.TRANSIENT; builder = new VirtualMachineBuilder(vmName, memory * 1000, vcpus, VirtualMachineBuilder.XEN_PATH_DEFAULT_ISO + iso + ".iso", domType); builder.setHardDrive(diskMem * 1000, true); //set hard drive size to n GB (nk MB) } else { List <VirtualDisk> disks = conn.getISOStorageList(); string filename = null; //hard coded for fluff foreach (VirtualDisk disk in disks) { if (disk.NameCanonical.Contains("Ubuntu14")) { filename = disk.Name; break; } } VirtualMachineBuilder.DomainType domType = VirtualMachineBuilder.DomainType.TRANSIENT; builder = new VirtualMachineBuilder(vmName, memory * 1000, vcpus, VirtualMachineBuilder.XEN_PATH_DEFAULT_ISO + filename, domType); builder.setHardDriveExisting(true, false, VirtualMachineBuilder.XEN_PATH_DEFAULT_DISK + ((string)combobox_os_image.SelectedItem) + ".img"); conn.createVm(builder); } XenError status = conn.createVm(builder); MessageBoxResult mbr; if (status.Type == XenError.XenErrorType.SUCCESS) { mbr = MessageBox.Show("Succesessfully created virtual machine " + vmName, "Create Virtual Machine", MessageBoxButton.OK, MessageBoxImage.Information); } else { mbr = MessageBox.Show(status.Message, "Create Virtual Machine", MessageBoxButton.OK, MessageBoxImage.Information); } if (mbr.CompareTo(MessageBoxResult.OK) == 0) { if (status.Type == XenError.XenErrorType.SUCCESS) { Close(); } } }