Code Monkey home page Code Monkey logo

python-ecsclient's Introduction

python-ecsclient

Build Status Read the docs Python Versions Version Coverage

This library is the Python Software Development Kit (SDK) for Dell EMC ECS. It allows developers to interact with the ECS Management API. You can find the ECS API specification here.

This library is the successor of ECS Minion.

Quick Start

You can install python-ecsclient using pip.

$ pip install python-ecsclient

Creating an instance of the ECSClient class allows the following arguments:

+-----------------------+------------+------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | Name | Required | Default Value | Description | +=======================+============+========================+===============================================================================================================================================+ | version | Yes | None | Version of the target ECS system. Options are 2, 3 and 4 | +-----------------------+------------+------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | username | No | None | The username used to fetch the ECS token | +-----------------------+------------+------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | password | No | None | The password used to fetch the ECS token | +-----------------------+------------+------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | token | No | None | Pass a token to ECSClient (username/password are ignored then) | +-----------------------+------------+------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | ecs_endpoint | Yes | None | The ECS API endpoint, ex: https://192.168.0.149:4443 | +-----------------------+------------+------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | token_endpoint | No | None | The ECS API endpoint, ex: https://192.168.0.149:4443/login | +-----------------------+------------+------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | verify_ssl | No | False | Whether to check a host's SSL certificate | +-----------------------+------------+------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | token_path | No | /tmp/ecsclient.tkn | The location to store the temporary token file | +-----------------------+------------+------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | request_timeout | No | 15.0 | Stop waiting for a response after a given number of seconds, this is a decimal value. Ex: 10.0 is ten seconds | +-----------------------+------------+------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | cache_token | No | True | Whether to cache the token, by default this is true you should only switch this to false when you want to directly fetch a token for a user | +-----------------------+------------+------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | override_header | No | None | Add X-EMC-Override header with the header value in API request only if it is not None | +-----------------------+------------+------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ This is how you can instantiate the Client class and use the library.

from ecsclient.client import Client

client = Client('3',
                username='ecsadmin@internal',
                password='PASSWORD',
                token_endpoint='https://192.168.0.149:4443/login',
                ecs_endpoint='https://192.168.0.149:4443')

print(client.user_info.whoami())

Take a look at our documentation to find a list of all supported ECS endpoints and services.

Supply a token

You can pass an authentication token directly to the client which means you don't need to supply a username/password.

client = Client('3',
                token='ALAcbGZtbjh6eVB3eUF1TzFEZWNmc0M2VVl2QjBVPQM',
                ecs_endpoint='https://192.168.1.146:4443')

Token caching

By default, the client caches the auth token. But you can disable caching by setting the cache_token parameter to false.

client = Client('3',
                username='someone',
                password='password',
                token_endpoint='https://192.168.1.146:4443/login',
                ecs_endpoint='https://192.168.1.146:4443',
                cache_token=False)

Alternatively, when token caching is enabled, you may want to force the client to obtain a new token on the next call. To do so, you can remove the cached token.

client.remove_cached_token()

Add X-EMC-Override: "true" header ~~~~~~~~~~~~~~ You can pass override_header to the client which means the user wants to add custom X-EMC-Override header into API request

client = Client('3',
                username='someone',
                password='password',
                token_endpoint='https://192.168.1.146:4443/login',
                ecs_endpoint='https://192.168.1.146:4443',
                override_header='true')

Supported endpoints

The following table shows the supported endpoints per API version.

v2 v3 v4
Configuration
Certificate

Configuration Properties

✓*

✓*

✓*

Licensing

Feature

Syslog

✓*

✓*

Snmp

✓*

✓*

CAS
CAS User Profile

✓*

✓*

✓*

File System Access
NFS

Metering
Billing

~

~

~

Migration
Transformation

Monitoring
Capacity

Dashboard

✓*

✓*

✓*

Events

✓*

✓*

✓*

Alerts

✓*

✓*

✓*

Multi-tenancy
Namespace

✓*

✓*

✓*

Tenant(Flex)

✓*

Geo-Replication
Replication Group

Temporary Failed Zone

✓*

✓*

✓*

Provisioning
Base URL

✓*

✓*

✓*

Bucket

✓*

Data Store

✓*

Node

~

~

~

Storage Pool

Virtual Data Center

VDC Keystore

Support
Call Home

User Management
Authentication Provider

~

~

~

Password Group (Swift)

Secret Key

Secret Key Self-Service

User (Object)

User (Management)

✓*

Other
Who am I

Legend:

Supported and tested

✓*

Supported but not tested yet

~

Partially supported

Not supported yet
Not available in this API version

Development

Getting Started

Assuming that you have Python and virtualenv installed, set up your environment and install the required dependencies like this instead of the pip install python-ecsclient defined above:

$ git clone https://github.com/EMCECS/python-ecsclient.git
$ cd python-ecsclient
$ virtualenv venv
...
$ . venv/bin/activate
$ pip install -r requirements.txt

Running Tests

You can run tests in all supported Python versions using tox. By default, it will run all of the unit tests, but you can also specify your own nosetests options. Note that this requires that you have all supported versions of Python installed, otherwise you must pass -e or run the nosetests command directly:

$ tox
$ tox -e py27,py35 tests/functional

You can also run individual tests with your default Python version:

$ nosetests tests/unit

License

This software library is released to you under the Apache License 2.0. See LICENSE for more information.


ECS is an Dell EMC product, trademarked, copyrighted, etc.

python-ecsclient's People

Contributors

adrianmo avatar apeter0807 avatar ben-schumacher avatar brc avatar chadlung avatar crazylionheart avatar dunedodo avatar open4storage avatar padthaitofuhot avatar rm75 avatar skizot722 avatar spiegela avatar twincitiesguy avatar xiaoxin-ren avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-ecsclient's Issues

Issues in exceptions.py

Fedor: who is supporting python client? Code in client:

        a = self.message
        if self.ecs_details not in a:
            a += ' - %s' % self.ecs_details
        if self.ecs_description not in a:
            a += ' - %s' % self.ecs_description
        b = ''
        if self.http_scheme:
            b += '%s://' % self.http_scheme
        if self.http_host:
            b += self.http_host
        if self.http_port:
            b += ':%s' % self.http_port
        if self.http_path:
            b += self.http_path
        if self.http_query:
            b += '?%s' % self.http_query
        if self.http_status:
            if b:
                b = '%s %s' % (b, self.http_status)
            else:
                b = str(self.http_status)
        if self.http_reason:
            if b:
                b = '%s %s' % (b, self.http_reason)
            else:
                b = '- %s' % self.http_reason
        if self.http_response_content:
            if len(self.http_response_content) <= 60:
                b += '   %s' % self.http_response_content
            else:
                b += '  [first 60 chars of response] %s' \
                     % self.http_response_content[:60]
        return b and '%s: %s' % (a, b) or a```
Fedor: https://github.com/EMCECS/python-ecsclient/blob/master/ecsclient/common/exceptions.py#L72
Fedor: It's creating new exceptions)
Fedor: every exception raising use it
Fedor: and `first 60 chars of response` is too small. I think we should increase size of message. It's just logs, so I don't understand why client needs to cut messages

Ability to create data stores and VDCs

Check and add tests for the data store endpoint. Also make sure it can create new VDCs. Since it's not documented in the API, review how it's done in the CLI and ECS CE step 2 script.

`management_users` results in 400 Bad Request errors

Depends on #12

    conf.api_client.management_user.create_local_user_info(name, mu_pass, **mu_dict)
  File "/usr/local/lib/python2.7/site-packages/ecsclient/common/user_management/management_user.py", line 42, in create_local_user_info
    return self.conn.post(url='vdc/users', json_payload=payload)
  File "/usr/local/lib/python2.7/site-packages/ecsclient/baseclient.py", line 111, in post
    return self._request(url, json_payload, http_verb='POST')
  File "/usr/local/lib/python2.7/site-packages/ecsclient/baseclient.py", line 160, in _request
    raise ECSClientException.from_response(req)
ecsclient.common.exceptions.ECSClientException: Unrecognized field "user" (Class com.emc.storageos.data.datasvcmodels.mgmtuserinfo.MgmtUserInfoCreate), not marked as ignorable
 at [Source: HttpInputOverHTTP@5254f7cd[c=95,s=STREAM]; line: 1, column: 35] (through reference chain: com.emc.storageos.data.datasvcmodels.mgmtuserinfo.MgmtUserInfoCreate["user"]) - Bad request body: https://192.168.2.220:4443/vdc/users 400 Bad Request  [first 60 chars of response] {"code":1013,"retryable":false,"description":"Bad request bo

For reference, the values passed to api_client.management_user.create_local_user_info(name, mu_pass, **mu_dict) are:

name = "user1"
mu_pass = "ChangeMe"
mu_dict = {'is_system_monitor': False, 'is_system_admin': False}

Let me know what other data you'd like to help troubleshooting.

Create a utilities class

Create a utilities class with functions for users to validate responses and other useful utilities.

Example for validating a response:

from ecsclient import util, schemas
util.is_valid_response(response, schemas.LICENSE)

Error when creating a data store in ECS 3.1

The API has changed in 3.1 and it fails to create data store given an IP address. It should instead use a node ID.

Error output:

> Adding Data Stores to Storage Pool:
>       vdc1/sp1/192.168.2.220
Traceback (most recent call last):
  File "/usr/local/bin/ecsconfig", line 11, in <module>
    load_entry_point('ecsdeploy==2.4.0', 'console_scripts', 'ecsconfig')()
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 1092, in invoke
    rv.append(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args[1:], **kwargs)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/bin/ecsconfig.py", line 637, in sp
    tasks = add_all()
  File "/usr/local/bin/ecsconfig.py", line 613, in add_all
    sp_tasks.extend(add_one(name))
  File "/usr/local/bin/ecsconfig.py", line 605, in add_one
    sp_tasks.append(sp_add_node(sp_id, node))
  File "/usr/local/bin/ecsconfig.py", line 582, in sp_add_node
    return conf.api_client.data_store.create(**kwargs)
  File "/usr/local/lib/python2.7/site-packages/ecsclient/common/provisioning/data_store.py", line 217, in create
    return self.conn.post('vdc/data-stores/commodity', json_payload=payload)
  File "/usr/local/lib/python2.7/site-packages/ecsclient/baseclient.py", line 120, in post
    return self._request(url, json_payload, http_verb='POST')
  File "/usr/local/lib/python2.7/site-packages/ecsclient/baseclient.py", line 170, in _request
    raise ECSClientException.from_response(req)
ecsclient.common.exceptions.ECSClientException: Usage of node IP address in place of nodeId is no longer supported - Api Parameter Node Id Invalid: https://192.168.2.220:4443/vdc/data-stores/commodity 400 Bad Request  [first 60 chars of response] {"code":1050,"retryable":false,"description":"Api Parameter

Create Bucket when compliance enabled fails

We have a requirement to create some namespaces with compliance enabled but I noted when attempting to create buckets in those namespaces using ecsclient an error is returned stating that "Incorrect retention parameter: bucket retention period must be set if retention enforcement is off".

On checking I see that under ecsclient.common.provisioning.bucket the create under the Bucket class does not support specifying retention as specified int he REST API guide for ECS - is there supposed to be another way around this (i.e. am I doing it wrong - probably yes is the answer :) ) As there is a function to alter retention post bucket creation I had assumed that you'd be able to create the bucket and then modify retention but no such luck.

Upon modifying bucket.py to allow for specification of retention the bucket is able to be created successfully and specifying a retention of 0 seems as the default also seems to allow for non-compliance buckets to be created without issue.

Create a CLI

Create a command line utility to enable users to use this library from the terminal and automate it in shell scripts.

Create Bucket

Am getting error while using
client.bucket.create(bucket_name='bucket-test1', replication_group='REP-ECS', namespace='namespace1')

File "", line 1, in
File "ecs.py", line 244, in create_bucket
status = self.client.bucket.create(bucket_name, replication_group, namespace)
File "/ecsclient/common/provisioning/bucket.py", line 85, in create
return self.conn.post('object/bucket', json_payload=payload)
File "/ecsclient/baseclient.py", line 120, in post
return self._request(url, json_payload, http_verb='POST')
File "/ecsclient/baseclient.py", line 170, in _request
raise ECSClientException.from_response(req)
ecs.ExecutionError: Can not construct instance of java.lang.Boolean from String value 'ess_aut_ns': only "true" or "false" recognized
at [Source: HttpInputOverHTTP@7025d20c[c=153,s=STREAM]; line: 1, column: 2] (through reference chain: com.emc.storageos.data.datasvcmodels.bucket.ObjectBucketParam["filesystem_enabled"]) - Bad request

Python module to do Object operations

Is there an equivalent Python Module to List objects in a given bucket ;
GET
retrieve object
retrieve object’s metadata
retrieve object’s ACLs

PUT, POST, DELETE method as well.

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.