qingcloud-cli 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +47 -0
- data/README.md +131 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/qingcloud +8 -0
- data/bin/setup +8 -0
- data/lib/qingcloud/api/base.rb +47 -0
- data/lib/qingcloud/api/client.rb +13 -0
- data/lib/qingcloud/api/iaas.rb +19 -0
- data/lib/qingcloud/cli.rb +12 -0
- data/lib/qingcloud/cli/app.rb +137 -0
- data/lib/qingcloud/cli/version.rb +5 -0
- data/qingcloud-cli.gemspec +41 -0
- metadata +147 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 5a5c5c869fa08ebc117e77585c6a85e5fa2f3dd9
|
|
4
|
+
data.tar.gz: 8895472e51f8385035a343d45ed21b144fc67c3d
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: f75e2aaf24318aef2b54cdb4a0326751bc8bea06d5dd7b982a71e9e2eb7f124d90057761cb13b5cd4501e3a2b9396d9c868a595cb7c2531d8c0e5ffd3fb05c74
|
|
7
|
+
data.tar.gz: f39651526065ffec3aace72b35603ad3c1cc241435321e8108e74f18366de903f5c24b99edeaee0fc05be98373784e12c1a57b672361d3dc15d863ea60a06661
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at jiewuzhan@qq.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
qingcloud-cli (0.1.0)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
awesome_print (1.8.0)
|
|
10
|
+
diff-lcs (1.3)
|
|
11
|
+
httparty (0.16.3)
|
|
12
|
+
mime-types (~> 3.0)
|
|
13
|
+
multi_xml (>= 0.5.2)
|
|
14
|
+
mime-types (3.2.2)
|
|
15
|
+
mime-types-data (~> 3.2015)
|
|
16
|
+
mime-types-data (3.2018.0812)
|
|
17
|
+
multi_xml (0.6.0)
|
|
18
|
+
optimist (3.0.0)
|
|
19
|
+
rake (10.5.0)
|
|
20
|
+
rspec (3.7.0)
|
|
21
|
+
rspec-core (~> 3.7.0)
|
|
22
|
+
rspec-expectations (~> 3.7.0)
|
|
23
|
+
rspec-mocks (~> 3.7.0)
|
|
24
|
+
rspec-core (3.7.1)
|
|
25
|
+
rspec-support (~> 3.7.0)
|
|
26
|
+
rspec-expectations (3.7.0)
|
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
28
|
+
rspec-support (~> 3.7.0)
|
|
29
|
+
rspec-mocks (3.7.0)
|
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
31
|
+
rspec-support (~> 3.7.0)
|
|
32
|
+
rspec-support (3.7.1)
|
|
33
|
+
|
|
34
|
+
PLATFORMS
|
|
35
|
+
ruby
|
|
36
|
+
|
|
37
|
+
DEPENDENCIES
|
|
38
|
+
awesome_print
|
|
39
|
+
bundler (~> 1.16)
|
|
40
|
+
httparty
|
|
41
|
+
optimist
|
|
42
|
+
qingcloud-cli!
|
|
43
|
+
rake (~> 10.0)
|
|
44
|
+
rspec (~> 3.0)
|
|
45
|
+
|
|
46
|
+
BUNDLED WITH
|
|
47
|
+
1.16.2
|
data/README.md
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# Qingcloud::Cli
|
|
2
|
+
|
|
3
|
+
Command line tool for QingCloud
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
This tool(gem) is not ready, you can only install it from source code. It'll be published to [RubyGems](https://rubygems.org) when it's ok.
|
|
8
|
+
|
|
9
|
+
Get Code from Github:
|
|
10
|
+
|
|
11
|
+
$ git clone https://github.com/jiewuzhan/qingcloud-cli.git
|
|
12
|
+
|
|
13
|
+
Build and Install with Bundle:
|
|
14
|
+
|
|
15
|
+
$ cd qingcloud-cli
|
|
16
|
+
$ bundle install
|
|
17
|
+
$ bundle exec rake install
|
|
18
|
+
|
|
19
|
+
##### Setup your API keys
|
|
20
|
+
Please go to [QingCloud Console](https://console.qingcloud.com/access_keys/) to create a pair of QingCloud API keys.
|
|
21
|
+
And edit your configure file in "~/.qingcloud/config.yml".
|
|
22
|
+
|
|
23
|
+
```yaml
|
|
24
|
+
qy_access_key_id: 'OFZKUIJWKYEVGGEKALTP'
|
|
25
|
+
qy_secret_access_key: '51mHFcuSSRSirpsWzONFJqg2ZRIZLzQRlFRoigt3'
|
|
26
|
+
zone: 'pek3'
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Uninstall
|
|
30
|
+
|
|
31
|
+
$ gem uninstall qingcloud-cli
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
Usage:
|
|
37
|
+
qingcloud [options] [<command> [suboptions]]
|
|
38
|
+
|
|
39
|
+
Options:
|
|
40
|
+
-v, --version Print version and exit
|
|
41
|
+
-h, --help Show help message
|
|
42
|
+
|
|
43
|
+
Commands:
|
|
44
|
+
describe-instances Get the list of host computers.
|
|
45
|
+
run-instances Create host computers.
|
|
46
|
+
terminate-instances Destroy host computers.
|
|
47
|
+
|
|
48
|
+
## Getting Started
|
|
49
|
+
|
|
50
|
+
After install this command line tool, just bring up your terminal and give it a try.
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
$ qingcloud --help
|
|
54
|
+
Usage:
|
|
55
|
+
qingcloud [options] [<command> [suboptions]]
|
|
56
|
+
|
|
57
|
+
Options:
|
|
58
|
+
-v, --version Print version and exit
|
|
59
|
+
-h, --help Show help message
|
|
60
|
+
|
|
61
|
+
Commands:
|
|
62
|
+
describe-instances Get the list of host computers.
|
|
63
|
+
run-instances Create host computers.
|
|
64
|
+
terminate-instances Destroy host computers.
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
$ qingcloud describe-instances --help
|
|
69
|
+
Usage: qingcloud describe-instances [options]
|
|
70
|
+
|
|
71
|
+
Specific options:
|
|
72
|
+
-i, --instances-N=<s> 主机ID
|
|
73
|
+
-m, --image-id-N=<s> 一个或多个映像ID
|
|
74
|
+
-n, --instance-type-N=<s> 主机配置类型
|
|
75
|
+
-s, --instance-class=<i> 主机性能类型: 性能型:0, 超高性能型:1
|
|
76
|
+
-t, --status-N=<s> 主机状态: pending, running, stopped, suspended, terminated, ceased
|
|
77
|
+
-e, --search-word=<s> 搜索关键词, 支持主机ID, 主机名称
|
|
78
|
+
-a, --tags-N=<s> 按照标签ID过滤, 只返回已绑定某标签的资源
|
|
79
|
+
-d, --dedicated-host-group-id=<s> 按照专属宿主机组过滤
|
|
80
|
+
-c, --dedicated-host-id=<s> 按照专属宿主机组中某个宿主机过滤
|
|
81
|
+
-o, --owner=<s> 按照用户账户过滤, 只返回指定账户的资源
|
|
82
|
+
-v, --verbose=<i> 是否返回冗长的信息, 若为1, 则返回主机相关其他资源的详细数据。
|
|
83
|
+
-f, --offset=<i> 数据偏移量, 默认为0 (default: 0)
|
|
84
|
+
-l, --limit=<i> 返回数据长度,默认为20,最大100 (default: 20)
|
|
85
|
+
-z, --zone=<s> 区域ID,注意要小写
|
|
86
|
+
-h, --help Show this message
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
#### Command Suggestions
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
$ qingcloud des # press enter now, and you will get subcommand suggestions
|
|
93
|
+
qingcloud describe-instances
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Example
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
# Describe Instances
|
|
100
|
+
|
|
101
|
+
$ qingcloud describe-instances -z ap1
|
|
102
|
+
{
|
|
103
|
+
"action": "DescribeInstancesResponse",
|
|
104
|
+
"instance_set": [
|
|
105
|
+
|
|
106
|
+
],
|
|
107
|
+
"total_count": 0,
|
|
108
|
+
"ret_code": 0
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
# Run Instances
|
|
112
|
+
|
|
113
|
+
$ qingcloud run-instances -m centos7x64b -l keypair -k keypair-id -C 1 -M 1024 -z ap1
|
|
114
|
+
{
|
|
115
|
+
"action": "RunInstancesResponse",
|
|
116
|
+
"instances": [
|
|
117
|
+
"instance-id"
|
|
118
|
+
],
|
|
119
|
+
"job_id": "job-id",
|
|
120
|
+
"ret_code": 0
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
## Contributing
|
|
125
|
+
|
|
126
|
+
1. Fork it ( https://github.com/jiewuzhan/qingcloud-cli/fork )
|
|
127
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
128
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
129
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
130
|
+
5. Create a new Pull Request
|
|
131
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "qingcloud/cli"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/qingcloud
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "qingcloud/cli"
|
|
5
|
+
|
|
6
|
+
config_map = YAML.load_file("#{ENV['HOME']}/.qingcloud/config.yml")
|
|
7
|
+
client = Qingcloud::Api::Client.new(config_map['qy_access_key_id'], config_map['qy_secret_access_key'], config_map['zone'])
|
|
8
|
+
Qingcloud::Cli::App.new(client, ARGV).call!
|
data/bin/setup
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
module Qingcloud
|
|
2
|
+
module Api
|
|
3
|
+
class Base
|
|
4
|
+
include HTTParty
|
|
5
|
+
|
|
6
|
+
base_uri "https://api.qingcloud.com"
|
|
7
|
+
|
|
8
|
+
attr_accessor :client, :action, :options, :now
|
|
9
|
+
|
|
10
|
+
def initialize(client, action, options={}, now=nil)
|
|
11
|
+
@client = client
|
|
12
|
+
@action = action
|
|
13
|
+
@options = options
|
|
14
|
+
@now = now || Time.now.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
protected
|
|
18
|
+
def base_parameters
|
|
19
|
+
{
|
|
20
|
+
access_key_id: client.access_key_id, zone: client.zone, action: action,
|
|
21
|
+
signature_version: 1, signature_method: "HmacSHA256", version: 1,
|
|
22
|
+
time_stamp: now
|
|
23
|
+
}
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def request_body
|
|
27
|
+
base_parameters.merge(options).sort.map { |key, value|
|
|
28
|
+
if value.is_a? Array
|
|
29
|
+
if key.to_s.include? '_N'
|
|
30
|
+
value.map { |v|
|
|
31
|
+
"#{CGI.escape key.to_s.gsub('_N', '').to_s}.#{value.index(v)+1}=#{CGI.escape v.to_s}"
|
|
32
|
+
}.join('&')
|
|
33
|
+
end
|
|
34
|
+
else
|
|
35
|
+
"#{CGI.escape key.to_s}=#{CGI.escape value.to_s}"
|
|
36
|
+
end
|
|
37
|
+
}.join('&')
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def sign_by(str)
|
|
41
|
+
digest = OpenSSL::Digest.new('sha256')
|
|
42
|
+
hmac = OpenSSL::HMAC.digest(digest, client.secret_access_key, "#{str}#{request_body}")
|
|
43
|
+
signature = Base64.encode64(hmac).strip
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Qingcloud
|
|
2
|
+
module Api
|
|
3
|
+
class Client
|
|
4
|
+
attr_accessor :access_key_id, :secret_access_key, :zone
|
|
5
|
+
|
|
6
|
+
def initialize(access_key_id, secret_access_key, zone)
|
|
7
|
+
@access_key_id = access_key_id
|
|
8
|
+
@secret_access_key = secret_access_key
|
|
9
|
+
@zone = zone
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Qingcloud
|
|
2
|
+
module Api
|
|
3
|
+
class Iaas < Base
|
|
4
|
+
def invoke
|
|
5
|
+
_full_request_body = "#{request_body}&signature=#{CGI.escape(sign)}"
|
|
6
|
+
|
|
7
|
+
puts "Request: "
|
|
8
|
+
ap _full_request_body.split('&').map { |a| a.split('=') }.to_h
|
|
9
|
+
|
|
10
|
+
self.class.get("/iaas/?#{_full_request_body}")
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def sign
|
|
14
|
+
sign_by("GET\n/iaas/\n")
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require "optimist"
|
|
2
|
+
require "httparty"
|
|
3
|
+
require "awesome_print"
|
|
4
|
+
require "openssl"
|
|
5
|
+
require "base64"
|
|
6
|
+
|
|
7
|
+
require "qingcloud/cli/version"
|
|
8
|
+
require "qingcloud/cli/app"
|
|
9
|
+
|
|
10
|
+
require "qingcloud/api/client"
|
|
11
|
+
require "qingcloud/api/base"
|
|
12
|
+
require "qingcloud/api/iaas"
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
module Qingcloud
|
|
2
|
+
module Cli
|
|
3
|
+
class App
|
|
4
|
+
COMMAND_MAP = {
|
|
5
|
+
'describe-instances' => 'Get the list of host computers.',
|
|
6
|
+
'run-instances' => 'Create host computers.',
|
|
7
|
+
'terminate-instances' => 'Destroy host computers.'
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
def initialize(client, args=[])
|
|
11
|
+
@client = client
|
|
12
|
+
|
|
13
|
+
@mainopts = Optimist::options do
|
|
14
|
+
synopsis "A Command Line Interface for QingCloud API."
|
|
15
|
+
version "qingcloud v#{Qingcloud::Cli::VERSION}"
|
|
16
|
+
|
|
17
|
+
banner "Usage:"
|
|
18
|
+
banner " qingcloud [options] [<command> [suboptions]]\n \n"
|
|
19
|
+
banner "Options:"
|
|
20
|
+
opt :version, "Print version and exit"
|
|
21
|
+
opt :help, "Show help message"
|
|
22
|
+
stop_on COMMAND_MAP.keys
|
|
23
|
+
stop_on_unknown
|
|
24
|
+
banner "\nCommands:"
|
|
25
|
+
COMMAND_MAP.each { |cmd, desc| banner format(" %-20s %s", cmd, desc) }
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
@command = args.shift
|
|
29
|
+
@subopts = nil
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def call!
|
|
33
|
+
command_array = COMMAND_MAP.keys
|
|
34
|
+
|
|
35
|
+
if @command.nil?
|
|
36
|
+
puts "Error: must with options or command."
|
|
37
|
+
puts "Try --help for help."
|
|
38
|
+
return
|
|
39
|
+
elsif command_array.include?(@command)
|
|
40
|
+
@subopts = self.send("opt_#{@command.gsub("-", "_")}")
|
|
41
|
+
|
|
42
|
+
ret =
|
|
43
|
+
Qingcloud::Api::Iaas.new(
|
|
44
|
+
@client,
|
|
45
|
+
@command.split('-').map(&:capitalize).join,
|
|
46
|
+
@subopts.select { |k, v| !k.to_s.end_with?("_given") && (v.is_a?(Array) ? !v.empty? : v) }
|
|
47
|
+
).invoke
|
|
48
|
+
|
|
49
|
+
puts "\n\nResponse: "
|
|
50
|
+
ap ret.parsed_response
|
|
51
|
+
elsif (sug = command_array.select { |x| x.start_with? @command }.compact) && !sug.empty?
|
|
52
|
+
puts sug
|
|
53
|
+
return
|
|
54
|
+
else
|
|
55
|
+
puts "Error: unknown command #{@command}."
|
|
56
|
+
puts "Try --help for help."
|
|
57
|
+
return
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
protected
|
|
62
|
+
def opt_run_instances
|
|
63
|
+
command = @command
|
|
64
|
+
Optimist::options do
|
|
65
|
+
banner "Usage: qingcloud #{command} [options]\n \n"
|
|
66
|
+
banner "Specific options:"
|
|
67
|
+
opt :image_id, "映像ID,此映像将作为主机的模板。可传青云提供的映像ID,或自己创建的映像ID", required: true, type: :string
|
|
68
|
+
opt :instance_type, "主机类型", type: :string
|
|
69
|
+
opt :cpu, "CPU core,有效值为: 1, 2, 4, 8, 16", type: :integer
|
|
70
|
+
opt :memory, "内存,有效值为: 1024, 2048, 4096, 6144, 8192, 12288, 16384, 24576, 32768", type: :integer
|
|
71
|
+
opt :os_disk_size, "系统盘大小,单位GB。Linux操作系统的有效值为:20-100,默认值为:20.Windows操作系统的有效值为:50-100,默认值为:50", default: 50
|
|
72
|
+
opt :count, "创建主机的数量,默认是1", type: :integer, default: 1
|
|
73
|
+
opt :instance_name, "主机名称", type: :string
|
|
74
|
+
opt :login_mode, "指定登录方式。当为 linux 主机时,有效值为 keypair 和 passwd; 当为 windows 主机时,只能选用 passwd 登录方式。" +
|
|
75
|
+
"当登录方式为 keypair 时,需要指定 login_keypair 参数;当登录方式为 passwd 时,需要指定 login_passwd 参数", required: true, type: :string
|
|
76
|
+
opt :login_keypair, "登录密钥ID。", type: :string
|
|
77
|
+
opt :login_passwd, "登录密码", type: :string
|
|
78
|
+
opt :vxnets_N, "主机要加入的私有网络ID,如果不传此参数,则表示不加入到任何网络。" +
|
|
79
|
+
"如果是自建的受管私有网络(不包括基础网络 vxnet-0 ),则可以在创建主机时指定内网IP, 这时参数值要改为 vxnet-id|ip-address ,如 vxnet-abcd123|192.168.1.2 。"
|
|
80
|
+
opt :security_group, "主机加载的防火墙ID,只有在 vxnets.n 包含基础网络(即:vxnet-0)时才需要提供。 若未提供,则默认加载缺省防火墙", type: :string, multi: true
|
|
81
|
+
opt :volumes_N, "主机创建后自动加载的硬盘ID,如果传此参数,则参数 count 必须为1 。", type: :string, multi: true
|
|
82
|
+
opt :hostname, "可指定主机的 hostname 。", type: :string
|
|
83
|
+
opt :need_newsid, "1: 生成新的SID,0: 不生成新的SID, 默认为0;只对Windows类型主机有效。", type: :integer
|
|
84
|
+
opt :instance_class, "主机性能类型: 性能型:0 ,超高性能型:1", type: :string
|
|
85
|
+
opt :cpu_model, "CPU 指令集, 有效值: Westmere, SandyBridge, IvyBridge, Haswell, Broadwell", type: :string
|
|
86
|
+
opt :cpu_topology, "CPU 拓扑结构: 插槽数, 核心数, 线程数; 插槽数 * 核心数 * 线程数 应等于您应选择的CPU数量。", type: :string
|
|
87
|
+
opt :gpu, "GPU 个数", type: :string
|
|
88
|
+
opt :nic_mqueue, "网卡多对列: 关闭(默认):0,开启:1", type: :integer
|
|
89
|
+
opt :need_userdata, "1: 使用 User Data 功能;0: 不使用 User Data 功能;默认为 0 。", type: :integer
|
|
90
|
+
opt :userdata_type, "User Data 类型,有效值:’plain’, ‘exec’ 或 ‘tar’。为 ‘plain’或’exec’ 时,使用一个 Base64 编码后的字符串;为 ‘tar’ 时,使用一个压缩包(种类为 zip,tar,tgz,tbz)。", type: :string
|
|
91
|
+
opt :userdata_value, "User Data 值。当类型为 ‘plain’ 时,为字符串的 Base64 编码值,长度限制 4K;当类型为 ‘tar’,为调用 UploadUserDataAttachment 返回的 attachment_id。", type: :string
|
|
92
|
+
opt :userdata_path, "User Data 和 MetaData 生成文件的存放路径。不输入或输入不合法时,为默认目录 /etc/qingcloud/userdata", type: :string
|
|
93
|
+
opt :userdata_file, "userdata_type 为 ‘exec’ 时,指定生成可执行文件的路径,默认为/etc/rc.local", type: :string
|
|
94
|
+
opt :target_user, "目标用户 ID ,可用于主账号为其子账号创建资源。", type: :string
|
|
95
|
+
opt :dedicated_host_group_id, "虚机创建到指定的专属宿主机组中", type: :string
|
|
96
|
+
opt :dedicated_host_id, "虚机创建到某专属宿主机组中指定的宿主机上", type: :string
|
|
97
|
+
opt :instance_group, "虚机创建加入到指定的主机组中", type: :string
|
|
98
|
+
opt :hypervisor, "hypervisor 类型,当前支持 kvm 和 bm, 默认是 kvm", type: :string
|
|
99
|
+
opt :zone, "区域ID,注意要小写", type: :string
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def opt_describe_instances
|
|
104
|
+
command = @command
|
|
105
|
+
Optimist::options do
|
|
106
|
+
banner "Usage: qingcloud #{command} [options]\n \n"
|
|
107
|
+
banner "Specific options:"
|
|
108
|
+
opt :instances_N, "主机ID", type: :string, multi: true
|
|
109
|
+
opt :image_id_N, "一个或多个映像ID", type: :string, multi: true
|
|
110
|
+
opt :instance_type_N, "主机配置类型", type: :string, multi: true
|
|
111
|
+
opt :instance_class, "主机性能类型: 性能型:0, 超高性能型:1", type: :integer
|
|
112
|
+
opt :status_N, "主机状态: pending, running, stopped, suspended, terminated, ceased", type: :string, multi: true
|
|
113
|
+
opt :search_word, "搜索关键词, 支持主机ID, 主机名称", type: :string
|
|
114
|
+
opt :tags_N, "按照标签ID过滤, 只返回已绑定某标签的资源", type: :string, multi: true
|
|
115
|
+
opt :dedicated_host_group_id, "按照专属宿主机组过滤", type: :string
|
|
116
|
+
opt :dedicated_host_id, "按照专属宿主机组中某个宿主机过滤", type: :string
|
|
117
|
+
opt :owner, "按照用户账户过滤, 只返回指定账户的资源", type: :string
|
|
118
|
+
opt :verbose, "是否返回冗长的信息, 若为1, 则返回主机相关其他资源的详细数据。", type: :integer
|
|
119
|
+
opt :offset, "数据偏移量, 默认为0", type: :integer, default: 0
|
|
120
|
+
opt :limit, "返回数据长度,默认为20,最大100", type: :integer, default: 20
|
|
121
|
+
opt :zone, "区域ID,注意要小写", type: :string
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def opt_terminate_instances
|
|
126
|
+
command = @command
|
|
127
|
+
Optimist::options do
|
|
128
|
+
banner "Usage: qingcloud #{command} [options]\n \n"
|
|
129
|
+
banner "Specific options:"
|
|
130
|
+
opt :instances_N, "一个或多个主机ID", required: true, type: :string, multi: true
|
|
131
|
+
opt :direct_cease, "是否直接彻底销毁主机,如果指定 “1” 则不会进入回收站直接销毁,默认是 “0”", default: 0
|
|
132
|
+
opt :zone, "区域ID,注意要小写", type: :string
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "qingcloud/cli/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "qingcloud-cli"
|
|
8
|
+
spec.version = Qingcloud::Cli::VERSION
|
|
9
|
+
spec.authors = ["maojie"]
|
|
10
|
+
spec.email = ["jiewuzhan@qq.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{Command Line Interface for QingCloud.}
|
|
13
|
+
spec.description = %q{Command Line Interface for QingCloud.}
|
|
14
|
+
spec.homepage = "https://github.com/jiewuzhan/qingcloud-cli"
|
|
15
|
+
|
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
|
18
|
+
if spec.respond_to?(:metadata)
|
|
19
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
|
20
|
+
else
|
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
|
22
|
+
"public gem pushes."
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Specify which files should be added to the gem when it is released.
|
|
26
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
27
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
28
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
29
|
+
end
|
|
30
|
+
spec.bindir = "bin"
|
|
31
|
+
spec.executables = %w(qingcloud)
|
|
32
|
+
spec.require_paths = %w(lib)
|
|
33
|
+
|
|
34
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
|
35
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
36
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
37
|
+
|
|
38
|
+
spec.add_development_dependency "optimist"
|
|
39
|
+
spec.add_development_dependency "httparty"
|
|
40
|
+
spec.add_development_dependency "awesome_print"
|
|
41
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: qingcloud-cli
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- maojie
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-01-23 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.16'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.16'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: optimist
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: httparty
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: awesome_print
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ">="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
97
|
+
description: Command Line Interface for QingCloud.
|
|
98
|
+
email:
|
|
99
|
+
- jiewuzhan@qq.com
|
|
100
|
+
executables:
|
|
101
|
+
- qingcloud
|
|
102
|
+
extensions: []
|
|
103
|
+
extra_rdoc_files: []
|
|
104
|
+
files:
|
|
105
|
+
- ".gitignore"
|
|
106
|
+
- ".rspec"
|
|
107
|
+
- ".travis.yml"
|
|
108
|
+
- CODE_OF_CONDUCT.md
|
|
109
|
+
- Gemfile
|
|
110
|
+
- Gemfile.lock
|
|
111
|
+
- README.md
|
|
112
|
+
- Rakefile
|
|
113
|
+
- bin/console
|
|
114
|
+
- bin/qingcloud
|
|
115
|
+
- bin/setup
|
|
116
|
+
- lib/qingcloud/api/base.rb
|
|
117
|
+
- lib/qingcloud/api/client.rb
|
|
118
|
+
- lib/qingcloud/api/iaas.rb
|
|
119
|
+
- lib/qingcloud/cli.rb
|
|
120
|
+
- lib/qingcloud/cli/app.rb
|
|
121
|
+
- lib/qingcloud/cli/version.rb
|
|
122
|
+
- qingcloud-cli.gemspec
|
|
123
|
+
homepage: https://github.com/jiewuzhan/qingcloud-cli
|
|
124
|
+
licenses: []
|
|
125
|
+
metadata:
|
|
126
|
+
allowed_push_host: https://rubygems.org
|
|
127
|
+
post_install_message:
|
|
128
|
+
rdoc_options: []
|
|
129
|
+
require_paths:
|
|
130
|
+
- lib
|
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
132
|
+
requirements:
|
|
133
|
+
- - ">="
|
|
134
|
+
- !ruby/object:Gem::Version
|
|
135
|
+
version: '0'
|
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
|
+
requirements:
|
|
138
|
+
- - ">="
|
|
139
|
+
- !ruby/object:Gem::Version
|
|
140
|
+
version: '0'
|
|
141
|
+
requirements: []
|
|
142
|
+
rubyforge_project:
|
|
143
|
+
rubygems_version: 2.6.8
|
|
144
|
+
signing_key:
|
|
145
|
+
specification_version: 4
|
|
146
|
+
summary: Command Line Interface for QingCloud.
|
|
147
|
+
test_files: []
|