parent
9153b850b2
commit
400f9317ba
@ -0,0 +1,192 @@
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import collections
|
||||
|
||||
from dracclient.resources import uris
|
||||
from dracclient import utils
|
||||
from dracclient import wsman
|
||||
|
||||
Job = collections.namedtuple('Job', ['id', 'name', 'start_time', 'until_time',
|
||||
'message', 'state', 'percent_complete'])
|
||||
|
||||
|
||||
class JobManagement(object):
|
||||
|
||||
def __init__(self, client):
|
||||
"""Creates JobManagement object
|
||||
|
||||
:param client: an instance of WSManClient
|
||||
"""
|
||||
self.client = client
|
||||
|
||||
def list_jobs(self, only_unfinished=False):
|
||||
"""Returns a list of jobs from the job queue
|
||||
|
||||
:param only_unfinished: indicates whether only unfinished jobs should
|
||||
be returned
|
||||
:returns: a list of Job objects
|
||||
:raises: WSManRequestFailure on request failures
|
||||
:raises: WSManInvalidResponse when receiving invalid response
|
||||
:raises: DRACOperationFailed on error reported back by the DRAC
|
||||
interface
|
||||
"""
|
||||
|
||||
filter_query = None
|
||||
if only_unfinished:
|
||||
filter_query = ('select * from DCIM_LifecycleJob '
|
||||
'where Name != "CLEARALL" and '
|
||||
'JobStatus != "Reboot Completed" and '
|
||||
'JobStatus != "Completed" and '
|
||||
'JobStatus != "Completed with Errors" and '
|
||||
'JobStatus != "Failed"')
|
||||
|
||||
doc = self.client.enumerate(uris.DCIM_LifecycleJob,
|
||||
filter_query=filter_query)
|
||||
|
||||
drac_jobs = utils.find_xml(doc, 'DCIM_LifecycleJob',
|
||||
uris.DCIM_LifecycleJob, find_all=True)
|
||||
|
||||
return [self._parse_drac_job(drac_job) for drac_job in drac_jobs]
|
||||
|
||||
def get_job(self, job_id):
|
||||
"""Returns a job from the job queue
|
||||
|
||||
:param job_id: id of the job
|
||||
:returns: a Job object on successful query, None otherwise
|
||||
:raises: WSManRequestFailure on request failures
|
||||
:raises: WSManInvalidResponse when receiving invalid response
|
||||
:raises: DRACOperationFailed on error reported back by the DRAC
|
||||
interface
|
||||
"""
|
||||
|
||||
filter_query = ('select * from DCIM_LifecycleJob where InstanceID="%s"'
|
||||
% job_id)
|
||||
|
||||
doc = self.client.enumerate(uris.DCIM_LifecycleJob,
|
||||
filter_query=filter_query)
|
||||
|
||||
drac_job = utils.find_xml(doc, 'DCIM_LifecycleJob',
|
||||
uris.DCIM_LifecycleJob)
|
||||
|
||||
if drac_job:
|
||||
return self._parse_drac_job(drac_job)
|
||||
|
||||
def create_config_job(self, resource_uri, cim_creation_class_name,
|
||||
cim_name, target,
|
||||
cim_system_creation_class_name='DCIM_ComputerSystem',
|
||||
cim_system_name='DCIM:ComputerSystem',
|
||||
reboot=False):
|
||||
"""Creates a config job
|
||||
|
||||
In CIM (Common Information Model), weak association is used to name an
|
||||
instance of one class in the context of an instance of another class.
|
||||
SystemName and SystemCreationClassName are the attributes of the
|
||||
scoping system, while Name and CreationClassName are the attributes of
|
||||
the instance of the class, on which the CreateTargetedConfigJob method
|
||||
is invoked.
|
||||
|
||||
:param: resource_uri: URI of resource to invoke
|
||||
:param: cim_creation_class_name: creation class name of the CIM object
|
||||
:param: cim_name: name of the CIM object
|
||||
:param: target: target device
|
||||
:param: cim_system_creation_class_name: creation class name of the
|
||||
scoping system
|
||||
:param: cim_system_name: name of the scoping system
|
||||
:param: reboot: indicates whether a RebootJob should be also be
|
||||
created or not
|
||||
:returns: id of the created job
|
||||
:raises: WSManRequestFailure on request failures
|
||||
:raises: WSManInvalidResponse when receiving invalid response
|
||||
:raises: DRACOperationFailed on error reported back by the DRAC
|
||||
interface
|
||||
:raises: DRACUnexpectedReturnValue on return value mismatch
|
||||
"""
|
||||
|
||||
selectors = {'SystemCreationClassName': cim_system_creation_class_name,
|
||||
'SystemName': cim_system_name,
|
||||
'CreationClassName': cim_creation_class_name,
|
||||
'Name': cim_name}
|
||||
|
||||
properties = {'Target': target,
|
||||
'ScheduledStartTime': 'TIME_NOW'}
|
||||
|
||||
if reboot:
|
||||
properties['RebootJobType'] = '3'
|
||||
|
||||
doc = self.client.invoke(resource_uri, 'CreateTargetedConfigJob',
|
||||
selectors, properties,
|
||||
expected_return_value=utils.RET_CREATED)
|
||||
|
||||
query = ('.//{%(namespace)s}%(item)s[@%(attribute_name)s='
|
||||
'"%(attribute_value)s"]' %
|
||||
{'namespace': wsman.NS_WSMAN, 'item': 'Selector',
|
||||
'attribute_name': 'Name',
|
||||
'attribute_value': 'InstanceID'})
|
||||
job_id = doc.find(query).text
|
||||
return job_id
|
||||
|
||||
def delete_pending_config(
|
||||
self, resource_uri, cim_creation_class_name, cim_name, target,
|
||||
cim_system_creation_class_name='DCIM_ComputerSystem',
|
||||
cim_system_name='DCIM:ComputerSystem'):
|
||||
"""Cancels pending configuration
|
||||
|
||||
Configuration can only be canceled until a config job hasn't been
|
||||
submitted.
|
||||
|
||||
In CIM (Common Information Model), weak association is used to name an
|
||||
instance of one class in the context of an instance of another class.
|
||||
SystemName and SystemCreationClassName are the attributes of the
|
||||
scoping system, while Name and CreationClassName are the attributes of
|
||||
the instance of the class, on which the CreateTargetedConfigJob method
|
||||
is invoked.
|
||||
|
||||
:param: resource_uri: URI of resource to invoke
|
||||
:param: cim_creation_class_name: creation class name of the CIM object
|
||||
:param: cim_name: name of the CIM object
|
||||
:param: target: target device
|
||||
:param: cim_system_creation_class_name: creation class name of the
|
||||
scoping system
|
||||
:param: cim_system_name: name of the scoping system
|
||||
:raises: WSManRequestFailure on request failures
|
||||
:raises: WSManInvalidResponse when receiving invalid response
|
||||
:raises: DRACOperationFailed on error reported back by the DRAC
|
||||
interface
|
||||
:raises: DRACUnexpectedReturnValue on return value mismatch
|
||||
"""
|
||||
|
||||
selectors = {'SystemCreationClassName': cim_system_creation_class_name,
|
||||
'SystemName': cim_system_name,
|
||||
'CreationClassName': cim_creation_class_name,
|
||||
'Name': cim_name}
|
||||
|
||||
properties = {'Target': target}
|
||||
|
||||
self.client.invoke(resource_uri, 'DeletePendingConfiguration',
|
||||
selectors, properties,
|
||||
expected_return_value=utils.RET_SUCCESS)
|
||||
|
||||
def _parse_drac_job(self, drac_job):
|
||||
return Job(id=self._get_job_attr(drac_job, 'InstanceID'),
|
||||
name=self._get_job_attr(drac_job, 'Name'),
|
||||
start_time=self._get_job_attr(drac_job, 'JobStartTime'),
|
||||
until_time=self._get_job_attr(drac_job, 'JobUntilTime'),
|
||||
message=self._get_job_attr(drac_job, 'Message'),
|
||||
state=self._get_job_attr(drac_job, 'JobStatus'),
|
||||
percent_complete=self._get_job_attr(drac_job,
|
||||
'PercentComplete'))
|
||||
|
||||
def _get_job_attr(self, drac_job, attr_name):
|
||||
return utils.get_wsman_resource_attr(drac_job, uris.DCIM_LifecycleJob,
|
||||
attr_name)
|
@ -0,0 +1,17 @@
|
||||
<s:Envelope xmlns:n1="http://schemas.dell.com/wbem/wscim/1/cim-schema/2/DCIM_BIOSService"
|
||||
xmlns:s="http://www.w3.org/2003/05/soap-envelope"
|
||||
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">
|
||||
<s:Header>
|
||||
<wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
|
||||
<wsa:Action>http://schemas.dell.com/wbem/wscim/1/cim-schema/2/DCIM_BIOSService/CreateTargetedConfigJobResponse</wsa:Action>
|
||||
<wsa:RelatesTo>uuid:80cf5e1b-b109-4ef5-87c8-5b03ce6ba117</wsa:RelatesTo>
|
||||
<wsa:MessageID>uuid:e57fa514-2189-1189-8ec1-a36fc6fe83b0</wsa:MessageID>
|
||||
</s:Header>
|
||||
<s:Body>
|
||||
<n1:CreateTargetedConfigJob_OUTPUT>
|
||||
<n1:Message>Configuration job already created, cannot create another config job on specified target until existing job is completed or is cancelled</n1:Message>
|
||||
<n1:MessageID>BIOS007</n1:MessageID>
|
||||
<n1:ReturnValue>2</n1:ReturnValue>
|
||||
</n1:CreateTargetedConfigJob_OUTPUT>
|
||||
</s:Body>
|
||||
</s:Envelope>
|
@ -0,0 +1,28 @@
|
||||
<s:Envelope xmlns:n1="http://schemas.dell.com/wbem/wscim/1/cim-schema/2/DCIM_BIOSService"
|
||||
xmlns:s="http://www.w3.org/2003/05/soap-envelope"
|
||||
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
|
||||
xmlns:wsman="http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd">
|
||||
<s:Header>
|
||||
<wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
|
||||
<wsa:Action>http://schemas.dell.com/wbem/wscim/1/cim-schema/2/DCIM_BIOSService/CreateTargetedConfigJobResponse</wsa:Action>
|
||||
<wsa:RelatesTo>uuid:fc2fdae5-6ac2-4338-9b2e-e69b813af829</wsa:RelatesTo>
|
||||
<wsa:MessageID>uuid:d7d89957-2189-1189-8ec0-a36fc6fe83b0</wsa:MessageID>
|
||||
</s:Header>
|
||||
<s:Body>
|
||||
<n1:CreateTargetedConfigJob_OUTPUT>
|
||||
<n1:Job>
|
||||
<wsa:EndpointReference>
|
||||
<wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>
|
||||
<wsa:ReferenceParameters>
|
||||
<wsman:ResourceURI>http://schemas.dell.com/wbem/wscim/1/cim-schema/2/DCIM_LifecycleJob</wsman:ResourceURI>
|
||||
<wsman:SelectorSet>
|
||||
<wsman:Selector Name="InstanceID">JID_442507917525</wsman:Selector>
|
||||
<wsman:Selector Name="__cimnamespace">root/dcim</wsman:Selector>
|
||||
</wsman:SelectorSet>
|
||||
</wsa:ReferenceParameters>
|
||||
</wsa:EndpointReference>
|
||||
</n1:Job>
|
||||
<n1:ReturnValue>4096</n1:ReturnValue>
|
||||
</n1:CreateTargetedConfigJob_OUTPUT>
|
||||
</s:Body>
|
||||
</s:Envelope>
|
@ -0,0 +1,17 @@
|
||||
<s:Envelope xmlns:n1="http://schemas.dell.com/wbem/wscim/1/cim-schema/2/DCIM_BIOSService"
|
||||
xmlns:s="http://www.w3.org/2003/05/soap-envelope"
|
||||
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">
|
||||
<s:Header>
|
||||
<wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
|
||||
<wsa:Action>http://schemas.dell.com/wbem/wscim/1/cim-schema/2/DCIM_BIOSService/DeletePendingConfigurationResponse</wsa:Action>
|
||||
<wsa:RelatesTo>uuid:6bd49922-f63b-44d9-abf7-b902f08ec932</wsa:RelatesTo>
|
||||
<wsa:MessageID>uuid:87a16ea4-2189-1189-8eb5-a36fc6fe83b0</wsa:MessageID>
|
||||
</s:Header>
|
||||
<s:Body>
|
||||
<n1:DeletePendingConfiguration_OUTPUT>
|
||||
<n1:Message>Configuration job already created, pending data cannot be deleted</n1:Message>
|
||||
<n1:MessageID>BIOS011</n1:MessageID>
|
||||
<n1:ReturnValue>2</n1:ReturnValue>
|
||||
</n1:DeletePendingConfiguration_OUTPUT>
|
||||
</s:Body>
|
||||
</s:Envelope>
|
@ -0,0 +1,15 @@
|
||||
<s:Envelope xmlns:n1="http://schemas.dell.com/wbem/wscim/1/cim-schema/2/DCIM_BIOSService" xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">
|
||||
<s:Header>
|
||||
<wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
|
||||
<wsa:Action>http://schemas.dell.com/wbem/wscim/1/cim-schema/2/DCIM_BIOSService/DeletePendingConfigurationResponse</wsa:Action>
|
||||
<wsa:RelatesTo>uuid:33b4948b-79e6-42ff-8670-19fbb25702c8</wsa:RelatesTo>
|
||||
<wsa:MessageID>uuid:d578f646-2189-1189-8ebe-a36fc6fe83b0</wsa:MessageID>
|
||||
</s:Header>
|
||||
<s:Body>
|
||||
<n1:DeletePendingConfiguration_OUTPUT>
|
||||
<n1:Message>The command was successful.</n1:Message>
|
||||
<n1:MessageID>BIOS001</n1:MessageID>
|
||||
<n1:ReturnValue>0</n1:ReturnValue>
|
||||
</n1:DeletePendingConfiguration_OUTPUT>
|
||||
</s:Body>
|
||||
</s:Envelope>
|
@ -0,0 +1,19 @@
|
||||
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"
|
||||
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
|
||||
xmlns:wsen="http://schemas.xmlsoap.org/ws/2004/09/enumeration"
|
||||
xmlns:wsman="http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd"
|
||||
xmlns:n1="http://schemas.dell.com/wbem/wscim/1/cim-schema/2/DCIM_LifecycleJob">
|
||||
<s:Header>
|
||||
<wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
|
||||
<wsa:Action>http://schemas.xmlsoap.org/ws/2004/09/enumeration/EnumerateResponse</wsa:Action>
|
||||
<wsa:RelatesTo>uuid:2453cc4f-104c-104c-8002-fd0aa2bdb228</wsa:RelatesTo>
|
||||
<wsa:MessageID>uuid:28c00f71-1051-1051-8003-fcc71555dbe0</wsa:MessageID>
|
||||
</s:Header>
|
||||
<s:Body>
|
||||
<wsen:EnumerateResponse>
|
||||
<wsman:Items/>
|
||||
<wsen:EnumerationContext/>
|
||||
<wsman:EndOfSequence/>
|
||||
</wsen:EnumerateResponse>
|
||||
</s:Body>
|
||||
</s:Envelope>
|
@ -0,0 +1,76 @@
|
||||
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsen="http://schemas.xmlsoap.org/ws/2004/09/enumeration" xmlns:wsman="http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd" xmlns:n1="http://schemas.dell.com/wbem/wscim/1/cim-schema/2/DCIM_LifecycleJob">
|
||||
<s:Header>
|
||||
<wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
|
||||
<wsa:Action>http://schemas.xmlsoap.org/ws/2004/09/enumeration/EnumerateResponse</wsa:Action>
|
||||
<wsa:RelatesTo>uuid:f3ee3b82-210b-110b-8002-fd0aa2bdb228</wsa:RelatesTo>
|
||||
<wsa:MessageID>uuid:f4327d65-210b-110b-836c-0581b4d9bed4</wsa:MessageID>
|
||||
</s:Header>
|
||||
<s:Body>
|
||||
<wsen:EnumerateResponse>
|
||||
<wsman:Items>
|
||||
<n1:DCIM_LifecycleJob>
|
||||
<n1:InstanceID>JID_CLEARALL</n1:InstanceID>
|
||||
<n1:JobStartTime>TIME_NA</n1:JobStartTime>
|
||||
<n1:JobStatus>Pending</n1:JobStatus>
|
||||
<n1:JobUntilTime>TIME_NA</n1:JobUntilTime>
|
||||
<n1:Message>NA</n1:Message>
|
||||
<n1:MessageID>NA</n1:MessageID>
|
||||
<n1:Name>CLEARALL</n1:Name>
|
||||
<n1:PercentComplete>0</n1:PercentComplete>
|
||||
</n1:DCIM_LifecycleJob>
|
||||
<n1:DCIM_LifecycleJob>
|
||||
<n1:InstanceID>JID_001436912645</n1:InstanceID>
|
||||
<n1:JobStartTime>00000101000000</n1:JobStartTime>
|
||||
<n1:JobStatus>Completed</n1:JobStatus>
|
||||
<n1:JobUntilTime>TIME_NA</n1:JobUntilTime>
|
||||
<n1:Message>Job completed successfully</n1:Message>
|
||||
<n1:MessageID>PR19</n1:MessageID>
|
||||
<n1:Name>ConfigBIOS:BIOS.Setup.1-1</n1:Name>
|
||||
<n1:PercentComplete>100</n1:PercentComplete>
|
||||
</n1:DCIM_LifecycleJob>
|
||||
<n1:DCIM_LifecycleJob>
|
||||
<n1:InstanceID>JID_001436960861</n1:InstanceID>
|
||||
<n1:JobStartTime>00000101000000</n1:JobStartTime>
|
||||
<n1:JobStatus>Completed</n1:JobStatus>
|
||||
<n1:JobUntilTime>TIME_NA</n1:JobUntilTime>
|
||||
<n1:Message>Job completed successfully</n1:Message>
|
||||
<n1:MessageID>PR19</n1:MessageID>
|
||||
<n1:Name>ConfigBIOS:BIOS.Setup.1-1</n1:Name>
|
||||
<n1:PercentComplete>100</n1:PercentComplete>
|
||||
</n1:DCIM_LifecycleJob>
|
||||
<n1:DCIM_LifecycleJob>
|
||||
<n1:InstanceID>JID_001436966148</n1:InstanceID>
|
||||
<n1:JobStartTime>00000101000000</n1:JobStartTime>
|
||||
<n1:JobStatus>Completed</n1:JobStatus>
|
||||
<n1:JobUntilTime>TIME_NA</n1:JobUntilTime>
|
||||
<n1:Message>Job completed successfully</n1:Message>
|
||||
<n1:MessageID>PR19</n1:MessageID>
|
||||
<n1:Name>ConfigBIOS:BIOS.Setup.1-1</n1:Name>
|
||||
<n1:PercentComplete>100</n1:PercentComplete>
|
||||
</n1:DCIM_LifecycleJob>
|
||||
<n1:DCIM_LifecycleJob>
|
||||
<n1:InstanceID>JID_001436980372</n1:InstanceID>
|
||||
<n1:JobStartTime>00000101000000</n1:JobStartTime>
|
||||
<n1:JobStatus>Completed</n1:JobStatus>
|
||||
<n1:JobUntilTime>TIME_NA</n1:JobUntilTime>
|
||||
<n1:Message>Job completed successfully</n1:Message>
|
||||
<n1:MessageID>PR19</n1:MessageID>
|
||||
<n1:Name>ConfigBIOS:BIOS.Setup.1-1</n1:Name>
|
||||
<n1:PercentComplete>100</n1:PercentComplete>
|
||||
</n1:DCIM_LifecycleJob>
|
||||
<n1:DCIM_LifecycleJob>
|
||||
<n1:InstanceID>JID_001436981582</n1:InstanceID>
|
||||
<n1:JobStartTime>00000101000000</n1:JobStartTime>
|
||||
<n1:JobStatus>Running</n1:JobStatus>
|
||||
<n1:JobUntilTime>TIME_NA</n1:JobUntilTime>
|
||||
<n1:Message>Job in progress</n1:Message>
|
||||
<n1:MessageID>PR20</n1:MessageID>
|
||||
<n1:Name>ConfigBIOS:BIOS.Setup.1-1</n1:Name>
|
||||
<n1:PercentComplete>34</n1:PercentComplete>
|
||||
</n1:DCIM_LifecycleJob>
|
||||
</wsman:Items>
|
||||
<wsen:EnumerationContext/>
|
||||
<wsman:EndOfSequence/>
|
||||
</wsen:EnumerateResponse>
|
||||
</s:Body>
|
||||
</s:Envelope>
|
Loading…
Reference in new issue