Coder Social home page Coder Social logo

onemind-services-llc / py-jelastic Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 11.27 MB

Python API client library for Jelastic.

Home Page: https://onemind-services-llc.github.io/py-jelastic/

License: Apache License 2.0

Python 100.00%
api-client jelastic python sdk-python virtuozzo

py-jelastic's Introduction

py-jelastic

CI Documentation Upload Python Package

Python API client library for Jelastic.

Note: This library is only tested with Jelastic version v8.4.1.

Installation

You can clone the repo and run python setup.py install.

Quick Start

To begin, import the Jelastic client and instantiate the API.

from jelastic import Jelastic

jelastic = Jelastic(
    'https://app.xapp.cloudmydc.com',
    token='d6f4e314a5b5fefd164995169f28ae32d987704f'
)

The library follows the convention from the Jelastic API documentation. For example, to get the list of accounts, you would do the following:

from jelastic import Jelastic

jelastic = Jelastic(
    'https://app.xapp.cloudmydc.com',
    token='d6f4e314a5b5fefd164995169f28ae32d987704f'
)

accounts = jelastic.billing.Account.GetAccounts()

The result is a JSON dictionary returned from the Jelastic API.

You can read more about this library at Read the Docs.

py-jelastic's People

Contributors

abhi1693 avatar github-actions[bot] avatar kprince28 avatar mjoshionemind avatar rraj9921 avatar vkumar786 avatar yash-pal1 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

py-jelastic's Issues

CreateEnvTask is missing `envName`

py-jelastic version

v0.1.0

Jelastic version

v8.4.2

Python version

3.10

Steps to Reproduce

As per the docs, CreateEnvTask requires envName which is missing from the parameters

Expected Behavior

Parameter should accept env_name

Observed Behavior

TypeError: _Scheduler.CreateEnvTask() got an unexpected keyword argument 'env_name'

Recheck Signatures of all Methods

py-jelastic version

0.1.0

Jelastic version

8.4.1

Python version

3.10

Steps to Reproduce

Please review the documentation where you will find a set of optional parameters. These parameters are categorized into two groups: some are compiled into a list, while others represent individual optional values.

Expected Behavior

There should be single optional value

Observed Behavior

There is lists of optional values.

Dot Notation Access for API Response Handling

py-jelastic version

0.0.4

Jelastic version

8.4.1

Feature type

New functionality

Proposed functionality

The addition of a feature to convert dictionaries to objects with dot notation access in py-jelastic would enhance the flexibility and readability of the code when managing Jelastic environment configurations. The feature would involve creating a new utility class within py-jelastic that can recursively convert dictionaries into objects. This class should be able to handle nested dictionaries and convert them into nested objects, providing a clean and Pythonic way to access response keys. It should also include error handling to manage attempts to access keys that do not exist.

Use case

This feature would be beneficial for py-jelastic users who prefer object-oriented access to configurations rather than dictionary-based access, which can be verbose and error-prone when dealing with deeply nested structures. For instance, users managing complex configurations with multiple nested parameters would find it easier to read and write config.database.host instead of config['database']['host']. This can also reduce the likelihood of typos and runtime errors due to incorrect key access, thus improving the overall reliability of configuration management within the py-jelastic framework.

External dependencies

No response

Fix Functions Names in billing.order

py-jelastic version

v0.1.2

Jelastic version

8.4.1

Python version

3.10

Steps to Reproduce

There is wrong functions written tn billing.Order.
Check Here.
https://docs.jelastic.com/api/private/#!/api/billing.Order

Expected Behavior

Actual functions name

  • GetFraudCheckUrl
  • GetHistoryUrl
  • GetOrders
  • GetUrlSupplyingCookiesForHistoryUrl
  • OrderEvent
  • PayServicePlan

Observed Behavior

Functions name in billing.Order

  • AddStats
  • EnvResources
  • EnvsResources
  • EnvsResourcesByAccount
  • GetOptions
  • SetOptions

Remote end closed connection without response

py-jelastic version

v0.1.2

Jelastic version

v8.4.2

Python version

3.10

Steps to Reproduce

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']}")

while executing above code i am getting below 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# 

Expected Behavior

it should not give exception.

Observed Behavior

It appears that we might need to consider extending the timeout duration in the request, though there is uncertainty regarding this course of action.

Allow to override `appid` for methods

py-jelastic version

v0.1.3

Jelastic version

v8.4.2

Feature type

Change to existing functionality

Proposed functionality

Every method internally sets the appid to cluster as a default. This should be changed to allow the user to set the appid for the methods. If this value is not set, keep the default as is.

Example Code:

def GetNodesAffinitySuggestion(
        self,
        target_app_ids: list[str] = None,
        node_groups: list[str] = None,
        uids: list[int] = None,
        thread_count: int = None,
        app_id: str = None,
    ):
    return self._get(
            "GetNodesAffinitySuggestion",
            params={
                "targetAppIds": target_app_ids,
                "nodeGroups": node_groups,
                "uids": uids,
                "threadCount": thread_count,
                "appid": app_id,
            },
            delimiter=",",
        )

Use case

To invoke an environment task, a script that exists within an environment is needed. However, functionality was removed in v0.1.3 which caused the script to be not found in the environment even though it existed in the cluster level.

To test the viability to the solution, let's test this on a smaller scale by only updating development.Scripting module with this change. This will allow us to test the changes for netbox-cloud-pilot which stopped working with the release of v0.1.3 today possibly due to missing app_id which existed for the methods in older versions.

External dependencies

No response

cannot pickle '_thread.RLock' object

py-jelastic version

0.0.4

Jelastic version

8.4.2

Python version

3.10

Steps to Reproduce

import django_rq
from jelastic import Jelastic

client = Jelastic(...)
control = client.environment.Control

queue = django_rq.get_queue()
queue(control.RestartNodes, node_group='cp', env_name='test')

Expected Behavior

The function should be submitted to the queue

Observed Behavior

cannot pickle '_thread.RLock' object

marketplace.App.Install settings parameter type mismatch

Proposed Changes

marketplace.App.Install settings should be a dict

Justification

As a user, I need to pass a dictionary to the settings

jelastic.marketplace.App.Install(
    settings={
        "deploymentType": JELASTIC_DEPLOYMENT_TYPE,
        "version": JELASTIC_NETBOX_VERSION,
        "loadGrowth": "slow",
        "loglevel": "INFO",
        "highQueue": 0,
        "lowQueue": 0,
        "defaultQueue": 1,
        "dbDiskLimit": 10,
        "redisDiskLimit": 1
    },
)

Dynamic Client Application Timeouts and Enhanced Server Request Handling: Introducing Unique 'ruk' Parameter for Request Repetition

py-jelastic version

v.0.1.4

Jelastic version

v.8.4.2

Feature type

New functionality

Proposed functionality

Each client application has its own timeouts. Therefore, if deployments take too long, the Python requests library may result in an error: "Remote end closed connection without response."
you can try to repeat the request. To make the server think that the repeated request is the same as initial request, the only extra thing you need to do is to add a unique ruk parameter which would be the same for each repeated request. For example:

...marketplace/app/rest/install?...&ruk=107a6b0a-d61d-4ad3-aaba-ebe0cbd2d373
...marketplace/app/rest/install?...&ruk=107a6b0a-d61d-4ad3-aaba-ebe0cbd2d373

When the server sees the ruk parameter, it will try to retrieve the response from the database. There could be three different situations:

  • if there is no request with such a ruk, the server will start a new installation
  • if the record exists and the response is empty, the server will wait until the response is ready and then return it
  • if the record exists and the response is not empty, the server will simply return the response from the database

Use case

Each client application has its own timeouts. Therefore, if deployments take too long, the Python requests library may result in an error: "Remote end closed connection without response."

sample url value

url = "baseURL/marketplace/app/rest/install?ruk=0f697749-e4a1-4949-ba34-28eee1f5ddc7&appid=cluster&displayName=NetBox+Demo&envGroups=NetBox+Testing+Area&envName=netbox-demo-gaurav-1006&id=netbox&region=colpaashg&session=JELASTIC_TOKEN_HERE&settings=%7B%22deploymentType%22%3A+%22development%22%2C+%22version%22%3A+%22v3.5%22%2C+%22loadGrowth%22%3A+%22slow%22%2C+%22loglevel%22%3A+%22INFO%22%2C+%22highQueue%22%3A+0%2C+%22lowQueue%22%3A+0%2C+%22defaultQueue%22%3A+1%2C+%22dbDiskLimit%22%3A+10%2C+%22redisDiskLimit%22%3A+1%7D&skipEmail=True&skipNodeEmails=True"

External dependencies

we can pass the uuid as ruk value so may be we need uuid module.

Update variable naming "_endpoint" to "_endpoint2"

py-jelastic version

v0.1.6

Jelastic version

v8.4.1

Python version

3.10

Steps to Reproduce

  1. Search for occurrences of the endpoint variable inside the sub-module
  2. Observe the usage of both "_endpoint" and "_endpoint2".

Expected Behavior

All instances of the endpoint variable should be consistently named "_endpoint2" inside the sub-module

Observed Behavior

Inconsistent naming of the endpoint variable is observed, with occurrences of both "_endpoint" and "_endpoint2" inside the sub-module

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.