Skip to content

Commit

Permalink
rest api change timeout and fix trap parse (#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangyutan authored Dec 1, 2020
1 parent a8ca53b commit 7be276d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion delfin/drivers/hitachi/vsp/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
SOCKET_TIMEOUT = 52
SOCKET_TIMEOUT = 30
ERROR_SESSION_INVALID_CODE = 403
ERROR_SESSION_IS_BEING_USED_CODE = 409
BLOCK_SIZE = 512
Expand Down
18 changes: 8 additions & 10 deletions delfin/drivers/hitachi/vsp/rest_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ def __init__(self, **kwargs):
self.device_model = None
self.serial_number = None

def call(self, url, data=None, method=None):
def call(self, url, data=None, method=None,
calltimeout=consts.SOCKET_TIMEOUT):
try:
res = self.do_call(url, data, method,
calltimeout=consts.SOCKET_TIMEOUT)
res = self.do_call(url, data, method, calltimeout)
if (res.status_code == consts.ERROR_SESSION_INVALID_CODE
or res.status_code ==
consts.ERROR_SESSION_IS_BEING_USED_CODE):
Expand All @@ -57,8 +57,7 @@ def call(self, url, data=None, method=None):
access_session = self.login()
if access_session is not None:
res = self. \
do_call(url, data, method,
calltimeout=consts.SOCKET_TIMEOUT)
do_call(url, data, method, calltimeout)
else:
LOG.error('Login error,get access_session failed')
elif res.status_code == 503:
Expand All @@ -71,9 +70,9 @@ def call(self, url, data=None, method=None):
LOG.error(err_msg)
raise e

def get_rest_info(self, url, data=None):
def get_rest_info(self, url, timeout=consts.SOCKET_TIMEOUT, data=None):
result_json = None
res = self.call(url, data, 'GET')
res = self.call(url, data, 'GET', timeout)
if res.status_code == 200:
result_json = res.json()
return result_json
Expand All @@ -96,8 +95,7 @@ def login(self):
self.rest_username,
cryptor.decode(self.rest_password))
res = self. \
do_call(url, data, 'POST',
calltimeout=consts.SOCKET_TIMEOUT)
do_call(url, data, 'POST', 10)
if res.status_code == 200:
result = res.json()
self.session_id = result.get('sessionId')
Expand Down Expand Up @@ -199,6 +197,6 @@ def get_all_volumes(self):
return result_json

def get_system_info(self):
result_json = self.get_rest_info(RestHandler.COMM_URL)
result_json = self.get_rest_info(RestHandler.COMM_URL, timeout=10)

return result_json
4 changes: 2 additions & 2 deletions delfin/drivers/hitachi/vsp/vsp_stor.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class HitachiVspDriver(driver.StorageDriver):
TRAP_TIME_OID = '1.3.6.1.4.1.116.5.11.4.2.6'
TRAP_DATE_OID = '1.3.6.1.4.1.116.5.11.4.2.5'
TRAP_NICKNAME_OID = '1.3.6.1.4.1.116.5.11.4.2.2'
LOCATION_OID = '1.3.6.1.4.1.116.5.11.4.2.4'
OID_SEVERITY = '1.3.6.1.6.3.1.1.4.1.0'
SECONDS_TO_MS = 1000

Expand Down Expand Up @@ -294,7 +293,8 @@ def parse_alert(context, alert):
HitachiVspDriver.SECONDS_TO_MS)
alert_model['description'] = alert.get(HitachiVspDriver.DESC_OID)
alert_model['resource_type'] = constants.DEFAULT_RESOURCE_TYPE
alert_model['location'] = alert.get(HitachiVspDriver.LOCATION_OID)
alert_model['location'] = alert.get(HitachiVspDriver.
TRAP_NICKNAME_OID)

return alert_model
except Exception as e:
Expand Down

0 comments on commit 7be276d

Please sign in to comment.