Lint fixes and some changes by @rallytime

This commit is contained in:
C. R. Oldham 2015-10-15 13:11:05 -06:00
parent cca310eee0
commit 0957beea46
2 changed files with 83 additions and 41 deletions

View file

@ -60,7 +60,8 @@ def __execute_cmd(command, host=None,
# or all switches in a chassis. Allow
# user to say 'module=ALL_SERVER' or 'module=ALL_SWITCH'
if module.startswith('ALL_'):
modswitch = '-a ' + module[module.index('_') + 1:len(module)].lower()
modswitch = '-a '\
+ module[module.index('_') + 1:len(module)].lower()
else:
modswitch = '-m {0}'.format(module)
else:
@ -205,7 +206,8 @@ def network_info(host=None,
salt dell dracr.network_info
'''
inv = inventory(host=host, admin_username=admin_username, admin_password=admin_password)
inv = inventory(host=host, admin_username=admin_username,
admin_password=admin_password)
if module not in inv.get('switch'):
cmd = {}
cmd['retcode'] = -1
@ -253,7 +255,7 @@ def nameservers(ns,
host=host,
admin_username=admin_username,
admin_password=admin_password,
module=module)
module=module):
return False
return True
@ -320,7 +322,8 @@ def email_alerts(action,
def list_users(host=None,
admin_username=None,
admin_password=None):
admin_password=None,
module=None):
'''
List all DRAC users
@ -693,8 +696,8 @@ def server_poweroff(host=None,
The password used to access the chassis.
module
The element to power off on the chassis such as a blade. If not provided,
the chassis will be powered off.
The element to power off on the chassis such as a blade.
If not provided, the chassis will be powered off.
CLI Example:
@ -787,16 +790,16 @@ def server_powerstatus(host=None,
salt dell drac.server_powerstatus
'''
ret = __execute_ret('serveraction powerstatus',
host=host, admin_username=admin_username,
admin_password=admin_password,
module=module)
ret = __execute_ret('serveraction powerstatus',
host=host, admin_username=admin_username,
admin_password=admin_password,
module=module)
result = { 'retcode': 0 }
result = {'retcode': 0}
if ret['stdout'] == 'ON':
result['status'] = True
result['comment'] = 'Power is on'
if ret['stdout'] == 'OFF':
if ret['stdout'] == 'OFF':
result['status'] = False
result['comment'] = 'Power is on'
if ret['stdout'].startswith('ERROR'):
@ -805,6 +808,7 @@ def server_powerstatus(host=None,
return result
def server_pxe(host=None,
admin_username=None,
admin_password=None):
@ -851,7 +855,8 @@ def list_slotnames(host=None,
.. code-block:: bash
salt-call --local dracr.list_slotnames host=111.222.333.444 admin_username=root admin_password=secret
salt-call --local dracr.list_slotnames host=111.222.333.444
admin_username=root admin_password=secret
'''
slotraw = __execute_ret('getslotname',
@ -903,10 +908,12 @@ def get_slotname(slot, host=None, admin_username=None, admin_password=None):
.. code-block:: bash
salt-call --local dracr.get_slotname 0 host=111.222.333.444 admin_username=root admin_password=secret
salt-call --local dracr.get_slotname 0 host=111.222.333.444
admin_username=root admin_password=secret
'''
slots = list_slotnames(host=host, admin_username=admin_username, admin_password=admin_password)
slots = list_slotnames(host=host, admin_username=admin_username,
admin_password=admin_password)
return slots[slot]
@ -934,7 +941,8 @@ def set_slotname(slot, name, host=None,
.. code-block:: bash
salt '*' dracr.set_slotname 2 my-slotname host=111.222.333.444 admin_username=root admin_password=secret
salt '*' dracr.set_slotname 2 my-slotname host=111.222.333.444
admin_username=root admin_password=secret
'''
return __execute_cmd('setslotname -i {0} {1}'.format(
@ -966,7 +974,8 @@ def set_chassis_name(name,
.. code-block:: bash
salt '*' dracr.set_chassis_name my-chassis host=111.222.333.444 admin_username=root admin_password=secret
salt '*' dracr.set_chassis_name my-chassis host=111.222.333.444
admin_username=root admin_password=secret
'''
return __execute_cmd('setsysinfo -c chassisname {0}'.format(name),
@ -991,12 +1000,14 @@ def get_chassis_name(host=None, admin_username=None, admin_password=None):
.. code-block:: bash
salt '*' dracr.get_chassis_name host=111.222.333.444 admin_username=root admin_password=secret
salt '*' dracr.get_chassis_name host=111.222.333.444
admin_username=root admin_password=secret
'''
return system_info(host=host,
admin_username=admin_username,
admin_password=admin_password)['Chassis Information']['Chassis Name']
admin_password=admin_password)['Chassis Information']\
['Chassis Name']
def inventory(host=None, admin_username=None, admin_password=None):
@ -1103,7 +1114,8 @@ def set_chassis_location(location,
.. code-block:: bash
salt '*' dracr.set_chassis_location location-name host=111.222.333.444 admin_username=root admin_password=secret
salt '*' dracr.set_chassis_location location-name host=111.222.333.444
admin_username=root admin_password=secret
'''
return __execute_cmd('setsysinfo -c chassislocation {0}'.format(location),
@ -1130,17 +1142,20 @@ def get_chassis_location(host=None,
.. code-block:: bash
salt '*' dracr.set_chassis_location host=111.222.333.444 admin_username=root admin_password=secret
salt '*' dracr.set_chassis_location host=111.222.333.444
admin_username=root admin_password=secret
'''
return system_info(host=host,
admin_username=admin_username,
admin_password=admin_password)['Chassis Information']['Chassis Location']
admin_password=admin_password)['Chassis Information']\
['Chassis Location']
def set_general(cfg_sec, cfg_var, val, host=None,
admin_username=None, admin_password=None):
return __execute_cmd('config -g {0} -o {1} {2}'.format(cfg_sec, cfg_var, val),
return __execute_cmd('config -g {0} -o {1} {2}'.format(cfg_sec,
cfg_var, val),
host=host,
admin_username=admin_username,
admin_password=admin_password)

View file

@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
'''
Manage chassis via Salt Proxies.
@ -17,7 +17,7 @@ Example managing a Dell chassis:
- slot_names:
- 1: my-slot-name
- 2: my-other-slot-name
- blade_power:
- blade_power_states:
- server-1: on
- server-2: off
- server-3: powercycle
@ -28,8 +28,6 @@ Example managing a Dell chassis:
from __future__ import absolute_import
import logging
# Import Salt Libs
log = logging.getLogger(__name__)
@ -37,7 +35,8 @@ def __virtual__():
return 'chassis.cmd' in __salt__
def dell(name, location=None, mode=None, idrac_launch=None, slot_names=None):
def dell(name, location=None, mode=None, idrac_launch=None, slot_names=None,
blade_power_states=None):
'''
Manage a Dell Chassis.
@ -61,7 +60,16 @@ def dell(name, location=None, mode=None, idrac_launch=None, slot_names=None):
- 1: Enabled (launch iDRAC using DNS name)
slot_names
The names of the slots, provided as a list.
The names of the slots, provided as a listidentified by
their slot numbers.
blade_power_states
The power states of a blade server, provided as a list and
identified by their server numbers. Viable options are:
- on: Ensure the blade server is powered on.
- off: Ensure the blade server is powered off.
- powercycle: Power cycle the blade server.
Example:
@ -76,6 +84,10 @@ def dell(name, location=None, mode=None, idrac_launch=None, slot_names=None):
- slot_names:
- 1: my-slot-name
- 2: my-other-slot-name
- blade_power_states:
- server-1: on
- server-2: off
- server-3: powercycle
'''
ret = {'name': name,
'result': True,
@ -115,19 +127,36 @@ def dell(name, location=None, mode=None, idrac_launch=None, slot_names=None):
if slot_names:
current_slot_names = __salt__[chassis_cmd]('list_slotnames')
for item in slot_names:
slot_name = slot_names.get(item)
current_slot_name = current_slot_names.get(item).get('slotname')
if current_slot_name != slot_name:
old = {item: current_slot_name}
new = {item: slot_name}
for key, val in slot_names:
current_slot_name = current_slot_names.get(key).get('slotname')
if current_slot_name != val:
old = {key: current_slot_name}
new = {key: val}
if ret['changes'].get('Slot Names') is None:
ret['changes'].update({'Slot Names':
{'Old': {item: current_slot_name},
'New': {item: slot_name}}})
{'Old': {},
'New': {}}})
ret['changes']['Slot Names']['Old'].update(old)
ret['changes']['Slot Names']['New'].update(new)
# TODO: Refactor this and make DRY - can probable farm this out to a new funciton
if blade_power_states:
# TODO: Get the power state list working
current_power_states = 'get a list of current power states'
for key, val in blade_power_states:
# TODO: Get the correct state infos
current_power_state = current_power_states.get(key).get('state')
# TODO: Don't just compare values, check if True should be "on" or "off" etc
if current_power_state != val:
old = {key: current_power_state}
new = {key: val}
if ret['changes'].get('Blade Power States') is None:
ret['changes'].update({'Blade Power States':
{'Old': {},
'New': {}}})
ret['changes']['Blade Power States']['Old'].update(old)
ret['changes']['Blade Power States']['New'].update(new)
if ret['changes'] == {}:
ret['comment'] = 'Dell chassis is already in the desired state.'
return ret
@ -211,7 +240,6 @@ def dell_switch(name, ip=None, netmask=None, gateway=None, dhcp=None,
'changes': {},
'comment': ''}
current_nic = __salt__['chassis.cmd']('network_info', module=name)
if current_nic.get('retcode', 0) != 0:
ret['result'] = False
@ -227,8 +255,8 @@ def dell_switch(name, ip=None, netmask=None, gateway=None, dhcp=None,
ip = current_nic['Network']['Gateway']
if current_nic['Network']['DHCP Enabled'] == '0' and dhcp:
ret['changes'].update({'DHCP': { 'Old': { 'DHCP Enabled': current_nic['Network']['DHCP Enabled'] },
'New': { 'DHCP Enabled': dhcp }}})
ret['changes'].update({'DHCP': {'Old': {'DHCP Enabled': current_nic['Network']['DHCP Enabled']},
'New': {'DHCP Enabled': dhcp}}})
if ((ip or netmask or gateway) and not dhcp and (ip != current_nic['Network']['IP Address'] or
netmask != current_nic['Network']['Subnet Mask'] or
@ -275,4 +303,3 @@ def dell_switch(name, ip=None, netmask=None, gateway=None, dhcp=None,
ret['comment'] = 'Dell chassis switch {0} was updated.'.format(name)
return ret