Sanggu's blog




최상단 광고 코드

 추천 사이트

 애자일 이야기 : http://agile.egloos.com
 서명덕 기자의 인터넷 : http://itviewpoint.com
 비지니스 뉴스 : http://www.ciobiz.co.kr
 MOCOMSYS : http://www.mocomsys.com
 Apache Software : http://www.apache.org
 소프트웨어 기술경력관리: http://career.sw.or.kr
 한이음 (지식경제부): http://www.hanium.or.kr
 IT 기술 뉴스: http://www.bloter.net/
 IBM 티볼리 까페: http://cafe.naver.com/tivolitool.cafe
 JAVA jar 검색 : http://www.findjar.com
 VM Ware 가상화: http://www.vmware.com

2011년 10월 4일 화요일

Hyper-V programing 개발

개요


MS 에서 만든 가상화 솔루션이며 아래는 참고 자료입니다.

Management API


using System.Management;

namespace HyperVSamples
{
    class GetSummaryInformationClass
    {
        ManagementObject virtualSystemService = null;
        ManagementScope scope = null;

        GetSummaryInformationClass()
        {
            scope = new ManagementScope(@"root\virtualization", null);
            virtualSystemService = Utility.GetServiceObject
            (scope, "Msvm_VirtualSystemManagementService");
        }

        ManagementObject GetVirtualSystemSetting(string vmName)
        {
            ManagementObject virtualSystem = Utility.GetTargetComputer
                                            (vmName, scope);

            ManagementObjectCollection virtualSystemSettings = 
            virtualSystem.GetRelated
             (
                 "Msvm_VirtualSystemSettingData",
                 "Msvm_SettingsDefineState",
                 null,
                 null,
                 "SettingData",
                 "ManagedElement",
                 false,
                 null
             );

            ManagementObject virtualSystemSetting = null;

            foreach (ManagementObject instance in virtualSystemSettings)
            {
                virtualSystemSetting = instance;
                break;
            }

            return virtualSystemSetting;

        }

        void GetSummaryInformation(ManagementObject[] 
             virtualSystemSettings, UInt32[] requestedInformation)
        {
            ManagementBaseObject inParams = 
            virtualSystemService.GetMethodParameters("GetSummaryInformation");
            string[] settingPaths = new string[virtualSystemSettings.Length];
            for (int i = 0; i < settingPaths.Length; ++i)
            {
                settingPaths[i] = virtualSystemSettings[i].Path.Path;
            }

            inParams["SettingData"] = settingPaths;
            inParams["RequestedInformation"] = requestedInformation;

            ManagementBaseObject outParams = virtualSystemService.InvokeMethod
           ("GetSummaryInformation", inParams, null);

            if ((UInt32)outParams["ReturnValue"] == ReturnCode.Completed)
            {
                Console.WriteLine("Summary information was retrieved
                                   successfully.");

                ManagementBaseObject[] summaryInformationArray = 
               (ManagementBaseObject[])outParams["SummaryInformation"];

                foreach (ManagementBaseObject summaryInformation in
                         summaryInformationArray)
                {
                    Console.WriteLine("\nVirtual System Summary Information:");
                    foreach (UInt32 requested in requestedInformation)
                    {
                        switch (requested)
                        {
                            case 0:
                                Console.WriteLine("\n\tName: {0}", 
                                summaryInformation["Name"].ToString());
                                break;

                            case 1:
                                Console.WriteLine("\tElement Name: {0}",
                                summaryInformation["ElementName"].ToString());
                                break;

                            case 2:
                                Console.WriteLine("\tCreation Time: {0}",
                                summaryInformation["CreationTime"].ToString());
                                break;

                            case 3:
                                Console.WriteLine("\tNotes: {0}",
                                summaryInformation["Notes"].ToString());
                                break;

                            case 4:
                                Console.WriteLine("\tNumber of Processors:
                                {0}", summaryInformation
                                ["NumberofProcessors"].ToString());
                                break;
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("Failed to retrieve virtual system
                summary information");
            }

            inParams.Dispose();
            outParams.Dispose();
        }

        void Close()
        {
            this.virtualSystemService.Dispose();
        }

        static void Main(string[] args)
        {
            if (args != null && (args.Length < 2 || args.Length > 6))
            {
                Console.WriteLine("GetSummaryInformation vmName value1
                value2...");
                Console.WriteLine("value:");
                Console.WriteLine("\t0:Name");
                Console.WriteLine("\t1:Element Name");
                Console.WriteLine("\t2:Creation Time");
                Console.WriteLine("\t3:Notes");
                Console.WriteLine("\t4:Number of Processors");
                Console.WriteLine("\nExample: GetSummaryInformation 
                MyfirstVM 0 1 4");
                return;
            }

            GetSummaryInformationClass getSummaryInfo = new 
            GetSummaryInformationClass();
            string vmName = args[0];
            ManagementObject virtualSystemSetting = 
            getSummaryInfo.GetVirtualSystemSetting(vmName);
            ManagementObject[] settings = new ManagementObject[1];
            settings[0] = virtualSystemSetting;

            UInt32[] requestedInfo = new UInt32[args.Length - 1];

            for (int i = 1; i < args.Length; ++i)
            {
                requestedInfo[i - 1] = UInt32.Parse(args[i]);
            }
            getSummaryInfo.GetSummaryInformation(settings, requestedInfo);
            getSummaryInfo.Close();

            virtualSystemSetting.Dispose();
        }
    }


SummaryInformation Class : http://msdn.microsoft.com/en-us/library/cc136898(v=VS.85).aspx
[Dynamic, Provider("VmmsWmiInstanceAndMethodProvider")]
class Msvm_SummaryInformation{  
    string                       Name;  
    string                       ElementName;
    uint16                       EnabledState;  
    uint16                       HealthState;  
    string                       Notes;  
    uint16                       NumberOfProcessors;  
    uint8                        ThumbnailImage[];  
    DateTime                     CreationTime;  
    uint16                       ProcessorLoad;  
    uint16                       ProcessorLoadHistory[];  
    uint64                       MemoryUsage;  
    sint32                       MemoryAvailable;  
    sint32                       AvailableMemoryBuffer;  
    uint16                       Heartbeat;  
    uint64                       UpTime;  
    string                       GuestOperatingSystem;  
    uint16                       OperationalStatus[];  
    string                       StatusDescriptions[];  
    CIM_VirtualSystemSettingData Snapshots[];
    CIM_ConcreteJob              AsynchronousTasks[];  
    string                       AllocatedGPU;
}; 




댓글 없음:

댓글 쓰기