Esempio n. 1
0
File: data.py Progetto: anoother/wry
def client_get(*args, **kwargs):
    if args[-1] == 'http://intel.com/wbem/wscim/1/amt-schema/1/AMT_BootSettingData':
        return pywsman.create_doc_from_string('''<?xml version="1.0" encoding="UTF-8"?>
<a:Envelope xmlns:a="http://www.w3.org/2003/05/soap-envelope" xmlns:b="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:c="http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd" xmlns:d="http://schemas.xmlsoap.org/ws/2005/02/trust" xmlns:e="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:f="http://schemas.dmtf.org/wbem/wsman/1/cimbinding.xsd" xmlns:g="http://intel.com/wbem/wscim/1/amt-schema/1/AMT_BootSettingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <a:Header>
    <b:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</b:To>
    <b:RelatesTo>uuid:d6ae5d5e-2419-1419-8004-80db73edaeb8</b:RelatesTo>
    <b:Action a:mustUnderstand="true">http://schemas.xmlsoap.org/ws/2004/09/transfer/GetResponse</b:Action>
    <b:MessageID>uuid:00000000-8086-8086-8086-00000000011C</b:MessageID>
    <c:ResourceURI>http://intel.com/wbem/wscim/1/amt-schema/1/AMT_BootSettingData</c:ResourceURI>
  </a:Header>
  <a:Body>
    <g:AMT_BootSettingData>
      <g:BIOSPause>false</g:BIOSPause>
      <g:BIOSSetup>false</g:BIOSSetup>
      <g:BootMediaIndex>0</g:BootMediaIndex>
      <g:ConfigurationDataReset>false</g:ConfigurationDataReset>
      <g:ElementName>Intel(r) AMT Boot Configuration Settings</g:ElementName>
      <g:EnforceSecureBoot>false</g:EnforceSecureBoot>
      <g:FirmwareVerbosity>0</g:FirmwareVerbosity>
      <g:ForcedProgressEvents>false</g:ForcedProgressEvents>
      <g:IDERBootDevice>0</g:IDERBootDevice>
      <g:InstanceID>Intel(r) AMT:BootSettingData 0</g:InstanceID>
      <g:LockKeyboard>false</g:LockKeyboard>
      <g:LockPowerButton>false</g:LockPowerButton>
      <g:LockResetButton>false</g:LockResetButton>
      <g:LockSleepButton>false</g:LockSleepButton>
      <g:OwningEntity>Intel(r) AMT</g:OwningEntity>
      <g:ReflashBIOS>false</g:ReflashBIOS>
      <g:UseIDER>false</g:UseIDER>
      <g:UseSOL>false</g:UseSOL>
      <g:UseSafeMode>false</g:UseSafeMode>
      <g:UserPasswordBypass>false</g:UserPasswordBypass>
    </g:AMT_BootSettingData>
  </a:Body>
</a:Envelope>''')
    elif args[-1] == 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_BootConfigSetting':
        return pywsman.create_doc_from_string('''<?xml version="1.0" encoding="UTF-8"?>
<a:Envelope xmlns:a="http://www.w3.org/2003/05/soap-envelope" xmlns:b="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:c="http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd" xmlns:d="http://schemas.xmlsoap.org/ws/2005/02/trust" xmlns:e="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:f="http://schemas.dmtf.org/wbem/wsman/1/cimbinding.xsd" xmlns:g="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_BootConfigSetting" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <a:Header>
    <b:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</b:To>
    <b:RelatesTo>uuid:6718d621-241c-141c-800e-80db73edaeb8</b:RelatesTo>
    <b:Action a:mustUnderstand="true">http://schemas.xmlsoap.org/ws/2004/09/transfer/GetResponse</b:Action>
    <b:MessageID>uuid:00000000-8086-8086-8086-000000000267</b:MessageID>
    <c:ResourceURI>http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_BootConfigSetting</c:ResourceURI>
  </a:Header>
  <a:Body>
    <g:CIM_BootConfigSetting>
      <g:ElementName>Intel(r) AMT: Boot Configuration</g:ElementName>
      <g:InstanceID>Intel(r) AMT: Boot Configuration 0</g:InstanceID>
    </g:CIM_BootConfigSetting>
  </a:Body>
</a:Envelope>''')
    raise RuntimeError(args, kwargs)
Esempio n. 2
0
    def really_apply_settings(self, type, target):
        xml = ""
        schema = "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/root/dcim/DCIM_%sService" % type
        method = "CreateTargetedConfigJob"
        client = self.get_dell_client()

        client_options = pywsman.ClientOptions()
        selectors = generate_dell_selectors(type)
        set_dell_selectors(client_options, selectors)

        xml = '''<p:Target>%s</p:Target>
        <p:RebootJobType>2</p:RebootJobType>
        <p:ScheduledStartTime>TIME_NOW</p:ScheduledStartTime>''' % target

        xml = generate_xml(method, schema, xml)

        wsxml = pywsman.create_doc_from_string(xml)

        result = client.invoke(client_options, schema, method, wsxml)

        if result is None:
            return None

        status = result.root().find(None, "ReturnValue").__str__()

        if status == '0' or status == '4096':
            selector = result.root().find(None, "Selector")
            while selector:
                attr = selector.attr_find(None, 'Name')
                if attr.value() == 'InstanceID':
                    return selector.__str__()
                selector = selector.next()

        return None
Esempio n. 3
0
    def really_apply_settings(self, type, target):
        xml = ""
        schema = "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/root/dcim/DCIM_%sService" % type
        method = "CreateTargetedConfigJob"
        client = self.get_dell_client()

        client_options = pywsman.ClientOptions()
        selectors = generate_dell_selectors(type)
        set_dell_selectors(client_options, selectors)

        xml = '''<p:Target>%s</p:Target>
        <p:RebootJobType>2</p:RebootJobType>
        <p:ScheduledStartTime>TIME_NOW</p:ScheduledStartTime>''' % target

        xml = generate_xml(method, schema, xml)

        wsxml = pywsman.create_doc_from_string(xml)

        result = client.invoke(client_options, schema, method, wsxml)

        if result is None:
            return None

        status = result.root().find(None, "ReturnValue").__str__()

        if status == '0' or status == '4096':
            selector = result.root().find(None, "Selector")
            while selector:
                attr = selector.attr_find(None, 'Name')
                if attr.value() == 'InstanceID':
                    return selector.__str__()
                selector = selector.next()

        return None
Esempio n. 4
0
File: data.py Progetto: anoother/wry
def client_enumerate(client, options, _, uri):
    if uri == 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_BootSourceSetting':
        return pywsman.create_doc_from_string('''<?xml version="1.0" encoding="UTF-8"?>
<a:Envelope xmlns:a="http://www.w3.org/2003/05/soap-envelope" xmlns:b="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:c="http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd" xmlns:d="http://schemas.xmlsoap.org/ws/2005/02/trust" xmlns:e="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:f="http://schemas.dmtf.org/wbem/wsman/1/cimbinding.xsd" xmlns:g="http://schemas.xmlsoap.org/ws/2004/09/enumeration" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <a:Header>
    <b:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</b:To>
    <b:RelatesTo>uuid:0041f82d-241a-141a-8002-80db73edaeb8</b:RelatesTo>
    <b:Action a:mustUnderstand="true">http://schemas.xmlsoap.org/ws/2004/09/enumeration/EnumerateResponse</b:Action>
    <b:MessageID>uuid:00000000-8086-8086-8086-00000000021D</b:MessageID>
    <c:ResourceURI>http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_BootSourceSetting</c:ResourceURI>
  </a:Header>
  <a:Body>
    <g:EnumerateResponse>
      <g:EnumerationContext>25000000-0000-0000-0000-000000000000</g:EnumerationContext>
    </g:EnumerateResponse>
  </a:Body>
</a:Envelope>
''')
    else:
        raise RuntimeError
Esempio n. 5
0
    def force_reboot(self):
        schema = "http://schemas.dell.com/wbem/wscim/1/cim-schema/2/DCIM_CSPowerManagementService"
        client = self.get_dell_client()
        client_options = pywsman.ClientOptions()
        method = "RequestPowerStateChange"

        xml = '''<p:PowerState>5</p:PowerState>'''
        xml = generate_xml(method, schema, xml)

        wsxml = pywsman.create_doc_from_string(xml)

        set_power_selectors(client_options)

        result = client.invoke(client_options, schema, method, wsxml)

        if result is None:
            return False

        status = result.root().find(None, "ReturnValue").__str__()

        if status == '0':
            return True

        return False
Esempio n. 6
0
    def force_reboot(self):
        schema = "http://schemas.dell.com/wbem/wscim/1/cim-schema/2/DCIM_CSPowerManagementService"
        client = self.get_dell_client()
        client_options = pywsman.ClientOptions()
        method = "RequestPowerStateChange"

        xml = '''<p:PowerState>5</p:PowerState>'''
        xml = generate_xml(method, schema, xml)

        wsxml = pywsman.create_doc_from_string(xml)

        set_power_selectors(client_options)

        result = client.invoke(client_options, schema, method, wsxml)

        if result is None:
            return False

        status = result.root().find(None, "ReturnValue").__str__()

        if status == '0':
            return True

        return False
Esempio n. 7
0
    def set_options(self, options, name, settings_type):
        changes = False
        schema = "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/root/dcim/DCIM_%sService" % name
        method = "SetAttributes"

        if settings_type:
            xml = "<p:Target>%s</p:Target>" % settings_type
        else:
            xml = ""

        for option in options.keys():
            if options[option]['dell_schema'] != name:
                continue

            # Each NIC needs to have settings applied separately. Skip any
            # that we haven't been asked to handle.
            fqdd = options[option]['dell_fqdd']
            if fqdd and fqdd != settings_type:
                continue

            # Skip option if we haven't been asked to set a value
            if options[option]['new_value'] is None:
                continue

            # Skip option if it matches the current state, as long as there's
            # no outstanding pending changes
            if options[option]['current'] == options[option]['new_value']:
                if options[option]['pending'] == []:
                    continue

            # Boot options are somewhat magic, so handle them specially
            if options[option]['dell_boot']:
                continue

            changes = True

            xml += "<p:AttributeName>%s</p:AttributeName>\r\n" % options[
                option]['dell_name']
            xml += "<p:AttributeValue>%s</p:AttributeValue>\r\n" % options[
                option]['new_value']

        if not changes:
            return True

        xml = generate_xml(method, schema, xml)

        wsxml = pywsman.create_doc_from_string(xml)

        client = self.get_dell_client()
        client_options = pywsman.ClientOptions()
        selectors = generate_dell_selectors(name)
        set_dell_selectors(client_options, selectors)

        result = client.invoke(client_options, schema, method, wsxml)

        if result is None:
            return False

        status = result.root().find(None, "ReturnValue")
        if status is None:
            return False

        status = status.__str__()

        if status != "0":
            return False

        reboot = result.root().find(None, "RebootRequired")
        if reboot is not None:
            reboot = reboot.__str__()
            if reboot == "Yes":
                self.reboot_required = True

        if name == "LC":
            method = "CreateConfigJob"
            result = client.invoke(client_options, schema, method, None)

        if name == "iDRACCard":
            client = self.get_dell_client()
            client_options = pywsman.ClientOptions()
            method = "CreateTargetedConfigJob"
            xml = "<p:Target>%s</p:Target> \
<p:ScheduledStartTime>TIME_NOW</p:ScheduledStartTime>"                                                       % \
            settings_type

            xml = generate_xml(method, schema, xml)
            wsxml = pywsman.create_doc_from_string(xml)

            selectors = generate_dell_selectors(name)
            set_dell_selectors(client_options, selectors)
            client_options.set_cim_namespace("root/dcim")
            result = client.invoke(client_options, schema, method, wsxml)
Esempio n. 8
0
    def set_boot_options(self, options):
        schema = "http://schemas.dell.com/wbem/wscim/1/cim-schema/2/DCIM_BootConfigSetting"
        method = "ChangeBootOrderByInstanceID"
        enable_method = "ChangeBootSourceState"
        changes = False

        client = self.get_dell_client()

        client_options = pywsman.ClientOptions()

        client_options.set_cim_namespace("root/dcim")

        xml = ""
        enable_xml = ""
        for option in options:
            if not options[option]['dell_boot']:
                continue

            # Skip option if we haven't been asked to set a value
            if options[option]['new_value'] is None:
                continue
            # Skip option if it matches the current state, as long as there's
            # no outstanding pending changes
            if options[option]['current'] == options[option]['new_value']:
                if options[option]['pending'] == []:
                    continue

            # Skip option if it matches the already pending state
            if options[option]['pending'] == options[option]['new_value']:
                continue

            changes = True

            boot_type = options[option]['dell_type']
            for boot in options[option]['new_value']:
                boot_id = options[option]['dell_id'][boot]
                enabled = options[option]['dell_enabled'][boot]
                xml += "<p:source>%s</p:source>" % boot_id
                enable_xml += "<p:EnabledState>1</p:EnabledState>"
                enable_xml += "<p:source>%s</p:source>" % boot_id

        if not changes:
            return True

        enable_xml = generate_xml(enable_method, schema, enable_xml)
        client_options.add_selector("InstanceID", boot_type)
        wsxml = pywsman.create_doc_from_string(enable_xml)
        result = client.invoke(client_options, schema, enable_method, wsxml)

        if result is None:
            return False

        status = result.root().find(None, "ReturnValue")
        if status is None:
            return False

        status = status.__str__()

        if status == "2":
            return False

        xml = generate_xml(method, schema, xml)
        wsxml = pywsman.create_doc_from_string(xml)
        result = client.invoke(client_options, schema, method, wsxml)

        if result is None:
            return False

        status = result.root().find(None, "ReturnValue")
        if status is None:
            return False

        status = status.__str__()

        if status != "0":
            return False
Esempio n. 9
0
File: data.py Progetto: anoother/wry
 def client_pull(client, options, _, uri, context):
     if uri == 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_BootSourceSetting':
         if context == '25000000-0000-0000-0000-000000000000':
             return pywsman.create_doc_from_string(boot_source_setting_values.pop(0))
Esempio n. 10
0
def wsman_invoke(client, resource_uri, method, data=None, options=None, silent=False):
    '''Invoke method on target server.'''
    doc = client.invoke(options, resource_uri, str(method), pywsman.create_doc_from_string(str(data)))
    return _validate(doc, silent=silent)
Esempio n. 11
0
    def set_options(self, options, name, settings_type):
        changes = False
        schema = "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/root/dcim/DCIM_%sService" % name
        method = "SetAttributes"

        if settings_type:
            xml = "<p:Target>%s</p:Target>" % settings_type
        else:
            xml = ""

        for option in options.keys():
            if options[option]['dell_schema'] != name:
                continue

            # Each NIC needs to have settings applied separately. Skip any
            # that we haven't been asked to handle.
            fqdd = options[option]['dell_fqdd']
            if fqdd and fqdd != settings_type:
                continue

            # Skip option if we haven't been asked to set a value
            if options[option]['new_value'] is None:
                continue

            # Skip option if it matches the current state, as long as there's
            # no outstanding pending changes
            if options[option]['current'] == options[option]['new_value']:
                if options[option]['pending'] == []:
                    continue

            # Boot options are somewhat magic, so handle them specially
            if options[option]['dell_boot']:
                continue

            changes = True

            xml += "<p:AttributeName>%s</p:AttributeName>\r\n" % options[option]['dell_name']
            xml += "<p:AttributeValue>%s</p:AttributeValue>\r\n" % options[option]['new_value']

        if not changes:
            return True

        xml = generate_xml(method, schema, xml)

        wsxml = pywsman.create_doc_from_string(xml)

        client = self.get_dell_client()
        client_options = pywsman.ClientOptions()
        selectors = generate_dell_selectors(name)
        set_dell_selectors(client_options, selectors)

        result = client.invoke(client_options, schema, method, wsxml)

        if result is None:
            return False

        status = result.root().find(None, "ReturnValue")
        if status is None:
            return False

        status = status.__str__()

        if status != "0":
            return False

        reboot = result.root().find(None, "RebootRequired")
        if reboot is not None:
            reboot = reboot.__str__()
            if reboot == "Yes":
                self.reboot_required = True

        if name == "LC":
            method = "CreateConfigJob"
            result = client.invoke(client_options, schema, method, None)

        if name == "iDRACCard":
            client = self.get_dell_client()
            client_options = pywsman.ClientOptions()
            method = "CreateTargetedConfigJob"
            xml = "<p:Target>%s</p:Target> \
<p:ScheduledStartTime>TIME_NOW</p:ScheduledStartTime>" % \
            settings_type

            xml = generate_xml(method, schema, xml)
            wsxml = pywsman.create_doc_from_string(xml)

            selectors = generate_dell_selectors(name)
            set_dell_selectors(client_options, selectors)
            client_options.set_cim_namespace("root/dcim")
            result = client.invoke(client_options, schema, method, wsxml)
Esempio n. 12
0
    def set_boot_options(self, options):
        schema = "http://schemas.dell.com/wbem/wscim/1/cim-schema/2/DCIM_BootConfigSetting"
        method = "ChangeBootOrderByInstanceID"
        enable_method = "ChangeBootSourceState"
        changes = False

        client = self.get_dell_client()

        client_options = pywsman.ClientOptions()

        client_options.set_cim_namespace("root/dcim")

        xml = ""
        enable_xml = ""
        for option in options:
            if not options[option]['dell_boot']:
                continue

            # Skip option if we haven't been asked to set a value
            if options[option]['new_value'] is None:
                continue
            # Skip option if it matches the current state, as long as there's
            # no outstanding pending changes
            if options[option]['current'] == options[option]['new_value']:
                if options[option]['pending'] == []:
                    continue

            # Skip option if it matches the already pending state
            if options[option]['pending'] == options[option]['new_value']:
                continue

            changes = True

            boot_type = options[option]['dell_type']
            for boot in options[option]['new_value']:
                boot_id = options[option]['dell_id'][boot]
                enabled = options[option]['dell_enabled'][boot]
                xml += "<p:source>%s</p:source>" % boot_id
                enable_xml += "<p:EnabledState>1</p:EnabledState>"
                enable_xml += "<p:source>%s</p:source>" % boot_id

        if not changes:
            return True

        enable_xml = generate_xml(enable_method, schema, enable_xml)
        client_options.add_selector("InstanceID", boot_type)
        wsxml = pywsman.create_doc_from_string(enable_xml)
        result = client.invoke(client_options, schema, enable_method, wsxml)

        if result is None:
            return False

        status = result.root().find(None, "ReturnValue")
        if status is None:
            return False

        status = status.__str__()

        if status == "2":
            return False

        xml = generate_xml(method, schema, xml)
        wsxml = pywsman.create_doc_from_string(xml)
        result = client.invoke(client_options, schema, method, wsxml)

        if result is None:
            return False

        status = result.root().find(None, "ReturnValue")
        if status is None:
            return False

        status = status.__str__()

        if status != "0":
            return False