Exemplo n.º 1
0
 public Add_Storage_Pool(Libvirt.CS_Objects.Host con)
 {
     InitializeComponent();
     _connection     = con;
     _CurrentControl = new Create_First_Step(_connection);
     panel1.Controls.Add(_CurrentControl);
 }
Exemplo n.º 2
0
 public View_Model_To_Service(Libvirt.CS_Objects.Host con, Libvirt.Models.Concrete.Virtual_Machine d)
 {
     _Validation_Errors  = new Dictionary <string, List <string> >();
     Model_State         = new Libvirt.Models.Concrete.Validator(_Validation_Errors);
     _Connection         = con;
     _Machine_Definition = d;
 }
Exemplo n.º 3
0
 public static void Upload(this Libvirt.CS_Objects.Storage_Volume s, Libvirt.CS_Objects.Host host, System.IO.Stream stream)
 {
     using (var st = host.virStreamNew(Libvirt.virStreamFlags.VIR_STREAM_NONBLOCK))
     {
         var  stupload   = s.virStorageVolUpload(st, 0, (ulong)stream.Length);
         long chunksize  = 65000;
         var  dat        = new byte[chunksize];
         var  totalbytes = stream.Length;
         while (totalbytes > 0)
         {
             var bytestoread = chunksize;
             if (totalbytes < bytestoread)
             {
                 bytestoread = totalbytes;
             }
             var bread     = (uint)stream.Read(dat, 0, (int)bytestoread);
             var bytessent = st.virStreamSend(dat, bread);
             if (bytessent < 0)
             {
                 st.virStreamAbort();
                 break;//get out!!
             }
             totalbytes -= (long)bread;
         }
         st.virStreamFinish();
     }
 }
Exemplo n.º 4
0
 public Add_Domain(Libvirt.CS_Objects.Host con)
 {
     InitializeComponent();
     _connection     = con;
     _CurrentControl = new Create_First_Step(new VM_Manager.Utilities.End_Control(), _connection, _Machine_Def);
     panel1.Controls.Add(_CurrentControl);
 }
Exemplo n.º 5
0
 public Upload_Progress(Libvirt.CS_Objects.Host hostptr, Libvirt.CS_Objects.Storage_Volume volptr, string fpath)
 {
     InitializeComponent();
     _storage_ptr      = volptr;
     _connectionptr    = hostptr;
     filepath          = fpath;
     this.FormClosing += Upload_Progress_FormClosing;
 }
Exemplo n.º 6
0
 public Local_Media_Create(UserControl p, Libvirt.CS_Objects.Host con, Libvirt.Models.Concrete.Virtual_Machine d)
 {
     InitializeComponent();
     this.Dock = DockStyle.Fill;
     _Previous = p;
     _Local_Media_Create_Model = new Local_Media_Create_Model(con, d);
     Init_Controls();
 }
Exemplo n.º 7
0
 public Server_Details(Libvirt.CS_Objects.Host connection)
 {
     InitializeComponent();
     _connection = Libvirt.CS_Objects.Host.GetPtr(connection);
     _pollthread = new System.Threading.Thread(UpdateStats);
     _pollthread.Start();
     this.FormClosing += Connection_Details_FormClosing;
     Host_TabControl.SelectedIndexChanged += Host_TabControl_SelectedIndexChanged;
     FIllGeneralInfo();
 }
Exemplo n.º 8
0
 public Create_First_Step(UserControl p, Libvirt.CS_Objects.Host con, Libvirt.Models.Concrete.Virtual_Machine d)
 {
     InitializeComponent();
     this.Dock = DockStyle.Fill;
     _Previous = p;
     _Create_First_Step_Model = new Create_First_Step_Model(con, d);
     textBox2.DataBindings.Add(
         Safe_Property.GetPropertyInfo(textBox2, a => a.Text).Name,
         d.Metadata,
         Safe_Property.GetPropertyInfo(d.Metadata, a => a.name).Name, false, DataSourceUpdateMode.OnPropertyChanged);
 }
Exemplo n.º 9
0
        public Add_Storage_Volume(Libvirt.CS_Objects.Storage_Pool ptr, Libvirt.CS_Objects.Host conptr)
        {
            _PoolPtr       = ptr;
            _connectionptr = conptr;
            InitializeComponent();

            Libvirt._virStoragePoolInfo info;
            ptr.virStoragePoolGetInfo(out info);
            Max_Capacity_Numeric.Maximum = info.available / 1000000; //convert to Megabytes
            Max_Capacity_Numeric.Minimum = 100;
            Allocation_Numeric.Maximum   = info.available / 1000000; //convert to Megabytes
            Allocation_Numeric.Minimum   = 0;
            _ReaderCallback      = Read_CB;
            AvailSpaceLabel.Text = ptr.virStoragePoolGetName() + "'s available space: " + VM_Manager.Utilities.Formatting.Format((long)info.available);
        }
Exemplo n.º 10
0
 private void PopulateVMs(TreeNode parent, Libvirt.CS_Objects.Host ptr)
 {
     Libvirt.CS_Objects.Domain[] vms;
     ptr.virConnectListAllDomains(out vms, Libvirt.virConnectListAllDomainsFlags.VIR_CONNECT_LIST_DOMAINS_ACTIVE | Libvirt.virConnectListAllDomainsFlags.VIR_CONNECT_LIST_DOMAINS_INACTIVE);
     foreach (var item in vms)
     {
         var name = item.virDomainGetName();
         Libvirt._virDomainInfo info;
         item.virDomainGetInfo(out info);
         var imgindex = info.state == Libvirt.virDomainState.VIR_DOMAIN_RUNNING ? 4 : 5;
         var poolnode = new TreeNode(name, imgindex, imgindex);
         poolnode.Name = "VM";
         poolnode.Tag  = ptr;
         parent.Nodes.Add(poolnode);
         item.Dispose();
     }
 }
Exemplo n.º 11
0
        public Cpu_Ram_Create(UserControl p, Libvirt.CS_Objects.Host con, Libvirt.Models.Concrete.Virtual_Machine d)
        {
            InitializeComponent();
            this.Dock = DockStyle.Fill;
            _Previous = p;
            _Local_Media_Create_Model = new Cpu_Ram_Create_Model(con, d);
            UpdateControls();

            Memory_num.DataBindings.Add(
                Safe_Property.GetPropertyInfo(Memory_num, a => a.Value).Name,
                d.Memory,
                Safe_Property.GetPropertyInfo(d.Memory, a => a.memory).Name, false, DataSourceUpdateMode.OnPropertyChanged);
            CPU_num.DataBindings.Add(
                Safe_Property.GetPropertyInfo(CPU_num, a => a.Value).Name,
                d.CPU,
                Safe_Property.GetPropertyInfo(d.CPU, a => a.vCpu_Count).Name, false, DataSourceUpdateMode.OnPropertyChanged);
        }
Exemplo n.º 12
0
        private void PopulatePools(TreeNode parent, Libvirt.CS_Objects.Host ptr, bool force_refresh = false)
        {
            Libvirt.CS_Objects.Storage_Pool[] pools;
            ptr.virConnectListAllStoragePools(out pools, Libvirt.virConnectListAllStoragePoolsFlags.VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE | Libvirt.virConnectListAllStoragePoolsFlags.VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE);

            foreach (var item in pools)
            {
                if (force_refresh)
                {
                    item.virStoragePoolRefresh();
                }
                var poolnode = new TreeNode(item.virStoragePoolGetName(), 3, 3);
                poolnode.Name = "Pool";
                poolnode.Tag  = ptr;
                parent.Nodes.Add(poolnode);
                PopulateVolumes(poolnode, item);
                item.Dispose();
            }
        }
Exemplo n.º 13
0
        private void AddNewServer(Libvirt.CS_Objects.Host ptr)
        {
            var newhostname = ptr.virConnectGetHostname();

            ptr.virConnSetErrorFunc(_ErrorFunc);
            var newnode = new TreeNode(newhostname, 0, 0);

            newnode.Tag  = ptr;
            newnode.Name = "VM_Server";
            var nodesfound = treeView1.Nodes.Find(newhostname, true);

            if (nodesfound != null)
            {
                if (nodesfound.Length > 0)
                {
                    return;                       //node already added
                }
            }
            var node = treeView1.Nodes.Find("Root", false);

            if (node != null)
            {
                if (node.Length > 0)
                {
                    node[0].Nodes.Add(newnode);

                    var vmnode = new TreeNode("VMs", 8, 8);
                    vmnode.Tag  = ptr;
                    vmnode.Name = "VM_List";
                    newnode.Nodes.Add(vmnode);

                    PopulateVMs(vmnode, ptr);

                    var poolnode = new TreeNode("Pools", 7, 7);
                    poolnode.Tag  = ptr;
                    poolnode.Name = "Pool_List";
                    newnode.Nodes.Add(poolnode);

                    PopulatePools(poolnode, ptr);
                    _Connections.Add(ptr);
                }
            }
        }
Exemplo n.º 14
0
 public Main_Form(Libvirt.CS_Objects.Host h, string domainname)
 {
     InitializeComponent();
     using (var item = h.virDomainLookupByName(domainname))
     {
         if (!item.IsValid)
         {
             MessageBox.Show("Could not find the VM, Try refreshing the VM list.");
             this.Close();
         }
         else
         {
             var xmldesc = item.virDomainGetXMLDesc(Libvirt.virDomainXMLFlags.VIR_DEFAULT);
             _VM = new Libvirt.Models.Concrete.Virtual_Machine();
             var d = System.Xml.Linq.XDocument.Parse(xmldesc);
             _VM.From_XML(d.Root);
         }
     }
     _CurrentControl = new Overview(_VM);
     panel1.Controls.Add(_CurrentControl);
 }
Exemplo n.º 15
0
        private void treeView1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            Point    p    = new Point(e.X, e.Y);
            TreeNode node = treeView1.GetNodeAt(p);

            treeView1.SelectedNode = node;
            Libvirt.CS_Objects.Host con = null;
            if (treeView1.SelectedNode != null)
            {
                con = treeView1.SelectedNode.Tag as Libvirt.CS_Objects.Host;
            }
            if (e.Button == MouseButtons.Right)
            {
                if (node != null)
                {
                    if (node.Text == "VM-Manager")
                    {
                        VM_Manager_ContextStrip.Show(treeView1, p);
                    }
                    else if (node.Name == "VM_Server")
                    {
                        VM_Server_ContextStrip.Show(treeView1, p);
                    }
                    else if (node.Name == "Pool" && con != null)
                    {
                        using (var item = con.virStoragePoolLookupByName(node.Text))
                        {
                            Libvirt._virStoragePoolInfo info;
                            item.virStoragePoolGetInfo(out info);
                            if (info.state == Libvirt.virStoragePoolState.VIR_STORAGE_POOL_RUNNING)
                            {
                                newVolumeToolStripMenuItem.Enabled = true;
                                startToolStripMenuItem1.Enabled    = false;
                                stopToolStripMenuItem.Enabled      = true;
                                deleteToolStripMenuItem1.Enabled   = false;
                            }
                            else
                            {
                                newVolumeToolStripMenuItem.Enabled = false;
                                startToolStripMenuItem1.Enabled    = true;
                                stopToolStripMenuItem.Enabled      = false;
                                deleteToolStripMenuItem1.Enabled   = true;
                            }
                            Pool_Contet_MenuStrip.Show(treeView1, p);
                        }
                    }
                    else if (node.Name == "Pool_List")
                    {
                        Pool_Listing_Context.Show(treeView1, p);
                    }
                    else if (node.Name == "VM_List")
                    {
                        VM_Listing_Context.Show(treeView1, p);
                    }
                    else if (node.Name == "VM" && con != null)
                    {
                        using (var item = con.virDomainLookupByName(node.Text))
                        {
                            Libvirt._virDomainInfo info;
                            item.virDomainGetInfo(out info);

                            if (info.state == Libvirt.virDomainState.VIR_DOMAIN_RUNNING)
                            {
                                startToolStripMenuItem.Enabled   = false;
                                stopToolStripMenuItem1.Enabled   = true;
                                deleteToolStripMenuItem.Enabled  = false;
                                connectToolStripMenuItem.Enabled = true;
                            }
                            else
                            {
                                startToolStripMenuItem.Enabled   = true;
                                stopToolStripMenuItem1.Enabled   = false;
                                deleteToolStripMenuItem.Enabled  = true;
                                connectToolStripMenuItem.Enabled = false;
                            }
                            VM_Context_Strip.Show(treeView1, p);
                        }
                        moveToolStripMenuItem.DropDownItems.Clear();
                        var listdropitems = new List <ToolStripItem>();
                        int counter       = 0;
                        foreach (var server in _Connections.Where(a => a != con))
                        {
                            var drp = new System.Windows.Forms.ToolStripMenuItem();

                            drp.Image       = global::VM_Manager.Properties.Resources.forward;
                            drp.Name        = "MoveVmToServer" + (counter++).ToString();
                            drp.Size        = new System.Drawing.Size(152, 22);
                            drp.Text        = server.virConnectGetHostname();
                            drp.Tag         = server;//destination server
                            drp.Visible     = true;
                            drp.ToolTipText = "This will migrate a VM from its current Host to the Selected Host";
                            drp.Click      += new System.EventHandler(this.migrateStripMenuItem_Click);
                            listdropitems.Add(drp);
                        }
                        if (listdropitems.Any())
                        {
                            moveToolStripMenuItem.DropDownItems.AddRange(listdropitems.ToArray());
                            moveToolStripMenuItem.Invalidate();
                        }
                    }
                }
            }



            if (node != null)
            {
                if (node.Text == "VM-Manager")
                {
                    panel1.Controls.Add(new Server_Listing());
                }
                else if (node.Name == "VM")
                {
                    panel1.Controls.Add(new Server_Listing());
                }
                else if (node.Name == "Pool" && con != null)
                {
                    var panelcontrol = panel1.Controls.OfType <Storage.Storage_Pool_Listing>();
                    if (panelcontrol.Any())
                    {
                        panelcontrol.FirstOrDefault().Refresh(con, node.Text);
                    }
                    else
                    {
                        ClearPanel();
                        panel1.Controls.Add(new Storage.Storage_Pool_Listing(con, node.Text));
                    }
                }
            }
        }
 public Create_First_Step_Model(Libvirt.CS_Objects.Host con, Libvirt.Models.Concrete.Virtual_Machine d)
     : base(con, d)
 {
     _General_Metadata_Validator = new Libvirt.Service.Concrete.General_Metadata_Validator();
 }
Exemplo n.º 17
0
 public NetFS_Create(Libvirt.CS_Objects.Host con, string name)
 {
     InitializeComponent();
     _connection = con;
     _poolname   = name;
 }
Exemplo n.º 18
0
 public Dir_Control(Libvirt.CS_Objects.Host con, string name)
 {
     InitializeComponent();
     _connection = con;
     _poolname   = name;
 }
Exemplo n.º 19
0
 public Storage_Create_Model(Libvirt.CS_Objects.Host con, Libvirt.Models.Concrete.Virtual_Machine d)
     : base(con, d)
 {
     _Device_Validator = new Libvirt.Service.Concrete.Device_Collection_Validator();
 }
Exemplo n.º 20
0
 public Create_First_Step(Libvirt.CS_Objects.Host con)
 {
     InitializeComponent();
     _connection = con;
 }
Exemplo n.º 21
0
        private void migrateStripMenuItem_Click(object sender, EventArgs e)
        {
            var obj = sender as System.Windows.Forms.ToolStripMenuItem;

            Libvirt.CS_Objects.Host source = null;

            string vmname = "";

            if (treeView1.SelectedNode != null)
            {
                source = treeView1.SelectedNode.Tag as Libvirt.CS_Objects.Host;
                if (source != null)
                {
                    vmname = treeView1.SelectedNode.Text;
                }
            }
            else
            {
                return;
            }
            if (source == null)
            {
                return;
            }


            var destination = obj.Tag as Libvirt.CS_Objects.Host;

            if (destination == null)
            {
                return;
            }

            using (var sourcevm = source.virDomainLookupByName(vmname))
            {
                if (sourcevm.IsValid)
                {
                    Libvirt._virDomainInfo stats;
                    sourcevm.virDomainGetInfo(out stats);

                    var flags = Libvirt.virDomainMigrateFlags.VIR_MIGRATE_ABORT_ON_ERROR |
                                Libvirt.virDomainMigrateFlags.VIR_MIGRATE_UNDEFINE_SOURCE |
                                Libvirt.virDomainMigrateFlags.VIR_MIGRATE_PEER2PEER |
                                Libvirt.virDomainMigrateFlags.VIR_MIGRATE_TUNNELLED;

                    if (stats.state == Libvirt.virDomainState.VIR_DOMAIN_RUNNING || stats.state == Libvirt.virDomainState.VIR_DOMAIN_PAUSED)
                    {
                        flags |= Libvirt.virDomainMigrateFlags.VIR_MIGRATE_LIVE;
                    }
                    else
                    {
                    }

                    using (var destvm = sourcevm.virDomainMigrate(destination, flags, null, null, 0))
                    {
                        if (destvm.IsValid)
                        {
                            MessageBox.Show("Migration Successfull!!");
                        }
                        else
                        {
                            MessageBox.Show("Migration FAILED!!");
                        }
                    }
                }
            }
        }
Exemplo n.º 22
0
 public void Refresh(Libvirt.CS_Objects.Host con, string storagepoolname)
 {
     _connection = con;
     _poolname   = storagepoolname;
     UpdateStorageInfo();
 }
Exemplo n.º 23
0
 public Cpu_Ram_Create_Model(Libvirt.CS_Objects.Host con, Libvirt.Models.Concrete.Virtual_Machine d)
     : base(con, d)
 {
     _CPU_Layout_Validator        = new Libvirt.Service.Concrete.CPU_Layout_Validator();
     _Memory_Allocation_Validator = new Libvirt.Service.Concrete.Memory_Allocation_Validator();
 }
Exemplo n.º 24
0
 public Storage_Pool_Listing(Libvirt.CS_Objects.Host con, string storagepoolname)
 {
     this.Dock = DockStyle.Fill;
     InitializeComponent();
     Refresh(con, storagepoolname);
 }