Skip to content

Commit

Permalink
Release 0.2.14
Browse files Browse the repository at this point in the history
Add following properties to enhance ease of use.

* Add `lun_list` property for `VNXStorageGroup` which returns a list of
 `VNXLun` that was added to the storage group.
* Add `hosts` property for `VNXStorageGroup` which returns a list of
  `VNXHost` that was added to the storage group.
* Add `lun_list` property for `VNXHost` which contains all connected LUNs
  of the host.
* Add `alu_hlu_map` that returns the mapping between array LUN ID and host
  LUN ID.
* Add `alu_ids` property for `VNXHost` which returns the IDs of the array
  LUNs that attached to the host.
* Add `hlu_ids` property for `VNXHost` which returns the LUN IDs on the
  host.
  • Loading branch information
Cedric Zhuang committed Jul 4, 2016
2 parents 62c07c5 + 77f8c95 commit 577769d
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ StorOps: The Python Library for VNX & Unity
.. image:: https://img.shields.io/pypi/v/storops.svg
:target: https://pypi.python.org/pypi/storops

VERSION: 0.2.13
VERSION: 0.2.14

A minimalist Python library to manage VNX/Unity systems.
This document lies in the source code and go with the release.
Expand Down
41 changes: 40 additions & 1 deletion storops/vnx/resource/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# under the License.
from __future__ import unicode_literals

from storops.lib.common import instance_cache, clear_instance_cache
from storops.vnx.resource import VNXCliResource, VNXCliResourceList
from storops.vnx.resource.sg import VNXStorageGroupList

Expand All @@ -29,21 +30,50 @@ def __init__(self, name=None, cli=None):

self.name = self._name
self.connections = None
self.storage_group = None
self._existed = False

def property_names(self):
return ['name', 'connections']
return ['name', 'connections', 'lun_list', 'alu_hlu_map']

def get_index(self):
return 'name'

@property
@instance_cache
def lun_list(self):
return self.storage_group.lun_list

@property
@instance_cache
def alu_hlu_map(self):
return self.storage_group.get_alu_hlu_map()

@property
def alu_ids(self):
if self.alu_hlu_map is not None:
ret = self.alu_hlu_map.keys()
else:
ret = tuple()
return ret

@property
def hlu_ids(self):
if self.alu_hlu_map is not None:
ret = self.alu_hlu_map.values()
else:
ret = tuple()
return ret

@clear_instance_cache
def update(self, data=None):
host_list = VNXHostList(cli=self._cli)
for host in host_list:
if host.name == self._name:
self._existed = True
self.name = host.name
self.connections = host.connections
self.storage_group = host.storage_group
return self

@property
Expand All @@ -60,6 +90,11 @@ def get(cls, cli, name=None):


class VNXHostList(VNXCliResourceList):
def __init__(self, cli=None, names=None):
super(VNXCliResourceList, self).__init__()
self._cli = cli
self._names = names

@classmethod
def get_resource_class(cls):
return VNXHost
Expand All @@ -72,11 +107,15 @@ def update(self, data=None):
if sg.hba_sp_pairs:
for pair in sg.hba_sp_pairs:
name = pair.host_name
if self._names is not None and name not in self._names:
continue

if name in host_names:
host = hosts[host_names.index(name)]
else:
host = VNXHost(name=name, cli=self._cli)
host.connections = []
host.storage_group = sg
hosts.append(host)
host_names.append(name)

Expand Down
4 changes: 2 additions & 2 deletions storops/vnx/resource/lun.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ def __init__(self, cli=None, lun_type=None, lun_ids=None, pool=None):
self._pool_name = pool

def _filter(self, lun):
if self._lun_ids:
if self._lun_ids is not None:
ret = VNXLun.get_id(lun) in self._lun_ids
elif self._pool_name:
elif self._pool_name is not None:
ret = lun.pool_name == self._pool_name
else:
ret = True
Expand Down
15 changes: 14 additions & 1 deletion storops/vnx/resource/sg.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from storops.vnx.enums import VNXPortType
import storops.vnx.resource.lun
import storops.vnx.resource.host
from storops.vnx.resource.port import VNXHbaPort
from storops.vnx.resource import VNXCliResource, VNXCliResourceList
from storops import exception as ex
Expand All @@ -46,7 +47,8 @@ def __init__(self, name=None, cli=None, shuffle_hlu=True):
self.shuffle_hlu = shuffle_hlu

def _get_raw_resource(self):
return self._cli.get_sg(name=self._name, poll=self.poll)
return self._cli.get_sg(name=self._name, poll=self.poll,
engineering=True)

@classmethod
def get(cls, cli, name=None):
Expand Down Expand Up @@ -88,6 +90,17 @@ def get_hlu(self, lun):
def is_valid(self):
return len(self.name) > 0 and len(self.uid) > 0

@property
def hosts(self):
host_names = [pair.host_name for pair in self.hba_sp_pairs]
clz = storops.vnx.resource.host.VNXHostList
return clz(cli=self._cli, names=host_names)

@property
def lun_list(self):
clz = storops.vnx.resource.lun.VNXLunList
return clz(cli=self._cli, lun_ids=self.get_alu_hlu_map().keys())

@property
def hba_port_list(self):
if not self._hba_port_list:
Expand Down
19 changes: 18 additions & 1 deletion test/vnx/resource/test_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from unittest import TestCase

from hamcrest import equal_to, assert_that, none, has_items
from hamcrest import equal_to, assert_that, none, has_items, only_contains

from storops.vnx.resource.host import VNXHostList, VNXHost
from test import patch_cli
Expand All @@ -35,12 +35,29 @@ def test_get_all(self):
'APM00152312055-spB', 'APM00152312055-spA', 'ubuntu-server11',
'ubuntu-server7', 'Celerra_CS0_21132', 'ubuntu14'))

@patch_cli()
def test_name_filter_of_get_all(self):
host_list = VNXHostList(t_cli(), names=('ubuntu-server11', 'ubuntu14'))
assert_that(len(host_list), equal_to(2))
assert_that(host_list.name, has_items('ubuntu-server11', 'ubuntu14'))

@patch_cli()
def test_host_property(self):
host = VNXHost.get(cli=t_cli(), name='ubuntu-server7')
assert_that(host.name, equal_to('ubuntu-server7'))
assert_that(host.existed, equal_to(True))
assert_that(len(host.connections), equal_to(15))
assert_that(host.storage_group.name, equal_to('ubuntu-server7'))
assert_that(len(host.lun_list), equal_to(0))

@patch_cli()
def test_host_with_lun(self):
host = VNXHost.get(cli=t_cli(), name='ubuntu14')
assert_that(host.lun_list.lun_id, only_contains(4, 15))
assert_that(host.alu_hlu_map[4], equal_to(14))
assert_that(host.alu_hlu_map[15], equal_to(154))
assert_that(host.alu_ids, only_contains(4, 15))
assert_that(host.hlu_ids, only_contains(14, 154))

@patch_cli()
def test_host_not_found(self):
Expand Down
20 changes: 19 additions & 1 deletion test/vnx/resource/test_sg.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from unittest import TestCase

from hamcrest import assert_that, equal_to, has_item, raises, instance_of, \
none, is_not, has_items
none, is_not, has_items, only_contains

from storops.vnx.resource.port import VNXStorageGroupHBAList
from test.vnx.cli_mock import patch_cli, t_cli
Expand Down Expand Up @@ -73,6 +73,24 @@ def test_properties(self):
assert_that(sg.has_hlu(11), equal_to(False))
assert_that(sg.existed, equal_to(True))

@patch_cli()
def test_property_hosts(self):
hosts = self.test_sg('~management').hosts
assert_that(len(hosts), equal_to(2))
assert_that(hosts.name,
has_items('APM00152312055-spB', 'APM00152312055-spA'))
assert_that(hosts[0].storage_group.name, equal_to('~management'))

@patch_cli()
def test_property_lun_list(self):
lun_list = self.test_sg('microsoft').lun_list
assert_that(lun_list.name, only_contains('lun4', 'lun456'))

@patch_cli()
def test_property_zero_lun_list(self):
lun_list = self.test_sg('os01').lun_list
assert_that(len(lun_list), equal_to(0))

@patch_cli()
def test_get_sg_os01(self):
sg = VNXStorageGroup(name='os01', cli=t_cli())
Expand Down
4 changes: 2 additions & 2 deletions test/vnx/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ def test_parse_no_header(self):
class VNXStorageGroupParserTest(TestCase):
def test_parse(self):
parser = get_vnx_parser('VNXStorageGroup')
output = MockCli.read_file('storagegroup_-list_-host_-iscsiAttributes_'
'-gname_microsoft.txt')
output = MockCli.read_file('storagegroup_-messner_-list_-host_'
'-iscsiAttributes_-gname_microsoft.txt')
sg = parser.parse(output)
assert_that(sg.shareable, equal_to(True))
assert_that(sg.name, equal_to('microsoft'))
Expand Down
6 changes: 3 additions & 3 deletions test/vnx/testdata/block_output/lun_-list_-all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10332,8 +10332,8 @@ Attached Snapshot: N/A
Allow Inband Snap Attach: N/A
Allocation Policy: Automatic

LOGICAL UNIT NUMBER 85
Name: lun_cl_32
LOGICAL UNIT NUMBER 456
Name: lun456
UID: 60:06:01:60:10:B0:34:00:6D:D5:00:7D:46:F0:E2:11
Current Owner: SP B
Default Owner: SP B
Expand Down Expand Up @@ -15349,7 +15349,7 @@ Allow Inband Snap Attach: N/A
Allocation Policy: Automatic

LOGICAL UNIT NUMBER 4
Name: lunc_5
Name: lun4
UID: 60:06:01:60:10:B0:34:00:DF:54:D7:91:15:EE:E2:11
Current Owner: SP B
Default Owner: SP B
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ HLU/ALU Pairs:
HLU Number ALU Number
---------- ----------
154 15
14 4
Shareable: YES

Storage Group Name: ubuntu-server7
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Storage Group Name: ~management
Storage Group UID: 60:06:01:60:00:00:00:00:00:00:00:00:00:00:00:02
HBA/SP Pairs:

HBA UID SP Name SPPort
------- ------- ------
50:06:01:60:B6:E0:15:26:50:06:01:69:36:E0:15:26 SP B 1
Host name: APM00152312055-spB
SPPort: B-1v0
Initiator IP: N/A
TPGT: 0
ISID: N/A

50:06:01:60:B6:E0:15:26:50:06:01:61:36:E0:15:26 SP A 1
Host name: APM00152312055-spA
SPPort: A-1v0
Initiator IP: N/A
TPGT: 0
ISID: N/A

Special: YES
Default: YES
Shareable: YES

0 comments on commit 577769d

Please sign in to comment.