Skip to content

Commit e38a7b7

Browse files
alexqualiAlexey Bogoslovskyi
authored andcommitted
Added support for old and new cloudshell-rest-api. Added possibility to pack shell without src folder
1 parent 69ec48b commit e38a7b7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+222
-355
lines changed

dev_requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pre-commit
22
tox
3+
tox-factor
34
-r test_requirements.txt
45
-r requirements.txt

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ cookiecutter~=1.7.2
33
click~=7.1.2
44
pyyaml
55
terminaltables
6-
cloudshell-rest-api>=8.2.3.1,<9
6+
cloudshell-rest-api~=9.0.0
77
colorama
88
giturlparse.py
99
ruamel.yaml

setup.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
32

43
from setuptools import find_packages, setup
54

@@ -27,8 +26,8 @@ def get_file_content(file_name):
2726
+ "\n\n"
2827
+ get_file_content("HISTORY.rst"),
2928
long_description_content_type="text/markdown",
30-
author="QualiSystems",
31-
author_email="info@qualisystems.com",
29+
author="Quali",
30+
author_email="info@quali.com",
3231
url="https://github.com/QualiSystems/shellfoundry",
3332
packages=find_packages(exclude=["*.tests", "*.tests.*", "tests.*", "tests"]),
3433
package_data={"shellfoundry": ["data/*.yml", "data/*.json"]},

shellfoundry/models/install_config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/python
2-
# -*- coding: utf-8 -*-
32

43
from shellfoundry.utilities.modifiers.configuration.password_modification import (
54
PasswordModification,

shellfoundry/utilities/archive_creator.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,21 @@ def make_archive(output_filename, archive_format, source_dir):
1515
:param source_dir: Directory to scan for archiving
1616
:return:
1717
"""
18-
if os.path.splitext(output_filename)[1] == "":
19-
output_filename += ".zip"
20-
output_dir = os.path.dirname(output_filename)
21-
if output_dir and not os.path.exists(output_dir):
22-
os.makedirs(output_dir)
23-
relroot = source_dir
24-
with zipfile.ZipFile(output_filename, "w", zipfile.ZIP_DEFLATED) as zip_f:
25-
for root, dirs, files in os.walk(source_dir):
26-
# add directory (needed for empty dirs)
27-
zip_f.write(root, os.path.relpath(root, relroot))
28-
for file in files:
29-
filename = os.path.join(root, file)
30-
if os.path.isfile(filename): # regular files only
31-
arcname = os.path.join(os.path.relpath(root, relroot), file)
32-
zip_f.write(filename, arcname)
18+
if os.path.exists(source_dir):
19+
if os.path.splitext(output_filename)[1] == "":
20+
output_filename += ".zip"
21+
output_dir = os.path.dirname(output_filename)
22+
if output_dir and not os.path.exists(output_dir):
23+
os.makedirs(output_dir)
24+
relroot = source_dir
25+
with zipfile.ZipFile(output_filename, "w", zipfile.ZIP_DEFLATED) as zip_f:
26+
for root, dirs, files in os.walk(source_dir):
27+
# add directory (needed for empty dirs)
28+
zip_f.write(root, os.path.relpath(root, relroot))
29+
for file in files:
30+
filename = os.path.join(root, file)
31+
if os.path.isfile(filename): # regular files only
32+
arcname = os.path.join(os.path.relpath(root, relroot), file)
33+
zip_f.write(filename, arcname)
3334

34-
return output_filename
35+
return output_filename

shellfoundry/utilities/cloudshell_api/client_wrapper.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/python
2-
# -*- coding: utf-8 -*-
32

43
from cloudshell.rest.api import PackagingRestApiClient
54

@@ -44,14 +43,24 @@ def create_client(self, **kwargs):
4443

4544
def _create_client(self):
4645
try:
47-
client = PackagingRestApiClient(
48-
ip=self._cs_config.host,
49-
username=self._cs_config.username,
50-
port=self._cs_config.port,
51-
domain=self._cs_config.domain,
52-
password=self._cs_config.password,
53-
)
54-
return client
46+
try:
47+
client = PackagingRestApiClient.login(
48+
host=self._cs_config.host,
49+
port=self._cs_config.port,
50+
username=self._cs_config.username,
51+
password=self._cs_config.password,
52+
domain=self._cs_config.domain,
53+
)
54+
return client
55+
except AttributeError:
56+
client = PackagingRestApiClient(
57+
ip=self._cs_config.host,
58+
port=self._cs_config.port,
59+
username=self._cs_config.username,
60+
password=self._cs_config.password,
61+
domain=self._cs_config.domain,
62+
)
63+
return client
5564
except (HTTPError, Exception) as e:
5665
if hasattr(e, "code") and e.code == 401:
5766
if hasattr(e, "msg") and e.msg:

shellfoundry/utilities/driver_generator.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/python
2-
# -*- coding: utf-8 -*-
32
try:
43
from urllib.error import URLError
54
except ImportError:
@@ -65,7 +64,7 @@ def _generate_driver_data_model(
6564
:param shell_name:
6665
:return:
6766
"""
68-
url = "http://{0}:{1}/API/ShellDrivers/Generate".format(
67+
url = "http://{}:{}/API/ShellDrivers/Generate".format(
6968
cloudshell_config.host, cloudshell_config.port
7069
)
7170
token = client.token
@@ -76,7 +75,7 @@ def _generate_driver_data_model(
7675
)
7776

7877
if response.status_code != 200:
79-
error_message = "Code generation failed with code {0} and error {1}".format(
78+
error_message = "Code generation failed with code {} and error {}".format(
8079
response.status_code, response.text
8180
)
8281
click.echo(message=error_message, err=True)
@@ -85,25 +84,35 @@ def _generate_driver_data_model(
8584
click.echo("Extracting data model ...")
8685
with TempDirContext(remove_dir_on_error=False, prefix=shell_name) as temp_dir:
8786
generated_zip = path.join(temp_dir, shell_filename)
88-
click.echo("Writing temporary file {0}".format(generated_zip))
87+
click.echo("Writing temporary file {}".format(generated_zip))
8988
with open(generated_zip, "wb") as driver_file:
9089
driver_file.write(response.content)
9190

92-
click.echo("Extracting generated code at {0}".format(destination_path))
91+
click.echo("Extracting generated code at {}".format(destination_path))
9392
with zipfile.ZipFile(generated_zip) as zf:
9493
zf.extractall(destination_path)
9594

9695
@staticmethod
9796
def _connect_to_cloudshell(cloudshell_config):
9897
try:
99-
client = PackagingRestApiClient(
100-
ip=cloudshell_config.host,
101-
username=cloudshell_config.username,
102-
port=cloudshell_config.port,
103-
domain=cloudshell_config.domain,
104-
password=cloudshell_config.password,
105-
)
106-
return client
98+
try:
99+
client = PackagingRestApiClient.login(
100+
host=cloudshell_config.host,
101+
port=cloudshell_config.port,
102+
username=cloudshell_config.username,
103+
password=cloudshell_config.password,
104+
domain=cloudshell_config.domain,
105+
)
106+
return client
107+
except AttributeError:
108+
client = PackagingRestApiClient(
109+
ip=cloudshell_config.host,
110+
port=cloudshell_config.port,
111+
username=cloudshell_config.username,
112+
password=cloudshell_config.password,
113+
domain=cloudshell_config.domain,
114+
)
115+
return client
107116
except URLError:
108117
click.echo(
109118
"Login to CloudShell failed. Please verify the credentials in cloudshell_config.yml", # noqa: E501

shellfoundry/utilities/installer.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,28 @@ def install(self, package_name, config):
1717
:type config shellfoundry.models.install_config.InstallConfig
1818
:return:
1919
"""
20-
host = config.host
21-
port = config.port
22-
username = config.username
23-
password = config.password
24-
domain = config.domain
25-
2620
package_full_path = os.path.join(os.getcwd(), "dist", package_name + ".zip")
2721
click.echo(
28-
"Installing package {0} into CloudShell at http://{1}:{2}".format(
29-
package_full_path, host, port
22+
"Installing package {} into CloudShell at http://{}:{}".format(
23+
package_full_path, config.host, config.port
3024
)
3125
)
32-
server = PackagingRestApiClient(host, port, username, password, domain)
33-
server.import_package(package_full_path)
26+
27+
try:
28+
client = PackagingRestApiClient.login(
29+
host=config.host,
30+
port=config.port,
31+
username=config.username,
32+
password=config.password,
33+
domain=config.domain,
34+
)
35+
except AttributeError:
36+
client = PackagingRestApiClient(
37+
ip=config.host,
38+
port=config.port,
39+
username=config.username,
40+
password=config.password,
41+
domain=config.domain,
42+
)
43+
44+
client.import_package(package_full_path)

shellfoundry/utilities/shell_package_installer.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/python
2-
# -*- coding: utf-8 -*-
32

43
import json
54
import os
@@ -13,7 +12,14 @@
1312
from urllib2 import HTTPError
1413

1514
from 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

1824
from shellfoundry.exceptions import FatalError
1925
from 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(

tests/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
import os
42

53
TEST_DIR = os.path.dirname(__file__)

0 commit comments

Comments
 (0)