Tony Asleson
2015-03-02 18:48:38 UTC
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'):
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
1.7.1