import humanize
import time
import requests
from jelastic import Jelastic
# from semver.version import Version
# Get the Jelastic environment variables
JELASTIC_URL = 'https://app.xapp.cloudmydc.com'
JELASTIC_TOKEN = 'TOKEN_HERE'
JELASTIC_ENV_NAME = 'netbox-demo-testing-123'
JELASTIC_REGION = 'colpaashg'
JELASTIC_DEBUG = False
# Initialize the Jelastic client
print(f"Connecting to Jelastic at {JELASTIC_URL}")
jelastic = Jelastic(base_url=JELASTIC_URL, token=JELASTIC_TOKEN, debug=JELASTIC_DEBUG)
environments = jelastic.environment.Control.GetEnvs(lazy=True).get('infos', [])
print(f"Found {len(environments)} environments")
for environment in environments:
if environment['env']['shortdomain'] == JELASTIC_ENV_NAME:
print(f"Deleting existing NetBox deployment: {JELASTIC_ENV_NAME}")
jelastic.environment.Control.DeleteEnv(env_name=JELASTIC_ENV_NAME)
break
# Create the NetBox demo environment
print(f"Creating new NetBox deployment: {JELASTIC_ENV_NAME}")
start_time = time.time()
result = jelastic.marketplace.App.Install(
settings={
"deploymentType": "production",
"version": "v3.5",
"loadGrowth": "slow",
"loglevel": "INFO",
"highQueue": 0,
"lowQueue": 0,
"defaultQueue": 1,
"dbDiskLimit": 10,
"redisDiskLimit": 1
},
env_name=JELASTIC_ENV_NAME,
env_groups="NetBox Testing Area",
skip_email=True,
skip_node_emails=True,
display_name="NetBox Demo",
id="netbox",
region=JELASTIC_REGION
)
print(f"Deployment took {humanize.naturaldelta(time.time() - start_time)}")
if result['result'] != 0:
raise Exception(f"Failed to create NetBox deployment: {result['error']}")
Connecting to Jelastic at https://app.xapp.cloudmydc.com
Found 7 environments
Deleting existing NetBox deployment: netbox-demo-testing-tejasree
Creating new NetBox deployment: netbox-demo-testing-tejasree
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 790, in urlopen
response = self._make_request(
File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 536, in _make_request
response = conn.getresponse()
File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 461, in getresponse
httplib_response = super().getresponse()
File "/usr/local/lib/python3.10/http/client.py", line 1375, in getresponse
response.begin()
File "/usr/local/lib/python3.10/http/client.py", line 318, in begin
version, status, reason = self._read_status()
File "/usr/local/lib/python3.10/http/client.py", line 287, in _read_status
raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line 486, in send
resp = conn.urlopen(
File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 844, in urlopen
retries = retries.increment(
File "/usr/local/lib/python3.10/site-packages/urllib3/util/retry.py", line 470, in increment
raise reraise(type(error), error, _stacktrace)
File "/usr/local/lib/python3.10/site-packages/urllib3/util/util.py", line 38, in reraise
raise value.with_traceback(tb)
File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 790, in urlopen
response = self._make_request(
File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 536, in _make_request
response = conn.getresponse()
File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 461, in getresponse
httplib_response = super().getresponse()
File "/usr/local/lib/python3.10/http/client.py", line 1375, in getresponse
response.begin()
File "/usr/local/lib/python3.10/http/client.py", line 318, in begin
version, status, reason = self._read_status()
File "/usr/local/lib/python3.10/http/client.py", line 287, in _read_status
raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/app/netbox.py", line 34, in <module>
result = jelastic.marketplace.App.Install(
File "/usr/local/lib/python3.10/site-packages/jelastic/api/marketplace/__init__.py", line 439, in Install
return self._get(
File "/usr/local/lib/python3.10/site-packages/jelastic/api/abstract.py", line 185, in _get
response = self._session.get(url)
File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 602, in get
return self.request("GET", url, **kwargs)
File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 589, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 703, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line 501, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
root@e294c19cf99f:/app#
it should not give exception.
It appears that we might need to consider extending the timeout duration in the request, though there is uncertainty regarding this course of action.