Skip to main content

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',
'描述':无,
'html_url':'https:
//www.distelli.com/youraccount/apps/test_app','latest_build':无,
'latest_release':无,
'名称':'test_app',
'所有者': '你的帐户',
'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',
'创建':'2016-12-30T18:24:07.511Z',
'deployments_url':'https://api. distelli.com/youraccount/apps/test_app2/deployments','description'
:'另一个测试应用',
'html_url':'https:
//www.distelli.com/youraccount/apps/test_app2','latest_build':无,
'latest_release':无,
'name':'test_app2',
'owner':'你的帐户',
'releases_url':'https://api.distelli.com/youraccount/apps/test_app2/releases'}]

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

client.app('test_app2')

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

### 创建一个应用程序

client.create_app('test_app3', 'Description of the application')

结果和上面的`app()`一样,但是只显示了添加的应用程序。

### 删除应用程序

client.delete_app('test_app3')

## 环境操作

### 查看现有环境:

只需运行:

envs = client.envs()

结果显示为 Python dict:

[{'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 ' :无, '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', '所有者':'您的帐户', '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', '值': '"/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',
“描述”:无,
“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', '环境描述'



### 删除环境

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/服务器/766b88c8-e925-11e4-ae8b-080027cc07f7',
'cloud_instance_id':无,
'cloud_location':无,
'cloud_provider':无,
'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':无}]

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

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 中所述,

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

创建一个virtualenv(例如`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 查看哈希)

已上传 source