跳转到主要内容

Distelli REST API客户端 https://www.distelli.com/docs/api/

项目描述

# Python Distelli

这是一个Distelli REST API的客户端。它目前允许您获取现有的应用信息,以及创建和删除应用。

### 入门

`distelli-python`依赖于`requests`库。

安装库

pip install distelli

导入模块

from distelli import Distelli

提供用户名和api\_token凭证

client = Distelli(username=YOUR_USERNAME, api_token=YOUR_API_TOKEN)

或设置环境变量

export DISTELLI_USERNAME=YOUR_USERNAME
export DISTELLI_API_TOKEN=YOUR_API_TOKEN

无凭证构造`Distelli`

client = Distelli()

## 应用操作

### 查看现有的应用

只需运行

apps = client.apps()

结果以Python字典的形式出现

[{'api_url': 'https://api.distelli.com/youraccount/apps/test_app',
'builds_url': 'https://api.distelli.com/youraccount/apps/test_app/builds',
'created': '2016-12-30T18:07:50.284Z',
'deployments_url': 'https://api.distelli.com/youraccount/apps/test_app/deployments',
'description': None,
'html_url': 'https://www.distelli.com/youraccount/apps/test_app',
'latest_build': None,
'latest_release': None,
'name': 'test_app',
'owner': 'youraccount',
'releases_url': 'https://api.distelli.com/youraccount/apps/test_app/releases'},
{'api_url': 'https://api.distelli.com/youraccount/apps/test_app2',
'builds_url': 'https://api.distelli.com/youraccount/apps/test_app2/builds',
'created': '2016-12-30T18:24:07.511Z',
'deployments_url': 'https://api.distelli.com/youraccount/apps/test_app2/deployments',
'description': 'Another test app',
'html_url': 'https://www.distelli.com/youraccount/apps/test_app2',
'latest_build': None,
'latest_release': None,
'name': 'test_app2',
'owner': 'youraccount',
'releases_url': 'https://api.distelli.com/youraccount/apps/test_app2/releases'}]

### 获取特定应用的详细信息

client.app('test_app2')

结果与上面的`apps()`相同,但只显示指定的应用。

### 创建一个应用

client.create_app('test_app3', '应用的描述')

结果与上面的`app()`相同,但只显示添加的应用。

### 删除一个应用

client.delete_app('test_app3')

## 环境操作

### 查看现有环境

只需运行

envs = client.envs()

结果以Python字典的形式出现

[{'active_release_url': 'https://api.distelli.com/youraccount/apps/demo-app/releases/v1',
'active_release_version': 'v1',
'api_url': 'https://api.distelli.com/youraccount/envs/demo-app-dev',
'app_name': 'demo-app',
'app_url': 'https://api.distelli.com/youraccount/apps/demo-app',
'deployments_url': 'https://api.distelli.com/youraccount/envs/demo-app-dev/deployments',
'description': None,
'html_url': 'https://www.distelli.com/youraccount/envs/demo-app-dev',
'last_deployment_url': 'https://api.distelli.com/youraccount/deployments/121509',
'name': 'demo-app-dev',
'owner': 'youraccount',
'server_count': 1,
'servers_url': 'https://api.distelli.com/youraccount/envs/demo-app-dev/servers',
'settings_url': 'https://api.distelli.com/youraccount/envs/demo-app-dev/settings',
'tags': [],
'vars': [{'name': 'ENV_FOLDER', 'value': '"/var/conf/env/dev"'}]},
{'active_release_url': 'https://api.distelli.com/youraccount/apps/demo-app/releases/v1',
'active_release_version': 'v1',
'api_url': 'https://api.distelli.com/youraccount/envs/demo-app-preview',
'app_name': 'demo-app',
'app_url': 'https://api.distelli.com/youraccount/apps/demo-app',
'deployments_url': 'https://api.distelli.com/youraccount/envs/demo-app-preview/deployments',
'description': None,
'html_url': 'https://www.distelli.com/youraccount/envs/demo-app-preview',
'last_deployment_url': 'https://api.distelli.com/youraccount/deployments/121515',
'name': 'demo-app-preview',
'owner': 'youraccount',
'server_count': 1,
'servers_url': 'https://api.distelli.com/youraccount/envs/demo-app-preview/servers',
'settings_url': 'https://api.distelli.com/youraccount/envs/demo-app-preview/settings',

### 获取特定环境的详细信息

client.env('demo-app-preview')

结果与上面的 `envs()` 相同,但仅显示指定的应用程序。

### 创建环境

client.create_env('demo-app-live', '环境的描述')

结果与上面的 `env()` 相同,但仅显示添加的环境。

### 删除环境

client.delete_env('demo-app-live')

### 将服务器添加到环境

client.add_env_servers('demo-app-live', ['server-id-1', 'server-id-2'])

### 从环境中移除服务器

client.remove_env_servers('demo-app-live', ['server-id-1', 'server-id-2'])

## 服务器操作

### 查看现有服务器

只需运行

envs = client.servers()

结果以Python字典的形式出现

[{'agent_version': '3.63',
'api_url': 'https://api.distelli.com/youraccount/servers/766b88c8-e925-11e4-ae8b-080027cc07f7',
'cloud_instance_id': None,
'cloud_location': None,
'cloud_provider': None,
'dns_name': 'demo-app-preview.youraccount.com',
'html_url': 'https://www.distelli.com/youraccount/servers/766b88c8-e925-11e4-ae8b-080027cc07f7',
'ip_addr': '192.168.1.112',
'is_healthy': 'true',
'mac_address': '08:00:27:cc:07:f7',
'os_name': 'Ubuntu',
'os_version': '14.04',
'server_id': '766b88c8-e925-11e4-ae8b-080027cc07f7',
'start_time': '2016-07-26T09:16:41.353Z',
'tags': ['becon', 'beta', 'preview']},
{'agent_version': '3.66',
'api_url': 'https://api.distelli.com/youraccount/servers/a4d253a3-1668-e64b-86be-122d4227c561',
'cloud_instance_id': 'i-9b668b5317f00995d',
'cloud_location': 'eu-west-1',
'cloud_provider': 'Aws',
'dns_name': 'demo-app-live.youraccount.com',
'html_url': 'https://www.distelli.com/youraccount/servers/a4d253a3-1668-e64b-86be-122d4227c561',
'ip_addr': '10.226.127.83',
'is_healthy': 'false',
'mac_address': '12:2d:42:27:c5:61',
'os_name': 'Ubuntu',
'os_version': '14.04',
'server_id': 'a4d253a3-1668-e64b-86be-122d4227c561',
'start_time': '2016-12-20T19:39:32.835Z',
'tags': None}]

### 获取特定服务器的详细信息

client.server('a4d253a3-1668-e64b-86be-122d4227c561')

结果与上面的 `servers()` 相同,但仅显示指定的服务器。

### 从您的帐户中删除服务器

client.delete_server('a4d253a3-1668-e64b-86be-122d4227c561')

## 测试

要运行测试,您需要一个Distelli帐户,并且您需要知道您的Distelli用户名和API令牌。如https://www.distelli.com/docs/api/getting-started-with-distelli-api中所述

测试将在您的帐户中创建和删除工件。

创建一个虚拟环境(例如 `mkvirtualenv --python=$(which python3) distelli-python`)

安装要求。`pip install -r requirements.txt`

使用环境变量 `DISTELLI_TEST_USERNAME` 和 `DISTELLI_TEST_API_TOKEN` 设置您的用户名和API令牌来运行测试

DISTELLI_TEST_USERNAME=<username> DISTELLI_TEST_API_TOKEN=<api_token> make test

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源代码分发

distelli-0.1.0.tar.gz (4.7 kB 查看哈希值)

上传时间 源代码

支持