Exemple #1
0
def getEnumerated(classToBeEnumerated, idrac_ip, idrac_userName, idrac_password, \
                  rawOutput=True):
    """
    This function is used for getting output of enumeration class as speciified

    Function Owner : Nithya_V

    Date created : 9/5/2016

    @param classToBeEnumerated : (string) DCIM class for which data to be retrieved
    @param idrac_ip : (string) idrac ip of system for which data to be retrieved
    @param idrac_userName : (string) idrac user name of system for which data to be retrieved
    @param idrac_password : (string) idrac password of system for which data to be retrieved
    @param rawOutput : (string) output without parsing

    @return result : (string) Command Output, None in case of any error
    """
    try:
        remobj = Remote(idrac_ip, idrac_userName, idrac_password)
        print '\nENUMERATING THE CLASS ' + classToBeEnumerated + "\n"
        winrmobj = winrm.WinRM(transport=Subprocess())
        result = winrmobj.enumerate(cim_class=classToBeEnumerated, \
                        cim_namespace=namespace, remote=remobj, raw=rawOutput, uri_host=uri)
        if result == None:
            print 'Enumeration Command Failed'
            return None
        else:
            if rawOutput == False:
                print 'Number of Instances returned : ', len(result)
            return result
    except:
        traceback.print_exc()
        return None
Exemple #2
0
def test_enumerate():
    remote = Remote("172.23.27.58", 'root', 'calvin')
    r = wsman.enumerate("DCIM_AggregationMetricDefinition",
                        "root/dcim",
                        remote=remote)
    print r

    print "Enumerate Cache Stats", wsman.enumerate.cache_info()
Exemple #3
0
def get_vrtx_chassis(name):
    CLASSNAME = "DCIM_ModularChassisView"

    remote = Remote(name, 'root', 'foobar')
    rs = wsman.enumerate(CLASSNAME, WS_PATH, remote=remote, uri_host=SCHEMA)
    logging.debug("rs = {}".format(rs))

    return {'value': '0', 'tags': {'host': name}}
Exemple #4
0
def get_NICView():
    remote = Remote("172.26.4.55", 'root', 'calvin')
    results = wsman.enumerate_keys("DCIM_NICView", "root/dcim", remote=remote)

    # Find the reference we want a full GET on
    for reference in results:
        if reference.get("InstanceID")[0] == "NIC.Slot.2-2-4":
            break

    my_nic = wsman.get(reference, "", remote=remote)
    print "Found NIC", my_nic
Exemple #5
0
def store_enum():
    import shelve
    import ut

    remote = Remote("172.26.4.55", 'root', 'calvin')
    r = wsman.enumerate("DCIM_AggregationMetricDefinition",
                        "root/dcim",
                        remote=remote)
    r_ = wsman.enumerate_keys("DCIM_AggregationMetricDefinition",
                              "root/dcim",
                              remote=remote)

    ut.associate(r, r_)

    store = shelve.open("instances")
    store["CIL"] = r
    store.close()
Exemple #6
0
def get(ip, force_fault=False):
    remote = Remote(ip, 'root', 'calvin')
    r = Reference("DCIM_RAIDService")

    if force_fault:
        r.set_resource_uri(
            "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/root/dcim/DCIM_AIDService"
        )
    else:
        r.set_resource_uri(
            "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/root/dcim/DCIM_RAIDService"
        )

    r.set("__cimnamespace", "root/dcim")
    r.set("CreationClassName", "DCIM_RAIDService")
    r.set("SystemName", "DCIM:ComputerSystem")
    r.set("Name", "DCIM:RAIDService")
    r.set("SystemCreationClassName", "DCIM_ComputerSystem")

    s = wsman.get(r, "", remote=remote)
    print "Result", s
    return s
Exemple #7
0
def set_test(ip):
    remote = Remote(ip, 'root', 'calvin')
    refs = wsman.enumerate_keys("DCIM_SystemInteger",
                                "root/dcim",
                                remote=remote)
    for ref in refs:
        if ref.get("InstanceID"
                   )[0] == "System.Embedded.1#ServerPwr.1#PowerCapValue":
            print ref.resource_uri

            # Show the properties of the system
            instance = wsman.get(ref, "", remote=remote)
            for k, v in instance.items:
                print k, v[0]

            # Set the value
            set_result = wsman.set(ref,
                                   "",
                                   properties={"CurrentValue": 133},
                                   remote=remote)
            if isinstance(set_result, Fault):
                print set_result.toString()
Exemple #8
0
def test_enumerate(ip):
    remote = Remote(ip, 'root', 'calvin')
    print "Enumerating %s" % CLASSNAME
    r = wsman.enumerate(CLASSNAME, "root/dcim", remote=remote)
    total_count = len(r)
    print "Found %d Unfiltered instances" % len(r)

    print "XPath Query"
    try:
        query = XPathFilter(query='../%s[WWN="78:2B:CB:4B:CD:9E"]' % CLASSNAME)
        r = wsman.enumerate(CLASSNAME, "root/dcim", remote=remote, query=query)
        print "Found %d instances" % len(r)
    except:
        print "Error"

    print "CQL Query"
    try:
        query = CQLFilter(
            query='select * from %s where WWN = "78:2B:CB:4B:CD:9E"' %
            CLASSNAME)
        r = wsman.enumerate(CLASSNAME, "root/dcim", remote=remote, query=query)
        print "Found %d instances" % len(r)
    except:
        print "Error"

    print "WQL Query"
    try:
        query = WQLFilter(
            query='select * from %s where WWN = "78:2B:CB:4B:CD:9E"' %
            CLASSNAME)
        r = wsman.enumerate(CLASSNAME, "root/dcim", remote=remote, query=query)
        print "Found %d instances" % len(r)
    except:
        print "Error"

    print "Selector Query"
    try:
        query = SelectorFilter(query='{DeviceNumber = "0"}')
        r = wsman.enumerate(CLASSNAME, "root/dcim", remote=remote, query=query)
        print "Found %d instances" % len(r)
    except:
        print "Error"

    print "Testing enumerate_keys"
    r = wsman.enumerate_keys(CLASSNAME, "root/dcim", remote=remote)
    print "XPath Query"
    try:
        query = XPathFilter(query='../%s[WWN="78:2B:CB:4B:CD:9E"]' % CLASSNAME)
        r = wsman.enumerate_keys(CLASSNAME,
                                 "root/dcim",
                                 remote=remote,
                                 query=query)
        print "Found %d instances" % len(r)
    except:
        print "Error"

    print "CQL Query"
    try:
        query = CQLFilter(
            query='select * from %s where WWN = "78:2B:CB:4B:CD:9E"' %
            CLASSNAME)
        r = wsman.enumerate_keys(CLASSNAME,
                                 "root/dcim",
                                 remote=remote,
                                 query=query)
        print "Found %d instances" % len(r)
    except:
        print "Error"

    print "WQL Query"
    try:
        query = WQLFilter(
            query='select * from %s where WWN = "78:2B:CB:4B:CD:9E"' %
            CLASSNAME)
        r = wsman.enumerate_keys(CLASSNAME,
                                 "root/dcim",
                                 remote=remote,
                                 query=query)
        print "Found %d instances" % len(r)
    except:
        print "Error"

    print "Selector Query"
    try:
        query = SelectorFilter(query='{WWN = "78:2B:CB:4B:CD:9E"}')
        r = wsman.enumerate_keys(CLASSNAME,
                                 "root/dcim",
                                 remote=remote,
                                 query=query)
        print "Found %d instances" % len(r)
    except:
        print "Error"
    """
Exemple #9
0
fmt = OutputFormatter(
    '%(asctime)s %(levelname)s %(name)s %(message)s %(command)s %(output)s %(duration)fs',
    pretty=True)
fHandle = logging.FileHandler("test.txt", mode="w")
fHandle.setFormatter(fmt)

# Set up the HTML log
html = HTMLHandler("test.html", pretty=True)
log = logging.getLogger("")
log.setLevel(logging.DEBUG)
log.addHandler(fHandle)
log.addHandler(html)

# Remote object

# WSMan test
wsman = WSMan(transport=Subprocess())

remote = Remote("172.26.4.55", 'root', 'calvin')
results = wsman.enumerate_keys("DCIM_NICView", "root/dcim", remote=remote)

# Find the reference we want a full GET on
for reference in results:
    if reference.get("InstanceID")[0] == "NIC.Slot.2-2-4":
        break
my_nic = wsman.get(reference, "", remote=remote)

for property in my_nic.keys:
    print property, ":", my_nic.get(property)
print "Found NIC", my_nic
Exemple #10
0
#
#    WSManAPI is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Lesser General Public License for more details.
#
#    You should have received a copy of the GNU Lesser General Public License
#    along with WSManAPI.  If not, see <http://www.gnu.org/licenses/>.

from wsman import WSMan
from wsman.provider.remote import Remote
from wsman.transport.dummy import Dummy
from wsman.transport.process import Subprocess
from wsman.response.reference import Reference
from wsman.response.fault import Fault
from wsman.format.command import OutputFormatter
from wsman.loghandlers.HTMLHandler import HTMLHandler

# WSMan test
wsman = WSMan(transport=Dummy())

if __name__ == "__main__":
    remote = Remote("172.23.200.13", 'root', 'calvin')
    results = wsman.identify(remote=remote, raw=False)
    print results
    if not isinstance(results, list):
        results = [results]

    for result in results:
        print result.toString()