-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdellemc_idrac.py
113 lines (91 loc) · 3.58 KB
/
dellemc_idrac.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#! /usr/bin/python
# _*_ coding: utf-8 _*_
#
# Copyright (c) 2017 Dell Inc.
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
try:
from omsdk.sdkinfra import sdkinfra
from omsdk.sdkcreds import UserCredentials
from omsdk.sdkfile import FileOnShare
HAS_OMSDK = True
except ImportError:
HAS_OMSDK = False
class iDRACConnection():
def __init__(self, module):
if not HAS_OMSDK:
results = {}
results['msg']="Dell EMC OpenManage Python SDK is required for this module"
module.fail_json(**results)
self.module = module
self.handle = None
def connect(self):
results = {}
ansible_module_params = self.module.params
idrac = ansible_module_params.get('idrac')
idrac_ip = ansible_module_params.get('idrac_ip')
idrac_user = ansible_module_params.get('idrac_user')
idrac_pwd = ansible_module_params.get('idrac_pwd')
idrac_port = ansible_module_params.get('idrac_port')
if idrac:
return idrac
try:
sd = sdkinfra()
sd.importPath()
except Exception as e:
results['msg'] = "Could not initialize drivers"
results['exception'] = str(e)
self.module.fail_json(**results)
# Connect to iDRAC
if idrac_ip == '' or idrac_user == '' or idrac_pwd == '':
results['msg'] = "hostname, username and password required"
self.module.fail_json(**results)
else:
creds = UserCredentials(idrac_user, idrac_pwd)
idrac = sd.get_driver(sd.driver_enum.iDRAC, idrac_ip, creds)
if idrac is None:
results['msg'] = "Could not find device driver for iDRAC with IP Address: " + idrac_ip
self.module.fail_json(**results)
self.handle = idrac
return idrac
def disconnect(self):
idrac = self.module.params.get('idrac')
if idrac:
# pre-existing handle from a task
return False
if self.handle:
self.handle.disconnect()
return True
return True
def setup_nw_share_mount(self):
results = {}
try:
share_name = self.module.params.get('share_name')
share_user = self.module.params.get('share_user')
share_pwd = self.module.params.get('share_pwd')
share_mnt = self.module.params.get('share_mnt')
if share_name and share_user and share_pwd and share_mnt:
nw_share = FileOnShare(remote=share_name,
mount_point=share_mnt,
isFolder=True,
creds=UserCredentials(share_user, share_pwd))
if nw_share:
return self.handle.config_mgr.set_liason_share(nw_share)
except Exception as e:
results['msg'] = "Error: %s" % str(e)
self.module.fail_json(**results)
return False