/
system.py
201 lines (155 loc) · 7.61 KB
/
system.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# Copyright (c) 2015 EMC Corporation.
# All Rights Reserved.
#
# 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.
from __future__ import unicode_literals
import logging
from storops import exception as ex
from storops.lib.common import instance_cache
from storops.unity.client import UnityClient
from storops.unity.enums import UnityEnum
from storops.unity.resource import UnityResource, UnityResourceList, \
UnitySingletonResource
from storops.unity.resource.cifs_server import UnityCifsServerList
from storops.unity.resource.cifs_share import UnityCifsShareList
from storops.unity.resource.dns_server import UnityFileDnsServerList
from storops.unity.resource.filesystem import UnityFileSystemList
from storops.unity.resource.interface import UnityFileInterfaceList
from storops.unity.resource.host import UnityHost, UnityHostList, \
UnityHostIpPortList, UnityHostInitiatorList
from storops.unity.resource.lun import UnityLunList
from storops.unity.resource.nas_server import UnityNasServerList
from storops.unity.resource.nfs_server import UnityNfsServerList
from storops.unity.resource.nfs_share import UnityNfsShareList
from storops.unity.resource.pool import UnityPoolList
from storops.unity.resource.port import UnityIpPortList
from storops.unity.resource.snap import UnitySnapList
from storops.unity.resource.sp import UnityStorageProcessorList
from storops.unity.resource.port import UnityEthernetPortList, \
UnityIscsiPortalList, UnityFcPortList
from storops.unity.resource.vmware import UnityCapabilityProfileList
__author__ = 'Jay Xu'
LOG = logging.getLogger(__name__)
class UnitySystem(UnitySingletonResource):
def __init__(self, host=None, username=None, password=None,
port=443, cli=None):
super(UnitySystem, self).__init__(cli=cli)
if cli is None:
self._cli = UnityClient(host, username, password, port)
else:
self._cli = cli
def get_capability_profile(self, _id=None, name=None, **filters):
return self._get_unity_rsc(UnityCapabilityProfileList,
_id=_id, name=name, **filters)
def get_sp(self, _id=None, name=None, **filters):
return self._get_unity_rsc(UnityStorageProcessorList, _id=_id,
name=name, **filters)
def get_iscsi_portal(self, _id=None, **filters):
return self._get_unity_rsc(UnityIscsiPortalList, _id=_id, **filters)
def get_fc_port(self, _id=None, **filters):
return self._get_unity_rsc(UnityFcPortList, _id=_id, **filters)
def get_ethernet_port(self, _id=None, name=None, **filters):
return self._get_unity_rsc(UnityEthernetPortList, _id=_id,
name=name, **filters)
def create_host(self, name, host_type=None, desc=None, os=None):
host = UnityHostList.get(self._cli, name=name)
if host:
raise ex.UnityHostNameInUseError()
else:
host = UnityHost.create(self._cli, name, host_type=host_type,
desc=desc, os=os)
return host
def get_initiator(self, _id=None, **filters):
return self._get_unity_rsc(UnityHostInitiatorList, _id=_id, **filters)
def get_lun(self, _id=None, name=None, **filters):
return self._get_unity_rsc(UnityLunList, _id=_id, name=name, **filters)
def get_pool(self, _id=None, name=None, **filters):
return self._get_unity_rsc(UnityPoolList, _id=_id, name=name,
**filters)
def get_nas_server(self, _id=None, name=None, **filters):
return self._get_unity_rsc(UnityNasServerList, _id=_id, name=name,
**filters)
def get_cifs_server(self, _id=None, name=None, **filters):
return self._get_unity_rsc(UnityCifsServerList, _id=_id, name=name,
**filters)
def get_nfs_server(self, _id=None, **filters):
return self._get_unity_rsc(UnityNfsServerList, _id=_id, **filters)
def get_snap(self, _id=None, name=None, **filters):
return self._get_unity_rsc(UnitySnapList, _id=_id, name=name,
**filters)
def create_nas_server(self, name, sp=None, pool=None, is_repl_dst=None,
multi_proto=None):
if sp is None:
sp = self.get_sp().first_item
return sp.create_nas_server(name, pool,
is_repl_dst=is_repl_dst,
multi_proto=multi_proto)
def get_ip_port(self, _id=None, name=None, **filters):
return self._get_unity_rsc(UnityIpPortList, _id=_id, name=name,
**filters)
def get_file_interface(self, _id=None, name=None, **filters):
return self._get_unity_rsc(UnityFileInterfaceList, _id=_id, name=name,
**filters)
def get_dns_server(self, _id=None, **filters):
return self._get_unity_rsc(UnityFileDnsServerList, _id=_id, **filters)
def get_filesystem(self, _id=None, name=None, **filters):
return self._get_unity_rsc(UnityFileSystemList, _id=_id, name=name,
**filters)
def get_cifs_share(self, _id=None, name=None, **filters):
return self._get_unity_rsc(UnityCifsShareList, _id=_id, name=name,
**filters)
def get_nfs_share(self, _id=None, name=None, **filters):
return self._get_unity_rsc(UnityNfsShareList, _id=_id, name=name,
**filters)
def get_host(self, _id=None, name=None, address=None, **filters):
ret = UnityHostList.get(self._cli, name='not found')
if address:
host_ip_ports = UnityHostIpPortList.get(self._cli, address=address)
if host_ip_ports:
ret = host_ip_ports[0].host
else:
ret = self._get_unity_rsc(UnityHostList, _id=_id, name=name,
**filters)
return ret
def get_doc(self, resource):
if isinstance(resource, (UnityResource, UnityEnum)):
clz = resource.__class__
else:
clz = resource
return self._cli.get_doc(clz)
@property
@instance_cache
def info(self):
return UnityBasicSystemInfo.get(cli=self._cli)
class UnitySystemList(UnityResourceList):
@classmethod
def get_resource_class(cls):
return UnitySystem
class UnityDpe(UnityResource):
pass
class UnityDpeList(UnityResourceList):
@classmethod
def get_resource_class(cls):
return UnityDpe
class UnityVirusChecker(UnityResource):
pass
class UnityVirusCheckerList(UnityResourceList):
@classmethod
def get_resource_class(cls):
return UnityVirusChecker
class UnityBasicSystemInfo(UnitySingletonResource):
pass
class UnityBasicSystemInfoList(UnityResourceList):
@classmethod
def get_resource_class(cls):
return UnityBasicSystemInfo