Example #1
0
        /// <summary>
        /// IF apiVersion >= 2.5  Using subroutine AcquireCimServicesTicket in CIMUtil class
        /// is used to acquire the session id and its passed in both username and password.
        /// otherwise Username and Password is passed.
        /// The getCIMSessionId subroutine retrieve session-id.
        /// <summary>
        private void doOperation(String[] args)
        {
            String    apiType           = cb.getConnection()._sic.about.apiType;
            ArrayList supportedVersions = VersionUtil.getSupportedVersions(cb.get_option("url"));

            if (apiType.Equals("HostAgent"))
            {
                string url      = cb.get_option("url");
                string username = "";
                string password = "";
                string hostname = url.Substring(0, url.IndexOf("/sdk"));
                hostname = hostname.Substring(8);
                ManagedObjectReference hmor = cb.getConnection()._service.FindByIp(cb.getConnection().ServiceContent.searchIndex,
                                                                                   null, hostname, false);
                if (hmor != null)
                {
                    Cookie cookie = cb.getConnection()._service.CookieContainer.GetCookies(
                        new Uri(cb.get_option("url")))[0];
                    string cimSessionId = CIMUtil.getCIMSessionId(hmor, args, cookie);
                    username = cimSessionId;
                    password = cimSessionId;
                }
                else
                {
                    System.Console.WriteLine("Host " + hostname + " not found");
                    return;
                }

                string        cimurl  = url.Substring(0, url.IndexOf("/sdk")) + "/wsman";
                IWSManSession session = createWSManConnection(cimurl, username, password);

                string urlString = "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_Fan";
                /// IWSManEnumerator enumerates all the CPU_Fan CIM Instances
                IWSManEnumerator enumeratorFans = (IWSManEnumerator)
                                                  session.Enumerate(urlString,
                                                                    null, null, wsman.SessionFlagUseBasic() & wsman.SessionFlagCredUsernamePassword() &
                                                                    wsman.SessionFlagSkipCACheck() & wsman.SessionFlagUseNoAuthentication());

                while (!enumeratorFans.AtEndOfStream)
                {
                    String      response = enumeratorFans.ReadItem();
                    XmlDocument xDoc     = new XmlDocument();
                    xDoc.LoadXml(response);
                    /// displayPrettyXML subroutine displays XML after formatting
                    /// in command prompt.
                    displayPrettyXML(xDoc);
                }
            }
            else
            {
                System.Console.WriteLine("Support for VC Server not implemented");
            }
        }
Example #2
0
            /// <summary>
            /// Enumerates all instances of a CIM class using a CIM query language (WQL supported only)
            /// </summary>
            public List <string> Query(string CIMClass, string filter, string dialect)
            {
                List <string>         xml_responses   = new List <string>();
                string                resource        = "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/";
                IWSManResourceLocator resourceLocator = (IWSManResourceLocator)m_wsman.CreateResourceLocator(string.Format("{0}{1}", resource, CIMClass));

                try
                {
                    IWSManEnumerator vm_enum = (IWSManEnumerator)m_wsmanSession.Enumerate(resourceLocator, filter, dialect, 0);
                    while (!vm_enum.AtEndOfStream)
                    {
                        string ss = vm_enum.ReadItem();
                        xml_responses.Add(ss);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Failed: Query()", ex);
                }
                return(xml_responses);
            }