{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# EnumerateInstanceNames"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"#\" onclick=\"history.back()\">&lt;--- Back</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The [`EnumerateInstanceNames()`](https://pywbem.readthedocs.io/en/latest/client.html#pywbem.WBEMConnection.EnumerateInstanceNames) method returns a list of [`pywbem.CIMInstanceName`](https://pywbem.readthedocs.io/en/latest/client.html#pywbem.CIMInstanceName) objects which reference each instance of a particular CIM class (and its subclasses).\n",
    "\n",
    "[`CIMInstanceName`](https://pywbem.readthedocs.io/en/latest/client.html#pywbem.CIMInstanceName) objects are required as parameters for most PyWBEM calls as they uniquely identify a CIM instance on the managed node.\n",
    "\n",
    "The following code enumerates the instance paths of instances of the specified CIM class and prints their instance paths in WBEM URI format (see  [`CIMInstanceName.__str__()`](https://pywbem.readthedocs.io/en/latest/client.html#pywbem.CIMInstanceName.__str__)), and their key bindings (= key property values) (see [`CIMInstanceName.items()`](https://pywbem.readthedocs.io/en/latest/client.html#pywbem.CIMInstanceName.items))."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from __future__ import print_function\n",
    "import pywbem\n",
    "\n",
    "username = 'user'\n",
    "password = 'password'\n",
    "classname = 'CIM_ComputerSystem'\n",
    "namespace = 'root/cimv2'\n",
    "server = 'http://localhost'\n",
    "\n",
    "conn = pywbem.WBEMConnection(server, (username, password),\n",
    "                             no_verification=True)\n",
    "try:\n",
    "    paths = conn.EnumerateInstanceNames(classname, namespace)\n",
    "except pywbem.Error as exc:\n",
    "    print('Operation failed: %s' % exc)\n",
    "else:\n",
    "    print('Retrieved %s instance paths' % (len(paths)))\n",
    "    for path in paths:\n",
    "        print('instance path: %s' % path)\n",
    "        print('keybindings: %s' % path.items())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this example, the connection has no default CIM namespace set, so we supply it in the operation method.\n",
    "\n",
    "Note that you cannot assume that the ordering of the returned instance paths is the same as the ordering of the instances returned by `EnumerateInstances()`. The CIM standards do not require to maintain the same order between these operations. For this reason, PyWBEM did not bother to maintain the order of entities it receives in the protocol, but uses the standard Python semantic for dictionaries, namely to be unordered."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"#\" onclick=\"history.back()\">&lt;--- Back</a>"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
