11#!/usr/bin/python
2- # -*- coding: utf-8 -*-
32
43import json
54import os
1312 from urllib2 import HTTPError
1413
1514from cloudshell .rest .api import PackagingRestApiClient
16- from cloudshell .rest .exceptions import FeatureUnavailable , ShellNotFoundException
15+
16+ try :
17+ from cloudshell .rest .exceptions import FeatureUnavailable , ShellNotFound
18+ except ImportError :
19+ from cloudshell .rest .exceptions import (
20+ FeatureUnavailable ,
21+ ShellNotFoundException as ShellNotFound ,
22+ )
1723
1824from shellfoundry .exceptions import FatalError
1925from shellfoundry .utilities .config_reader import CloudShellConfigReader , Configuration
@@ -77,7 +83,7 @@ def install(self, path):
7783 except FeatureUnavailable :
7884 # try to update shell first
7985 pass
80- except ShellNotFoundException :
86+ except ShellNotFound :
8187 # try to install shell
8288 pass
8389 except click .Abort :
@@ -98,7 +104,7 @@ def install(self, path):
98104 ) as pbar :
99105 try :
100106 client .update_shell (package_full_path )
101- except ShellNotFoundException :
107+ except ShellNotFound :
102108 self ._increase_pbar (pbar , DEFAULT_TIME_WAIT )
103109 self ._add_new_shell (client , package_full_path )
104110 except Exception as e :
@@ -145,7 +151,7 @@ def delete(self, shell_name):
145151 raise click .ClickException (
146152 "Delete shell command unavailable (probably due to CloudShell version below 9.2)" # noqa: E501
147153 )
148- except ShellNotFoundException :
154+ except ShellNotFound :
149155 self ._increase_pbar (pbar , DEFAULT_TIME_WAIT )
150156 raise click .ClickException (
151157 "Shell '{shell_name}' doesn't exist on CloudShell" .format (
@@ -166,16 +172,25 @@ def _open_connection_to_quali_server(self, cloudshell_config, pbar, retry):
166172 "Connection to CloudShell Server failed. "
167173 "Please make sure it is up and running properly."
168174 )
169-
170175 try :
171- client = PackagingRestApiClient (
172- ip = cloudshell_config .host ,
173- username = cloudshell_config .username ,
174- port = cloudshell_config .port ,
175- domain = cloudshell_config .domain ,
176- password = cloudshell_config .password ,
177- )
178- return client
176+ try :
177+ client = PackagingRestApiClient .login (
178+ host = cloudshell_config .host ,
179+ port = cloudshell_config .port ,
180+ username = cloudshell_config .username ,
181+ password = cloudshell_config .password ,
182+ domain = cloudshell_config .domain ,
183+ )
184+ return client
185+ except AttributeError :
186+ client = PackagingRestApiClient (
187+ ip = cloudshell_config .host ,
188+ port = cloudshell_config .port ,
189+ username = cloudshell_config .username ,
190+ password = cloudshell_config .password ,
191+ domain = cloudshell_config .domain ,
192+ )
193+ return client
179194 except HTTPError as e :
180195 if e .code == 401 :
181196 raise FatalError (
0 commit comments