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();
        }
        private void updateHostDisksList(Host host)
        {
            XenConnect conn = new XenConnect(host, Settings.SystemIdentifier, Settings.SystemIp);

            conn.Notifications += e_logXenMasterNotification;
            List <VirtualDisk> isoImages = conn.getISOStorageList();
            List <VirtualDisk> vmDisks   = conn.getVirtualDiskList();

            listview_host_disks.ItemsSource  = vmDisks;
            listview_host_images.ItemsSource = isoImages;
        }
        private void ComboBox_Host_DropDownClosed(object sender, EventArgs e)
        {
            //MessageBox.Show(combobox_host.Text);
            _selectedHost = getHostByName(combobox_host.Text);
            XenConnect         conn      = new XenConnect(_selectedHost, _settings.SystemIdentifier, _settings.SystemIp);
            List <VirtualDisk> isoImages = conn.getISOStorageList();

            combobox_os_image.Items.Clear();

            foreach (VirtualDisk disk in isoImages)
            {
                combobox_os_image.Items.Add(disk.NameCanonical);
            }
        }
        private void checkbox_existing_Unchecked(object sender, RoutedEventArgs e)
        {
            //MessageBox.Show(combobox_host.Text);
            _selectedHost = getHostByName(combobox_host.Text);
            XenConnect         conn      = new XenConnect(_selectedHost, _settings.SystemIdentifier, _settings.SystemIp);
            List <VirtualDisk> isoImages = conn.getISOStorageList();

            combobox_os_image.Items.Clear();

            foreach (VirtualDisk disk in isoImages)
            {
                combobox_os_image.Items.Add(disk.NameCanonical);
            }

            slider_hd.IsEnabled     = true;
            textbox_vm_hd.IsEnabled = true;
            textblock_slider_value_display.Opacity = 100;
        }
        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();
                }
            }
        }
 /// <summary>
 /// Tests List Disks
 /// </summary>
 /// <param name="host"></param>
 static void Test_ListIso(Host host)
 {
     Console.WriteLine("Retrieving host virtual machine disks...");
     XenConnect         con   = new XenConnect(host, testServerId, testip);
     List <VirtualDisk> disks = con.getISOStorageList();
 }