-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from DanNiESh/update
Update esi sdk
- Loading branch information
Showing
25 changed files
with
482 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,70 @@ | ||
# esisdk | ||
Unified SDK for ESI | ||
|
||
## Use the SDK in python scripts | ||
### Install ESI SDK: | ||
``` | ||
python setup.py install | ||
``` | ||
|
||
### Create a connection to ESI SDK | ||
|
||
There are several methods to establish a connection using the ESI SDK. Since the ***esi.connection.ESIConnection*** class inherits from ***openstack.connection.Connection***, [methods](https://docs.openstack.org/openstacksdk/latest/user/connection.html) applicable for creating connections in the OpenStack SDK can also be used with the ESI SDK. Below are some common ways to create an ESIConnection: | ||
|
||
**Create a connection using only keyword arguments** | ||
``` | ||
from esi import connection | ||
conn = connection.ESIConnection( | ||
region_name='example-region', | ||
auth={ | ||
'auth_url': 'https://auth.example.com', | ||
'username': 'user', | ||
'password': 'password', | ||
'project_name': 'project_name', | ||
'user_domain_name': 'user_domain_name', | ||
'project_domain_name': 'project_domain_name' | ||
}, | ||
interface='public' | ||
) | ||
``` | ||
**Create a connection from existing CloudRegion** | ||
``` | ||
from esi import connection | ||
import openstack.config | ||
config = openstack.config.get_cloud_region( | ||
cloud='example', | ||
region_name='earth' | ||
) | ||
conn = connection.ESIConnectionn(config=config) | ||
``` | ||
|
||
### Make API calls | ||
Detailed APIs can be found in the `esi/lease/v1/_proxy.py` file. Below are simple examples demonstrating lease resource CRUD operations. | ||
``` | ||
import esi | ||
import os | ||
TEST_CLOUD = os.getenv('OS_TEST_CLOUD', 'devstack-admin') | ||
conn = esi.connect(cloud=TEST_CLOUD) | ||
# Create a lease | ||
def lease_create(conn, resource_uuid, project_id, **kwargs): | ||
lease = conn.lease.create_lease(resource_uuid=resource_uuid, | ||
project_id=project_id, | ||
**kwargs) | ||
# List leases | ||
def lease_list(conn, **kwargs): | ||
leases = conn.lease.leases(**kwargs) | ||
# Update a lease | ||
def lease_update(conn, lease, **kwargs): | ||
lease_dict = conn.lease.update_lease(lease, **kwargs) | ||
# Delete a lease | ||
def lease_delete(conn, lease_id): | ||
leases = conn.lease.delete_lease(lease_id) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, 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. | ||
|
||
import argparse | ||
import typing as ty | ||
|
||
import esi.connection | ||
|
||
from openstack._log import enable_logging | ||
import openstack.config | ||
|
||
__all__ = [ | ||
'connect', | ||
'enable_logging', | ||
] | ||
|
||
|
||
def connect( | ||
cloud: ty.Optional[str] = None, | ||
app_name: ty.Optional[str] = None, | ||
app_version: ty.Optional[str] = None, | ||
options: ty.Optional[argparse.Namespace] = None, | ||
load_yaml_config: bool = True, | ||
load_envvars: bool = True, | ||
**kwargs, | ||
) -> esi.connection.ESIConnection: | ||
"""Create a :class:`~esi.connection.ESIConnection` | ||
:param string cloud: | ||
The name of the configuration to load from clouds.yaml. Defaults | ||
to 'envvars' which will load configuration settings from environment | ||
variables that start with ``OS_``. | ||
:param argparse.Namespace options: | ||
An argparse Namespace object. Allows direct passing in of | ||
argparse options to be added to the cloud config. Values | ||
of None and '' will be removed. | ||
:param bool load_yaml_config: | ||
Whether or not to load config settings from clouds.yaml files. | ||
Defaults to True. | ||
:param bool load_envvars: | ||
Whether or not to load config settings from environment variables. | ||
Defaults to True. | ||
:param kwargs: | ||
Additional configuration options. | ||
:returns: esi.connnection.ESIConnection | ||
:raises: keystoneauth1.exceptions.MissingRequiredOptions | ||
on missing required auth parameters | ||
""" | ||
cloud_region = openstack.config.get_cloud_region( | ||
cloud=cloud, | ||
app_name=app_name, | ||
app_version=app_version, | ||
load_yaml_config=load_yaml_config, | ||
load_envvars=load_envvars, | ||
options=options, | ||
**kwargs, | ||
) | ||
return esi.connection.ESIConnection( | ||
config=cloud_region, | ||
vendor_hook=kwargs.get('vendor_hook'), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.