Package com.vmware.cim
Class CIMReader
- java.lang.Object
-
- com.vmware.connection.ConnectedVimServiceBase
-
- com.vmware.cim.CIMReader
-
@Sample(name="cim-reader", description="allows you to walk the Common Information Model (CIM) data associated with an ESX Host You cannot read CIM data from a vCenter. This sample relies on classes in the javax.cim and javax.wbem packages. Implementations can be found in the sblim-cim-client2-2.1.1.jar or equivalent library. This sample allows you to drill down into CIM information by first connecting to a CIM service then exploring it\'s namespaces, classes, and class instances. ") public class CIMReader extends ConnectedVimServiceBaseexamples of how to work with CIM and vSphere API together.Requires the sblim-cim-client2-2.1.1.jar and the sblim-cim-client2.properties files these must both be in the classpath. The sblim-cim-client2.properties should have the value
sblim.wbem.httpMPOST=trueset so that the CIM client functions properly.cim-reader allows you to walk the Common Information Model (CIM) data associated with an ESX Host You cannot read CIM data from a vCenter. --url <url> [required] full url to vcenter --username <username> [required] username on remote system --password <password> [required] password on remote system --host <host> optional host name or IP to gather CIM data from (only if not talking directly to an ESX Host) --instance <instance> optional the CIM class instance to list properties of, if none specified then the command will list all available instances of the specified class --namespace <namespace> optional the namespace to explore, if none is specified, then the command will list all namespaces available at the target. --port <port> optional The port number on our remote host that the CIM services are running on. Defaults to 5989 if not specified. --class <class> optional the CIM class to explore, if none specified, then the command will list all available class names under the namespace. --descendants <class> optional Display the class hierarchy for a given specified class.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.vmware.connection.ConnectedVimServiceBase
ConnectedVimServiceBase.ConnectionException
-
-
Field Summary
-
Fields inherited from class com.vmware.connection.ConnectedVimServiceBase
PROP_ME_NAME, SVC_INST_NAME
-
-
Constructor Summary
Constructors Constructor Description CIMReader()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Stringalias(javax.cim.CIMClass cimClass)pretty print a CIM classjava.lang.Stringalias(javax.cim.CIMInstance instance)produces a pretty print alias for an instancejava.lang.Stringalias(javax.cim.CIMObjectPath objectPath)create an "alias" string for an object path, this is intended for display purposes and not really for looking up the object path later.booleancheck(java.net.URL url)checks a URL to see if we can open a connection to itjava.net.URLcimBaseUrl()builds a base URL to use for CIMObjectPath objects based on the host and connection objects already present in this object on initializationjava.lang.StringcimProperties(javax.cim.CIMProperty<?>[] properties, java.lang.String format)Knows how to read CIMProperty objects and put them in a string formatjavax.wbem.client.WBEMClientclient(java.lang.String namespace)Two ways to build a client, either with a username and password for direct login to the ESX host or using a ticket.GetCimgetCim()java.lang.StringgetConnectionType()javax.cim.CIMInstancegetInstance(javax.wbem.client.WBEMClient client, java.lang.String objectPath)gets a specific instance of a CIM class.javax.cim.CIMInstancegetInstance(javax.wbem.client.WBEMClient client, javax.cim.CIMObjectPath cimObjectPath)gets a specific CIM instance based on a cimObjectPath instancestatic java.lang.StringGetParent(javax.cim.CIMClass Child)java.lang.StringinstanceProperties(javax.cim.CIMInstance instance)pretty print the properties of an instancejava.lang.BooleanisDirectConnection()java.lang.BooleanisDirectConnection(java.lang.String type)java.util.Collection<javax.cim.CIMClass>listClasses(javax.wbem.client.WBEMClient client, java.lang.String namespace)lists all the classes at the client that are availablejava.util.Collection<javax.cim.CIMClass>listdescendants(javax.wbem.client.WBEMClient client, java.lang.String namespace, java.lang.String classname)Displays a list of instances of a particular class at the clientjava.util.Collection<javax.cim.CIMInstance>listInstances(javax.wbem.client.WBEMClient client, java.lang.String namespace, java.lang.String classname)builds a list of instances of a particular class at the clientjava.util.Collection<javax.cim.CIMObjectPath>listNamespaces()creates a list of namespaces for a host, this is the same for ALL ESX hostsjava.util.Collection<java.lang.String>listNamespaces(java.util.Collection<javax.cim.CIMObjectPath> objectPaths)creates a set of namespaces...java.util.Map<java.lang.String,java.lang.Object>listProperties(javax.cim.CIMInstance instance)builds a list of properties as a map based on an instance, instance objects hold local copies of the properties associated with the server-side instance.voidrun()The primary action entry point for this sample, presumes that all the property setters have been called and connection and other settings have been injected.voidsetCimClass(java.lang.String cimClass)voidsetCimPort(java.lang.String port)voidsetdescendants(java.lang.Boolean descendants)voidsetHost(java.lang.String hostNameOrIp)voidsetInstance(java.lang.String name)voidsetNamespace(java.lang.String namespace)-
Methods inherited from class com.vmware.connection.ConnectedVimServiceBase
basicConnectionFromConnection, connect, disconnect, getServiceInstanceReference, setConnection, setHostConnection
-
-
-
-
Method Detail
-
setHost
@Option(name="host", required=false, description="host\'s entity name or IP to gather CIM data from (if not talking directly to the ESX host).") public void setHost(java.lang.String hostNameOrIp)
-
setCimPort
@Option(name="port", required=false, description="The port number on our remote host that the CIM services are running on. Defaults to 5989 if not specified.") public void setCimPort(java.lang.String port)
-
setNamespace
@Option(name="namespace", required=false, description="the namespace to explore, if none is specified, then the command will list all namespaces available at the target.") public void setNamespace(java.lang.String namespace)
-
setCimClass
@Option(name="class", required=false, description="the CIM class to explore, if none specified, then the command will list all available class names under the namespace.") public void setCimClass(java.lang.String cimClass)
-
setInstance
@Option(name="instance", required=false, description="the CIM class instance to list properties of, if none specified then the command will list all available instances of the specified class") public void setInstance(java.lang.String name)
-
setdescendants
@Option(name="descendants", required=false, description="the CIM class inheritance details the command will list class inheritance hierarchy for the specified class", parameter=false) public void setdescendants(java.lang.Boolean descendants)
-
cimBaseUrl
public java.net.URL cimBaseUrl()
builds a base URL to use for CIMObjectPath objects based on the host and connection objects already present in this object on initialization- Returns:
- a URL to talk to the CIM server on
-
check
public boolean check(java.net.URL url)
checks a URL to see if we can open a connection to it- Parameters:
url- - to examine- Returns:
- true if we can talk to the host
-
listNamespaces
public java.util.Collection<javax.cim.CIMObjectPath> listNamespaces() throws javax.wbem.WBEMExceptioncreates a list of namespaces for a host, this is the same for ALL ESX hosts- Returns:
- a collection of CIMObjectPath objects representing the namespaces on the host
- Throws:
javax.wbem.WBEMException- See Also:
CIMObjectPath
-
listNamespaces
public java.util.Collection<java.lang.String> listNamespaces(java.util.Collection<javax.cim.CIMObjectPath> objectPaths)
creates a set of namespaces... based on a collection of objectPaths- Parameters:
objectPaths- the object paths to examine- Returns:
- a set of unique namespace names (strings)
-
listClasses
public java.util.Collection<javax.cim.CIMClass> listClasses(javax.wbem.client.WBEMClient client, java.lang.String namespace) throws javax.wbem.WBEMExceptionlists all the classes at the client that are available- Parameters:
client- an initialized client at the hostnamespace- the namespace to look at- Returns:
- a collection of CIMClass objects available at the host + namespace
- Throws:
javax.wbem.WBEMException
-
listInstances
public java.util.Collection<javax.cim.CIMInstance> listInstances(javax.wbem.client.WBEMClient client, java.lang.String namespace, java.lang.String classname) throws javax.wbem.WBEMExceptionbuilds a list of instances of a particular class at the client- Parameters:
client- initialized client to usenamespace- the namespace to considerclassname- the class to examine- Returns:
- a collection of CIMInstances that are of the specified class
- Throws:
javax.wbem.WBEMException
-
listdescendants
public java.util.Collection<javax.cim.CIMClass> listdescendants(javax.wbem.client.WBEMClient client, java.lang.String namespace, java.lang.String classname) throws javax.wbem.WBEMExceptionDisplays a list of instances of a particular class at the client- Parameters:
client- initialized client to usenamespace- the namespace to considerclassname- the class to be used for the descendants- Returns:
- a collection of CIMInstances that are of the specified class
- Throws:
javax.wbem.WBEMException
-
GetParent
public static java.lang.String GetParent(javax.cim.CIMClass Child)
-
getInstance
public javax.cim.CIMInstance getInstance(javax.wbem.client.WBEMClient client, java.lang.String objectPath) throws javax.wbem.WBEMExceptiongets a specific instance of a CIM class. Remember to command line escape or otherwise properly encode the string representing the URI to the CIM object. The path often contains quotes and other special characters that confuse many simple-minded parsers.- Parameters:
client- a configured and initialized client to useobjectPath- as a URI to a specific instance- Returns:
- the instance specified by the objectPath
- Throws:
javax.wbem.WBEMException
-
getInstance
public javax.cim.CIMInstance getInstance(javax.wbem.client.WBEMClient client, javax.cim.CIMObjectPath cimObjectPath) throws javax.wbem.WBEMExceptiongets a specific CIM instance based on a cimObjectPath instance- Parameters:
client- a configured and initialized client to usecimObjectPath- a properly constructed CIMObjectPath representing the instance's location- Returns:
- an instance object representing the instance
- Throws:
javax.wbem.WBEMException
-
listProperties
public java.util.Map<java.lang.String,java.lang.Object> listProperties(javax.cim.CIMInstance instance) throws javax.wbem.WBEMExceptionbuilds a list of properties as a map based on an instance, instance objects hold local copies of the properties associated with the server-side instance. This may not be the whole set of properties.NOTE: be sure to use "getInstance(path,true,true,null)" if you want to see all the
- Parameters:
instance- the instance to examine (holds a local subset of properties)- Returns:
- a map of the properties available in the instance
- Throws:
javax.wbem.WBEMException
-
getCim
public GetCim getCim()
-
client
public javax.wbem.client.WBEMClient client(java.lang.String namespace)
Two ways to build a client, either with a username and password for direct login to the ESX host or using a ticket.- Parameters:
namespace-- Returns:
-
isDirectConnection
public java.lang.Boolean isDirectConnection()
-
getConnectionType
public java.lang.String getConnectionType()
-
isDirectConnection
public java.lang.Boolean isDirectConnection(java.lang.String type)
-
alias
public java.lang.String alias(javax.cim.CIMObjectPath objectPath)
create an "alias" string for an object path, this is intended for display purposes and not really for looking up the object path later. If you want to provide a canonical representation that can be used to find an instance use the CIMObjectPath toString method to produce a URI. The URI cannot necessarily specify an instance if the properties are too short.- Parameters:
objectPath-- Returns:
- a pretty print string representing the object for display
- See Also:
review the section on keys
-
alias
public java.lang.String alias(javax.cim.CIMClass cimClass)
pretty print a CIM class- Parameters:
cimClass-- Returns:
- the name of the class
-
alias
public java.lang.String alias(javax.cim.CIMInstance instance)
produces a pretty print alias for an instance- Parameters:
instance- to examine- Returns:
- string representation of the CIMInstance
-
instanceProperties
public java.lang.String instanceProperties(javax.cim.CIMInstance instance)
pretty print the properties of an instance- Parameters:
instance- examine this- Returns:
- a string pretty print of the instance's properties
-
cimProperties
public java.lang.String cimProperties(javax.cim.CIMProperty<?>[] properties, java.lang.String format)Knows how to read CIMProperty objects and put them in a string format- Parameters:
properties- to list out pretty printformat- to use in pretty print, like "%s='%s',"- Returns:
- a string representing the properties with the format string repeatedly applied
-
run
@Action public void run() throws javax.wbem.WBEMExceptionThe primary action entry point for this sample, presumes that all the property setters have been called and connection and other settings have been injected. The sample switches logically on the provided arguments set by the setter.- Throws:
javax.wbem.WBEMException
-
-