Discussion:
[Libstoragemgmt-devel] [PATCH 2/2] nstor: Auto select correct port for v3.x & v4.x
Tony Asleson
2015-03-02 18:48:38 UTC
Permalink
Nexenta changed the default port for v4.x from 2000 to 8457. If the user
does not specify a port we try 2000 first. If that gets refused we will
try port 8457.

Signed-off-by: Tony Asleson <***@redhat.com>
---
plugin/nstor/nstor.py | 34 +++++++++++++++++++++++++---------
1 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/plugin/nstor/nstor.py b/plugin/nstor/nstor.py
index 358c2b1..939ef70 100644
--- a/plugin/nstor/nstor.py
+++ b/plugin/nstor/nstor.py
@@ -1,5 +1,5 @@
#
-# Copyright (C) 2013-2014 Nexenta Systems, Inc.
+# Copyright (C) 2013-2015 Nexenta Systems, Inc.
# All rights reserved.
#
# This library is free software; you can redistribute it and/or
@@ -20,6 +20,7 @@
# Gris Ge <***@redhat.com>

import urllib2
+import sys
import urlparse
try:
import simplejson as json
@@ -59,16 +60,16 @@ class NexentaStor(INfs, IStorageAreaNetwork):
self.password = None
self.timeout = None
self._system = None
+ self._port = '2000'
+ self._scheme = 'http'

def _ns_request(self, path, data):
response = None
- data = json.dumps(data)
- scheme = 'http'
- if self.uparse.scheme.lower() == 'nstor+ssl':
- scheme = 'https'
- port = self.uparse.port or '2000'
- url = '%s://%s:%s/%s' % (scheme, self.uparse.hostname, port, path)
- request = urllib2.Request(url, data)
+ parms = json.dumps(data)
+
+ url = '%s://%s:%s/%s' % \
+ (self._scheme, self.uparse.hostname, self._port, path)
+ request = urllib2.Request(url, parms)

username = self.uparse.username or 'admin'
base64string = base64.encodestring('%s:%s' %
@@ -78,7 +79,16 @@ class NexentaStor(INfs, IStorageAreaNetwork):
try:
response = urllib2.urlopen(request, timeout=self.timeout / 1000)
except Exception as e:
- common_urllib2_error_handler(e)
+ try:
+ common_urllib2_error_handler(e)
+ except LsmError as lsm_e:
+ exc_info = sys.exc_info()
+ if lsm_e.code == ErrorNumber.NETWORK_CONNREFUSED:
+ if not self.uparse.port and self._port == '2000':
+ self._port = '8457'
+ return self._ns_request(path, data)
+
+ raise exc_info[0], exc_info[1], exc_info[2]

resp_json = response.read()
resp = json.loads(resp_json)
@@ -114,6 +124,12 @@ class NexentaStor(INfs, IStorageAreaNetwork):
self.password = password or 'nexenta'
self.timeout = timeout

+ if self.uparse.port:
+ self._port = self.uparse.port
+
+ if self.uparse.scheme.lower() == 'nstor+ssl':
+ self._scheme = 'https'
+
@staticmethod
def _to_bytes(size):
if size.lower().endswith('k'):
--
1.7.1
Tony Asleson
2015-03-02 18:48:37 UTC
Permalink
Changes needed to make plugin work for 4.x array version.

Signed-off-by: Tony Asleson <***@redhat.com>
---
plugin/nstor/nstor.py | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/plugin/nstor/nstor.py b/plugin/nstor/nstor.py
index da25e48..358c2b1 100644
--- a/plugin/nstor/nstor.py
+++ b/plugin/nstor/nstor.py
@@ -103,8 +103,8 @@ class NexentaStor(INfs, IStorageAreaNetwork):
@property
def system(self):
if self._system is None:
- license_info = self._request("get_license_info", "appliance", [""])
- fqdn = self._request("get_fqdn", "appliance", [""])
+ license_info = self._request("get_license_info", "appliance", [])
+ fqdn = self._request("get_fqdn", "appliance", [])
self._system = System(license_info['machine_sig'], fqdn,
System.STATUS_OK, '')
return self._system
--
1.7.1
Gris Ge
2015-03-03 13:13:41 UTC
Permalink
Updates to allow plugin to work on 3.x and 4.x versions of
nexenta.
Gris, please review.
Hi Tony,

Looks good. The 'plugin_test' passed on version 4.0.2 and 3.1.5.

Trivial suggests:
1. Please use constant like _NSTOR_V_3_MGM_PORT instead of bare
number 2000.
2. "+# Copyright (C) 2013-2015 Nexenta Systems, Inc.' seems not
correct. We might add a new like indicate 2014-2015 Red Hat.

Thanks for the patches.
Best regards.
--
Gris Ge
Tony Asleson
2015-03-03 16:58:22 UTC
Permalink
Post by Gris Ge
Updates to allow plugin to work on 3.x and 4.x versions of
nexenta.
Gris, please review.
Hi Tony,
Looks good. The 'plugin_test' passed on version 4.0.2 and 3.1.5.
1. Please use constant like _NSTOR_V_3_MGM_PORT instead of bare
number 2000.
Will remove 'magic' numbers.
Post by Gris Ge
2. "+# Copyright (C) 2013-2015 Nexenta Systems, Inc.' seems not
correct. We might add a new like indicate 2014-2015 Red Hat.
I'm not sure what is the correct way to handle this. If I look at the
git history it could look something like:

Copyright (C) 2013 Nexenta, Inc.
Copyright (C) 2013-2015 Red Hat, Inc.
Copyright (C) 2014 Fujitsu

if we start adding copyrights for each person/company that made an edit.
I will look into this and see what is most appropriate before I post a
revised patch.

Regards,
Tony
Tony Asleson
2015-03-03 22:25:42 UTC
Permalink
Post by Tony Asleson
if we start adding copyrights for each person/company that made an edit.
I will look into this and see what is most appropriate before I post a
revised patch.
I backed out the year change and committed an updated patch fixing the
magic numbers. Once we decide if/what should be done WRT copyright
year/addendum we will go back and fix the entire code base.

Regards,
Tony

Loading...