public UserControl Forward()
        {
            _Local_Media_Create_Model.Machine_Definition.Devices.Devices.Clear();//remove any previous devices
            var de = new Libvirt.Models.Concrete.Device();

            de.Device_Bus_Type    = Libvirt.Models.Concrete.Device.Device_Bus_Types.virtio;
            de.Device_Device_Type = Libvirt.Models.Concrete.Device.Device_Device_Types.cdrom;
            de.Device_Type        = Libvirt.Models.Concrete.Device.Device_Types.volume;
            de.Driver_Cache_Type  = Libvirt.Models.Concrete.Device.Driver_Cache_Types._default;
            de.Driver_Type        = Libvirt.Models.Concrete.Device.Driver_Types.raw;
            de.ReadOnly           = true;
            de.Snapshot_Type      = Libvirt.Models.Concrete.Device.Snapshot_Types._default;
            var source = new Libvirt.Models.Concrete.Device_Source_Volume();

            source.pool = Pool_SelectBox.SelectedItem != null?Pool_SelectBox.SelectedItem.ToString() : "";

            source.volume = Volume_SelectBox.SelectedItem != null?Volume_SelectBox.SelectedItem.ToString() : "";

            source.Source_Startup_Policy = Libvirt.Models.Concrete.Device.Source_Startup_Policies.optional;
            de.Source = source;
            _Local_Media_Create_Model.Machine_Definition.Devices.Add(de);// add this .. NOW VALIDATE!!
            if (_Local_Media_Create_Model.Validate())
            {
                return(new Cpu_Ram_Create(this, _Local_Media_Create_Model.Connection, _Local_Media_Create_Model.Machine_Definition));
            }
            else
            {
                foreach (var item in _Local_Media_Create_Model.Errors)
                {
                    foreach (var r in item.Value)
                    {
                        errorProvider1.SetError(Volume_SelectBox, r);
                    }
                }
            }
            return(null);
        }
Exemple #2
0
        public UserControl Forward()
        {
            var previtem = _Storage_Create_Model.Machine_Definition.Devices.Devices.FirstOrDefault();

            _Storage_Create_Model.Machine_Definition.Devices.Devices.Clear();// clear everything
            var de = new Libvirt.Models.Concrete.Device();

            de.Device_Bus_Type    = Libvirt.Models.Concrete.Device.Device_Bus_Types.virtio;
            de.Device_Device_Type = Libvirt.Models.Concrete.Device.Device_Device_Types.disk;
            de.Device_Type        = Libvirt.Models.Concrete.Device.Device_Types.volume;
            de.Driver_Cache_Type  = Libvirt.Models.Concrete.Device.Driver_Cache_Types._default;
            de.Driver_Type        = Libvirt.Models.Concrete.Device.Driver_Types.raw;
            de.ReadOnly           = false;
            de.Snapshot_Type      = Libvirt.Models.Concrete.Device.Snapshot_Types._default;
            var source = new Libvirt.Models.Concrete.Device_Source_Volume();

            source.pool = Pool_ListBox.SelectedItem != null?Pool_ListBox.SelectedItem.ToString() : "";

            source.volume = Volume_ListBox.SelectedItem != null?Volume_ListBox.SelectedItem.ToString() : "";

            source.Source_Startup_Policy = Libvirt.Models.Concrete.Device.Source_Startup_Policies.mandatory;
            de.Source = source;

            _Storage_Create_Model.Machine_Definition.Devices.Add(de);// add this .. NOW VALIDATE!!
            if (_Storage_Create_Model.Validate())
            {
                _Storage_Create_Model.Machine_Definition.Devices.Add(previtem);//add the previous item back
                var tmpxml = _Storage_Create_Model.Machine_Definition.To_XML();

                using (var domain = _Storage_Create_Model.Connection.virDomainDefineXML(_Storage_Create_Model.Machine_Definition))
                {
                    if (domain.IsValid)
                    {
                        if (AutoStart_VM_chk.Checked)
                        {
                            if (domain.virDomainCreate() == 0)
                            {
                                MessageBox.Show("Successfully created and started the new VM!");
                                return(new End_Control());//marker to signal the end
                            }
                            else
                            {
                                MessageBox.Show("Successfully created the VM, but was unable to start it. Check the error logs");
                                return(new End_Control());//marker to signal the end
                            }
                        }
                        else
                        {
                            MessageBox.Show("Successfully created the new VM!");
                            return(new End_Control());//marker to signal the end
                        }
                    }
                    else
                    {
                        MessageBox.Show("Unable to create the VM, please check the error logs!");
                    }
                }
            }
            else
            {
                _Storage_Create_Model.Machine_Definition.Devices.Devices.Clear();// clear everything, bad attempt
            }



            return(null);
        }