Skip to content

Commit

Permalink
initial upload
Browse files Browse the repository at this point in the history
  • Loading branch information
mzjhe committed Aug 31, 2016
0 parents commit 791f367
Show file tree
Hide file tree
Showing 169 changed files with 41,906 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[run]
branch = True
omit =
kscore/vendored/*

[report]
exclude_lines =
raise NotImplementedError.*
include =
kscore/*
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
language: python
python:
- "2.6"
- "2.7"
- "3.3"
- "3.4"
- "3.5"
sudo: false
before_install:
- if [ "$TRAVIS_PULL_REQUEST" != "false" ] && [ "$TRAVIS_BRANCH" == "master" ]; then
echo "No pull requests can be sent to the master branch" 1>&2;
exit 1;
fi
- pip install codecov
install:
- python scripts/ci/install
script: python scripts/ci/run-tests
after_success:
- rm tests/coverage.xml && mv tests/.coverage ./ && codecov
18 changes: 18 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
=========
CHANGELOG
=========

1.0.1a0
======

* feature:``iam``: Update iam client to latest version

1.0.1a1
======

* feature:fix tests

1.0.2
======

* feature:``examples``: Add examples with ``kec``
12 changes: 12 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Copyright 2012-2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"). You
may not use this file except in compliance with the License. A copy of
the License is located at

http://aws.amazon.com/apache2.0/

or in the "license" file accompanying this file. This file 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.
8 changes: 8 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
include README.rst
include LICENSE.txt
include requirements.txt
include kscore/vendored/requests/cacert.pem
recursive-include kscore/data *.json *.yaml
graft docs
prune docs/build
graft tests
83 changes: 83 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
Botocore includes a vendorized copy of the requests python library to ease installation.

Requests License
================

Copyright 2013 Kenneth Reitz

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.


The requests library also includes some vendorized python libraries to ease installation.

Urllib3 License
===============

This is the MIT license: http://www.opensource.org/licenses/mit-license.php

Copyright 2008-2011 Andrey Petrov and contributors (see CONTRIBUTORS.txt),
Modifications copyright 2012 Kenneth Reitz.

Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

Chardet License
===============

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA



Bundle of CA Root Certificates
==============================

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301
165 changes: 165 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
kscore
========

A low-level interface to a growing number of KSC Web Services. Reference from botocore.

`Documentation <http://www.ksyun.com/doc/search?word=API>`__

----------------
安装
----------------

+ pip 安装
+ pip install kscore
+ github 安装
+ https://github.com/liuyichen/kscore 下载
+ python setup.py install

----------------
Credentials 配置
----------------

+ 参考examples内示例

+ 配置文件: ``.kscore.cfg``

+ 所在位置: '/etc/kscore.cfg' 或 './.kscore.cfg' 或 'C:\\kscore.cfg'

+ 注意: 使用相对路径时,需与运行目录保持一致。
::

[Credentials]
ks_access_key_id=AKLTyW1V6ZWET7aIvdCeIH1cwQ
ks_secret_access_key=OEoTK4IgEBIq3rlFsbpcNDs87w513D6aOwdXxP6QHuvWlonSRYeKQyTzqc1XkUvpuQ==


+ 或运行时配置
+ session.set_credentials(access_key_id, secret_access_key, session_token=None)

----------------
Service 使用
----------------

+ create_client 方法
| service_name 服务,必须参数,例 iam
| region_name=None 大区,必须参数,全局服务可以为None
| api_version=None API版本,默认使用最近版本
| use_ssl=True 是否使用HTTPS,如接口支持情况下,优先使用
| verify=None 是否验证SSL证书
| endpoint_url=None
| ks_access_key_id=None
| ks_secret_access_key=None
| ks_session_token=None

+ 已支持大区 region_name 参考data/endpoints.yaml
| cn-beijing-5 北京5区
| cn-beijing-6 北京6区
| cn-shanghai-2 上海2区
+ IAM

::

from kscore.session import get_session

if __name__ == "__main__":
s = get_session()

client = s.create_client("iam", use_ssl=False)

users = client.list_users()

+ KEC

::

from kscore.session import get_session

if __name__ == "__main__":
s = get_session()

client = s.create_client("kec", "cn-beijing-6", use_ssl=False)

client.[your method]()

+ MONITOR

::

from kscore.session import get_session

if __name__ == "__main__":
s = get_session()

client = s.create_client("monitor", "cn-beijing-5", use_ssl=True)

m=client.get_metric_statistics(InstanceID="6f582c78-5d49-438e-bf2d-db4345daf503",Namespace="eip",MetricName="qos.bps_in",StartTime="2016-08-16T17:09:00Z",EndTime="2016-08-16T23:56:00Z",Period="600",Aggregate="Average")

print json.dumps(m,sort_keys=True,indent=4)

+ 更多

::

欢迎补充

------------------
Data 更多服务配置
------------------
+ 参考 https://github.com/liuyichen/kscore/issues
+ ENDPOINT 配置
+ data\\endpoints.yaml

::

version: n
partitions:
- partition:
...
# REGION 列表
regions:
...
# 服务列表
- service:
...

+ SERVICE 配置
+ data\\[service]\\[version]\\service-2.yaml

::

version: n
# API 配置
metadata:
...
# 操作方法
operations:
...
# 请求及返回的结构体
shapes:
...

+ 请参考IAM,KEC等配置

配置文件变更后请重新安装 python setup.py install


--------------------
TESTS 测试
--------------------

+ 基本接口测试

\tests\acceptance> behave

+ 各服务测试用例

\tests>nosetests --with-xunit --cover-erase --with-coverage --cover-package kscore --cover-xml -v integration

--------------------
Contact Information
--------------------

群 号: 367780788
邮 箱: [email protected]
3 changes: 3 additions & 0 deletions examples/.kscore.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Credentials]
ks_access_key_id =
ks_secret_access_key =
2 changes: 2 additions & 0 deletions examples/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# -*- encoding: utf-8 -*-
from __future__ import unicode_literals
16 changes: 16 additions & 0 deletions examples/iam.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- encoding:utf-8 -*-

from kscore.session import get_session

if __name__ == "__main__":
s = get_session()

client = s.create_client("iam", use_ssl=False)

users = client.list_users()

client.create_user(UserName="test22", RealName=u"刘一辰")

client.update_user(UserName="test22",)

client.delete_user(UserName="test22")
16 changes: 16 additions & 0 deletions examples/kec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- encoding:utf-8 -*-

from kscore.session import get_session

if __name__ == "__main__":
s = get_session()

client = s.create_client("kec", "cn-beijing-6", use_ssl=True)

print client.describe_instances()

# client.create_user(UserName="test22", RealName=u"刘一辰")

# client.update_user(UserName="test22",)

# client.delete_user(UserName="test22")
20 changes: 20 additions & 0 deletions examples/kog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- encoding:utf-8 -*-

from kscore.session import get_session

if __name__ == "__main__":
s = get_session()

client = s.create_client("kog", use_ssl=True)

projects = client.get_project_list()

project = client.add_project(name='123123', comment='123123')

project.update(name="bcd")

client.edit_project(**project)

client.delete_project(id=project['id'])

assert projects == client.get_project_list()
Loading

0 comments on commit 791f367

Please sign in to comment.