public object vbdcollect(Session session, List <XenRef <VM> > vmRefs)
        {
            ArrayList vmc    = new ArrayList();
            string    mydocs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            int    te = 1;
            string log;
            string entry;

            try
            {
                foreach (XenRef <VM> vmRef in vmRefs)
                {
                    VM vm = VM.get_record(session, vmRef);
                    if (!vm.is_a_template && !vm.is_control_domain)
                    {
                        List <XenRef <VBD> > vbdRefs = VBD.get_all(session);
                        vmc.Add("Virtual Machine Name:");
                        try
                        {
                            vmc.Add(Convert.ToString(vm.name_label));
                        }
                        catch
                        {
                            vmc.Add("Data not available");
                            log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                            entry = DateTime.Now.ToString("HH:mm:ss") + " VBD Collection Error " + te;
                            writelog.entry(log, entry);
                            te++;
                        }
                        vmc.Add("Number of VBD devices:");
                        try
                        {
                            vmc.Add(Convert.ToString(vm.VBDs.Count));
                        }
                        catch
                        {
                            vmc.Add("Data not available");
                            log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                            entry = DateTime.Now.ToString("HH:mm:ss") + " VBD Collection Error " + te;
                            writelog.entry(log, entry);
                            te++;
                        }
                        try
                        {
                            for (int i = 0; i <= vm.VBDs.Count - 1;)
                            {
                                if (vm.VBDs[i].ServerOpaqueRef == "OpaqueRef:NULL")
                                {
                                }
                                else
                                {
                                    VBD vbd = VBD.get_record(session, (String)vm.VBDs[i].ServerOpaqueRef);

                                    vmc.Add("Device Name:");
                                    try
                                    {
                                        vmc.Add(Convert.ToString(vbd.device));
                                    }
                                    catch
                                    {
                                        vmc.Add("Data not available");
                                        log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                                        entry = DateTime.Now.ToString("HH:mm:ss") + " VBD Collection Error " + te;
                                        writelog.entry(log, entry);
                                        te++;
                                    }
                                    vmc.Add("Device is currently attached:");
                                    try
                                    {
                                        vmc.Add(Convert.ToString(vbd.currently_attached));
                                    }
                                    catch
                                    {
                                        vmc.Add("Data not available");
                                        log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                                        entry = DateTime.Now.ToString("HH:mm:ss") + " VBD Collection Error " + te;
                                        writelog.entry(log, entry);
                                        te++;
                                    }
                                    vmc.Add("Device Read/Write Mode:");
                                    try
                                    {
                                        vmc.Add("Not displayed in demo version");
                                    }
                                    catch
                                    {
                                        vmc.Add("Data not available");
                                        log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                                        entry = DateTime.Now.ToString("HH:mm:ss") + " VBD Collection Error " + te;
                                        writelog.entry(log, entry);
                                        te++;
                                    }
                                    vmc.Add("Device Type:");
                                    try
                                    {
                                        vmc.Add("Not displayed in demo version");
                                    }
                                    catch
                                    {
                                        vmc.Add("Data not available");
                                        log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                                        entry = DateTime.Now.ToString("HH:mm:ss") + " VBD Collection Error " + te;
                                        writelog.entry(log, entry);
                                        te++;
                                    }
                                    i++;
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
                    te = 1;
                }

                log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                entry = DateTime.Now.ToString("HH:mm:ss") + " VBD Collection Finished";
                writelog.entry(log, entry);
            }


            catch
            {
                log   = mydocs + "\\Halfmode\\HalfmodeConnection.log";
                entry = DateTime.Now.ToString("HH:mm:ss") + " VBD Collection Failed";
                writelog.entry(log, entry);
            }
            if ((vmc.Count & 2) == 0)
            {
            }
            else
            {
                vmc.Add(" ");
            }
            return(vmc);
        }
示例#2
0
        public object vdicollect(Session session)
        {
            ArrayList    vmc    = new ArrayList();
            string       mydocs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            StreamWriter SW;
            int          vd = 1;

            try
            {
                List <XenRef <VM> >  vmRefs  = VM.get_all(session);
                List <XenRef <VBD> > vbdRefs = VBD.get_all(session);
                List <XenRef <VDI> > vdiRefs = VDI.get_all(session);



                foreach (XenRef <VM> vmRef in vmRefs)
                {
                    VM vm = VM.get_record(session, vmRef);
                    if (!vm.is_a_template && !vm.is_control_domain)
                    {
                        for (int i = 0; i <= vm.VBDs.Count - 1;)
                        {
                            if (vm.VBDs[i].ServerOpaqueRef == "OpaqueRef:NULL")
                            {
                            }
                            else
                            {
                                // get the info from VDB first.
                                VBD vbd = VBD.get_record(session, (String)vm.VBDs[i].ServerOpaqueRef);

                                if (vbd.VDI.ServerOpaqueRef == "OpaqueRef:NULL")
                                {
                                }
                                else
                                {
                                    vmc.Add("Virtual Machine Name:");
                                    try
                                    {
                                        vmc.Add(Convert.ToString(vm.name_label));
                                    }
                                    catch
                                    {
                                        vmc.Add("Data not available");
                                        SW = File.AppendText(mydocs + "\\Halfmode\\HalfmodeConnection.log");
                                        SW.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " VDI Collection Error " + vd);
                                        SW.Close();
                                        vd++;
                                    }
                                    VDI vdi = VDI.get_record(session, vbd.VDI.ServerOpaqueRef);
                                    vmc.Add("Virtual Disk Name:");
                                    try
                                    {
                                        vmc.Add(Convert.ToString(vdi.name_label));
                                    }
                                    catch
                                    {
                                        vmc.Add("Data not available");
                                        SW = File.AppendText(mydocs + "\\Halfmode\\HalfmodeConnection.log");
                                        SW.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " VDI Collection Error " + vd);
                                        SW.Close();
                                        vd++;
                                    }
                                    vmc.Add("Virtual Description:");
                                    try
                                    {
                                        vmc.Add(Convert.ToString(vdi.name_description));
                                    }
                                    catch
                                    {
                                        vmc.Add("Data not available");
                                        SW = File.AppendText(mydocs + "\\Halfmode\\HalfmodeConnection.log");
                                        SW.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " VDI Collection Error " + vd);
                                        SW.Close();
                                        vd++;
                                    }
                                    vmc.Add("Virtual Disk Size:");
                                    try
                                    {
                                        vmc.Add("Not displayed in demo version");
                                    }
                                    catch
                                    {
                                        vmc.Add("Data not available");
                                        SW = File.AppendText(mydocs + "\\Halfmode\\HalfmodeConnection.log");
                                        SW.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " VDI Collection Error " + vd);
                                        SW.Close();
                                        vd++;
                                    }
                                    vmc.Add("Physical Disk Usage:");
                                    try
                                    {
                                        vmc.Add("Not displayed in demo version");
                                    }
                                    catch
                                    {
                                        vmc.Add("Data not available");
                                        SW = File.AppendText(mydocs + "\\Halfmode\\HalfmodeConnection.log");
                                        SW.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " VDI Collection Error " + vd);
                                        SW.Close();
                                        vd++;
                                    }

                                    SR sr = SR.get_record(session, vdi.SR.ServerOpaqueRef);
                                    vmc.Add("Parent Storage Repositry:");
                                    try
                                    {
                                        vmc.Add(Convert.ToString(sr.name_label));
                                    }
                                    catch
                                    {
                                        vmc.Add("Data not available");
                                        SW = File.AppendText(mydocs + "\\Halfmode\\HalfmodeConnection.log");
                                        SW.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " VDI Collection Error " + vd);
                                        SW.Close();
                                        vd++;
                                    }

                                    vmc.Add("Is VDI read-only:");
                                    try
                                    {
                                        vmc.Add(Convert.ToString(vdi.read_only));
                                    }
                                    catch
                                    {
                                        vmc.Add("Data not available");
                                        SW = File.AppendText(mydocs + "\\Halfmode\\HalfmodeConnection.log");
                                        SW.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " VDI Collection Error " + vd);
                                        SW.Close();
                                        vd++;
                                    }
                                    vmc.Add("Is VDI Shareable:");
                                    try
                                    {
                                        vmc.Add("Not displayed in demo version");
                                    }
                                    catch
                                    {
                                        vmc.Add("Data not available");
                                        SW = File.AppendText(mydocs + "\\Halfmode\\HalfmodeConnection.log");
                                        SW.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " VDI Collection Error " + vd);
                                        SW.Close();
                                        vd++;
                                    }
                                }

                                i++;
                            }
                        }
                    }
                    vd = 1;
                }
                SW = File.AppendText(mydocs + "\\Halfmode\\HalfmodeConnection.log");
                SW.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " VDI Collection Finished");
                SW.Close();
            }
            catch
            {
                SW = File.AppendText(mydocs + "\\Halfmode\\HalfmodeConnection.log");
                SW.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " VDI Collection Failed");
                SW.Close();
            }
            if ((vmc.Count & 2) == 0)
            {
            }
            else
            {
                vmc.Add(" ");
            }
            return(vmc);
        }