conoha 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +123 -0
- data/Rakefile +1 -0
- data/bin/conoha +56 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/conoha.gemspec +24 -0
- data/lib/conoha.rb +316 -0
- data/lib/conoha/version.rb +3 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 66cb1ab851cd778664afc2a1e5e6c62c3641f4b1
|
4
|
+
data.tar.gz: 81fb81e31e3434071b6906fbb9b0e9255bbbe47e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ee719e3df484973d370924ae0096a9981da91403b2b395375fd9c90f32408bd44e52283d6543508f373d77fe2fbb421c376dd4949d0e3e8b717f60c5061a0df3
|
7
|
+
data.tar.gz: 0b806a6eb95b9323c2e7f056d3b78ae2ab7d2654d0c3a07af6801c4d89ad73878e3c4fd3aa30c6cb007cd3370eeeec1099f3fafd6f4ccea8e09790827d7bfd5d
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 ka
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
# ConoHa VPS CLI Tool
|
2
|
+
|
3
|
+
CLI tool for management ConoHa VPS.
|
4
|
+
|
5
|
+
[ConoHa VPS](https://www.conoha.jp/en)
|
6
|
+
|
7
|
+
[API Document](https://www.conoha.jp/conoben/archives/10025)
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'conoha'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install conoha
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Create `username`, `password` and `tenant_id` values with the [Web control panel](https://manage.conoha.jp/Service/) at first.
|
28
|
+
|
29
|
+
Register a public key for SSH connection at least one. Set its key label name to `public_key` value.
|
30
|
+
|
31
|
+
Create `~/.conoha-config.json` like following:
|
32
|
+
|
33
|
+
```.conoha-config.json:json
|
34
|
+
{
|
35
|
+
"username": "gncu123456789",
|
36
|
+
"password": "your-password",
|
37
|
+
"tenant_id": "0123456789abcdef",
|
38
|
+
"public_key": "your-registered-public-key-name"
|
39
|
+
}
|
40
|
+
```
|
41
|
+
|
42
|
+
You should run `chmod 600 ~/.conoha-config.json`.
|
43
|
+
|
44
|
+
```
|
45
|
+
# Authenticate after preparation ~/.conoha-config.json
|
46
|
+
conoha authenticate
|
47
|
+
|
48
|
+
# Create a VPS
|
49
|
+
conoha create ubuntu g-1gb
|
50
|
+
# Remember the UUID of created VPS
|
51
|
+
|
52
|
+
# Create VPSs with other options
|
53
|
+
conoha create centos71 g-2gb
|
54
|
+
conoha create arch g-4gb
|
55
|
+
|
56
|
+
# You can check VPS UUIDs
|
57
|
+
conoha vpslist
|
58
|
+
|
59
|
+
# Check VPS IPv4 address
|
60
|
+
conoha ipaddress 01234567-89ab-cdef-0123-456789abcdef
|
61
|
+
|
62
|
+
# Shutdown VPS
|
63
|
+
conoha shutdown 01234567-89ab-cdef-0123-456789abcdef
|
64
|
+
|
65
|
+
# Boot VPS
|
66
|
+
conoha boot 01234567-89ab-cdef-0123-456789abcdef
|
67
|
+
|
68
|
+
# Delte VPS
|
69
|
+
conoha delete 01234567-89ab-cdef-0123-456789abcdef
|
70
|
+
|
71
|
+
# Create image with a name
|
72
|
+
conoha imagecreate 01234567-89ab-cdef-0123-456789abcdef ubuntu-backup
|
73
|
+
|
74
|
+
# Check image UUIDs
|
75
|
+
conoha imagelist
|
76
|
+
|
77
|
+
# Delete image
|
78
|
+
conoha imagedelete fedcba98-7654-3210-fedc-ba9876543210
|
79
|
+
|
80
|
+
# Create a VPS from a saved image
|
81
|
+
conoha createfromimage fedcba98-7654-3210-fedc-ba9876543210 g-1gb
|
82
|
+
```
|
83
|
+
|
84
|
+
## Development
|
85
|
+
|
86
|
+
<del>
|
87
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
88
|
+
|
89
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
90
|
+
</del>
|
91
|
+
|
92
|
+
## Contributing
|
93
|
+
|
94
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/kaosf/conoha.
|
95
|
+
|
96
|
+
## TODO
|
97
|
+
|
98
|
+
### Features
|
99
|
+
|
100
|
+
- [x] authenticate
|
101
|
+
- [x] create vps
|
102
|
+
- [x] show vps list
|
103
|
+
- [x] check ip address
|
104
|
+
- [x] delete vps
|
105
|
+
- [x] boot vps
|
106
|
+
- [x] shutdown vps
|
107
|
+
- [x] create image
|
108
|
+
- [x] create vps from image
|
109
|
+
- [x] show image list
|
110
|
+
- [x] delete image
|
111
|
+
- [ ] public keys
|
112
|
+
- [x] make as a gem
|
113
|
+
|
114
|
+
### Code
|
115
|
+
|
116
|
+
- [ ] DRY HTTP codes
|
117
|
+
- [ ] test (but, how and what should I write?)
|
118
|
+
|
119
|
+
## License
|
120
|
+
|
121
|
+
[MIT](http://opensource.org/licenses/MIT)
|
122
|
+
|
123
|
+
Copyright (C) 2015 ka
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/conoha
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# vim: filetype=ruby
|
3
|
+
|
4
|
+
require 'conoha'
|
5
|
+
require 'pp'
|
6
|
+
|
7
|
+
subcommand = ARGV.shift
|
8
|
+
|
9
|
+
Conoha.init!
|
10
|
+
|
11
|
+
def server_id(server_id_or_index)
|
12
|
+
if server_id_or_index.length == '01234567-89ab-cdef-0123-456789abcdef'.length
|
13
|
+
server_id_or_index
|
14
|
+
else
|
15
|
+
Conoha.vps_list[server_id_or_index.to_i]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
case subcommand
|
20
|
+
when 'authenticate'
|
21
|
+
Conoha.authenticate!
|
22
|
+
puts 'Succeeded!'
|
23
|
+
when 'vpslist'
|
24
|
+
pp Conoha.vps_list
|
25
|
+
when 'ipaddress'
|
26
|
+
exit 1 if ARGV.size != 1
|
27
|
+
pp Conoha.ip_address_of server_id(ARGV.first)
|
28
|
+
when 'create'
|
29
|
+
pp Conoha.create *ARGV
|
30
|
+
when 'delete'
|
31
|
+
exit 1 if ARGV.size != 1
|
32
|
+
puts Conoha.delete server_id(ARGV.first)
|
33
|
+
when 'boot'
|
34
|
+
exit 1 if ARGV.size != 1
|
35
|
+
puts Conoha.boot server_id(ARGV.first)
|
36
|
+
when 'shutdown'
|
37
|
+
exit 1 if ARGV.size != 1
|
38
|
+
puts Conoha.shutdown server_id(ARGV.first)
|
39
|
+
when 'imagelist'
|
40
|
+
pp Conoha.images
|
41
|
+
when 'imagecreate'
|
42
|
+
exit 1 if ARGV.size != 2
|
43
|
+
name = ARGV[1]
|
44
|
+
puts Conoha.create_image server_id(ARGV[0]), name
|
45
|
+
when 'imagedelete'
|
46
|
+
exit 1 if ARGV.size != 1
|
47
|
+
image_ref = ARGV.first
|
48
|
+
puts Conoha.delete_image image_ref
|
49
|
+
when 'createfromimage'
|
50
|
+
exit 1 if ARGV.size != 2
|
51
|
+
image_ref = ARGV[0]
|
52
|
+
ram = ARGV[1]
|
53
|
+
puts Conoha.create_from_image image_ref, ram
|
54
|
+
else
|
55
|
+
STDERR.puts 'Error'
|
56
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "conoha"
|
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
|
data/bin/setup
ADDED
data/conoha.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'conoha/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "conoha"
|
8
|
+
spec.version = ConohaVersion::ITSELF
|
9
|
+
spec.authors = ["ka"]
|
10
|
+
spec.email = ["ka.kaosf@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{ConoHa VPS CLI Tool}
|
13
|
+
spec.description = %q{ConoHa VPS CLI Tool}
|
14
|
+
spec.homepage = "https://github.com/kaosf/conoha"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
end
|
data/lib/conoha.rb
ADDED
@@ -0,0 +1,316 @@
|
|
1
|
+
require "conoha/version"
|
2
|
+
|
3
|
+
require 'net/https'
|
4
|
+
require 'uri'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
class Conoha
|
8
|
+
def self.init!
|
9
|
+
load_config!
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.authenticate!
|
13
|
+
#uri = URI.parse 'https://identity.tyo1.conoha.io/v2.0/tokens'
|
14
|
+
#https = Net::HTTP.new(uri.host, uri.port)
|
15
|
+
#https.use_ssl = true
|
16
|
+
#req = Net::HTTP::Post.new(uri.request_uri)
|
17
|
+
#req['Content-Type'] = 'application/json'
|
18
|
+
#payload = {
|
19
|
+
# auth: {
|
20
|
+
# passwordCredentials: {
|
21
|
+
# username: $USERNAME,
|
22
|
+
# password: $PASSWORD
|
23
|
+
# },
|
24
|
+
# tenant_id: $TENANT_ID
|
25
|
+
# }
|
26
|
+
#}.to_json
|
27
|
+
#req.body = payload
|
28
|
+
#res = https.request(req)
|
29
|
+
|
30
|
+
req_json = JSON.generate({
|
31
|
+
auth: {
|
32
|
+
passwordCredentials: {
|
33
|
+
username: @@username,
|
34
|
+
password: @@password
|
35
|
+
},
|
36
|
+
tenantId: @@tenant_id
|
37
|
+
}
|
38
|
+
})
|
39
|
+
command = <<EOS
|
40
|
+
curl -X POST -H "Accept: application/json" \
|
41
|
+
-d '#{req_json}' \
|
42
|
+
https://identity.tyo1.conoha.io/v2.0/tokens 2> /dev/null
|
43
|
+
EOS
|
44
|
+
result = `#{command}`
|
45
|
+
|
46
|
+
#token = JSON.parse(res.body)["access"]["token"]["id"]
|
47
|
+
token = JSON.parse(result)["access"]["token"]["id"]
|
48
|
+
|
49
|
+
@@authtoken = token
|
50
|
+
save_config!
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.servers
|
54
|
+
uri = URI.parse "https://compute.tyo1.conoha.io/v2/#{tenant_id}/servers"
|
55
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
56
|
+
https.use_ssl = true
|
57
|
+
req = Net::HTTP::Get.new(uri.path)
|
58
|
+
req['Content-Type'] = 'application/json'
|
59
|
+
req['Accept'] = 'application/json'
|
60
|
+
req['X-Auth-Token'] = authtoken
|
61
|
+
res = https.request(req)
|
62
|
+
JSON.parse(res.body)["servers"]
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.vps_list
|
66
|
+
servers.map { |e| e["id"] }
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.create(os, ram)
|
70
|
+
uri = URI.parse "https://compute.tyo1.conoha.io/v2/#{tenant_id}/servers"
|
71
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
72
|
+
https.use_ssl = true
|
73
|
+
req = Net::HTTP::Post.new(uri.request_uri)
|
74
|
+
req['Content-Type'] = 'application/json'
|
75
|
+
req['Accept'] = 'application/json'
|
76
|
+
req['X-Auth-Token'] = authtoken
|
77
|
+
payload = {
|
78
|
+
server: {
|
79
|
+
adminPass: randstr,
|
80
|
+
imageRef: image_ref_from_os(os),
|
81
|
+
flavorRef: flavor_ref(ram),
|
82
|
+
key_name: public_key,
|
83
|
+
security_groups: [
|
84
|
+
{name: 'default'},
|
85
|
+
{name: 'gncs-ipv4-all'}
|
86
|
+
]
|
87
|
+
}
|
88
|
+
}.to_json
|
89
|
+
req.body = payload
|
90
|
+
res = https.request(req)
|
91
|
+
JSON.parse(res.body)["server"]["id"]
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.delete(server_id)
|
95
|
+
uri = URI.parse "https://compute.tyo1.conoha.io/v2/#{tenant_id}/servers/#{server_id}"
|
96
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
97
|
+
https.use_ssl = true
|
98
|
+
req = Net::HTTP::Delete.new(uri.request_uri)
|
99
|
+
req['Content-Type'] = 'application/json'
|
100
|
+
req['Accept'] = 'application/json'
|
101
|
+
req['X-Auth-Token'] = authtoken
|
102
|
+
res = https.request(req)
|
103
|
+
res.code == '204' ? 'OK' : 'Error'
|
104
|
+
end
|
105
|
+
|
106
|
+
def self.ip_address_of(server_id)
|
107
|
+
uri = URI.parse "https://compute.tyo1.conoha.io/v2/#{tenant_id}/servers/#{server_id}"
|
108
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
109
|
+
https.use_ssl = true
|
110
|
+
req = Net::HTTP::Get.new(uri.path)
|
111
|
+
req['Content-Type'] = 'application/json'
|
112
|
+
req['Accept'] = 'application/json'
|
113
|
+
req['X-Auth-Token'] = authtoken
|
114
|
+
res = https.request(req)
|
115
|
+
JSON.parse(res.body)["server"]["addresses"].values[0].map{ |e| e["addr"] }
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.boot(server_id)
|
119
|
+
uri = URI.parse "https://compute.tyo1.conoha.io/v2/#{tenant_id}/servers/#{server_id}/action"
|
120
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
121
|
+
https.use_ssl = true
|
122
|
+
req = Net::HTTP::Post.new(uri.request_uri)
|
123
|
+
req['Content-Type'] = 'application/json'
|
124
|
+
req['Accept'] = 'application/json'
|
125
|
+
req['X-Auth-Token'] = authtoken
|
126
|
+
req.body = {"os-start": nil}.to_json
|
127
|
+
res = https.request(req)
|
128
|
+
res.code == '202' ? 'OK' : 'Error'
|
129
|
+
end
|
130
|
+
|
131
|
+
def self.shutdown(server_id)
|
132
|
+
uri = URI.parse "https://compute.tyo1.conoha.io/v2/#{tenant_id}/servers/#{server_id}/action"
|
133
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
134
|
+
https.use_ssl = true
|
135
|
+
req = Net::HTTP::Post.new(uri.request_uri)
|
136
|
+
req['Content-Type'] = 'application/json'
|
137
|
+
req['Accept'] = 'application/json'
|
138
|
+
req['X-Auth-Token'] = authtoken
|
139
|
+
req.body = {"os-stop": nil}.to_json
|
140
|
+
res = https.request(req)
|
141
|
+
res.code == '202' ? 'OK' : 'Error'
|
142
|
+
end
|
143
|
+
|
144
|
+
def self.images
|
145
|
+
uri = URI.parse "https://compute.tyo1.conoha.io/v2/#{tenant_id}/images"
|
146
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
147
|
+
https.use_ssl = true
|
148
|
+
req = Net::HTTP::Get.new(uri.path)
|
149
|
+
req['Content-Type'] = 'application/json'
|
150
|
+
req['Accept'] = 'application/json'
|
151
|
+
req['X-Auth-Token'] = authtoken
|
152
|
+
res = https.request(req)
|
153
|
+
JSON.parse(res.body)["images"].map { |e| [e["name"], e["id"]] }
|
154
|
+
end
|
155
|
+
|
156
|
+
def self.create_image(server_id, name)
|
157
|
+
uri = URI.parse "https://compute.tyo1.conoha.io/v2/#{tenant_id}/servers/#{server_id}/action"
|
158
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
159
|
+
https.use_ssl = true
|
160
|
+
req = Net::HTTP::Post.new(uri.request_uri)
|
161
|
+
req['Content-Type'] = 'application/json'
|
162
|
+
req['Accept'] = 'application/json'
|
163
|
+
req['X-Auth-Token'] = authtoken
|
164
|
+
req.body = {"createImage": {"name": name}}.to_json
|
165
|
+
res = https.request(req)
|
166
|
+
res.code == '202' ? 'OK' : 'Error'
|
167
|
+
end
|
168
|
+
|
169
|
+
def self.delete_image(image_ref)
|
170
|
+
uri = URI.parse "https://image-service.tyo1.conoha.io/v2/images/#{image_ref}"
|
171
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
172
|
+
https.use_ssl = true
|
173
|
+
req = Net::HTTP::Delete.new(uri.request_uri)
|
174
|
+
req['Content-Type'] = 'application/json'
|
175
|
+
req['Accept'] = 'application/json'
|
176
|
+
req['X-Auth-Token'] = authtoken
|
177
|
+
res = https.request(req)
|
178
|
+
res.code == '204' ? 'OK' : 'Error'
|
179
|
+
end
|
180
|
+
|
181
|
+
def self.create_from_image(image_ref, ram)
|
182
|
+
uri = URI.parse "https://compute.tyo1.conoha.io/v2/#{tenant_id}/servers"
|
183
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
184
|
+
https.use_ssl = true
|
185
|
+
req = Net::HTTP::Post.new(uri.request_uri)
|
186
|
+
req['Content-Type'] = 'application/json'
|
187
|
+
req['Accept'] = 'application/json'
|
188
|
+
req['X-Auth-Token'] = authtoken
|
189
|
+
payload = {
|
190
|
+
server: {
|
191
|
+
adminPass: randstr,
|
192
|
+
imageRef: image_ref,
|
193
|
+
flavorRef: flavor_ref(ram),
|
194
|
+
key_name: public_key,
|
195
|
+
security_groups: [
|
196
|
+
{name: 'default'},
|
197
|
+
{name: 'gncs-ipv4-all'}
|
198
|
+
]
|
199
|
+
}
|
200
|
+
}.to_json
|
201
|
+
req.body = payload
|
202
|
+
res = https.request(req)
|
203
|
+
JSON.parse(res.body)["server"]["id"]
|
204
|
+
end
|
205
|
+
|
206
|
+
private
|
207
|
+
|
208
|
+
@@config_loaded = false
|
209
|
+
|
210
|
+
def self.config_file_path
|
211
|
+
ENV['HOME'] + '/.conoha-config.json'
|
212
|
+
end
|
213
|
+
|
214
|
+
def self.config_file_string
|
215
|
+
unless File.exist? config_file_path
|
216
|
+
STDERR.print <<EOS
|
217
|
+
Create "~/.conoha-config.json".
|
218
|
+
For example:
|
219
|
+
|
220
|
+
cat <<EOF > ~/.conoha-config.json
|
221
|
+
{
|
222
|
+
"username": "gncu123456789",
|
223
|
+
"password": "your-password",
|
224
|
+
"tenant_id": "0123456789abcdef",
|
225
|
+
"public_key": "your-registered-public-key-name"
|
226
|
+
}
|
227
|
+
EOF
|
228
|
+
chmod 600 ~/.conoha-config.json # For security
|
229
|
+
EOS
|
230
|
+
exit 1
|
231
|
+
end
|
232
|
+
File.open(config_file_path).read
|
233
|
+
end
|
234
|
+
|
235
|
+
def self.load_config!
|
236
|
+
unless @@config_loaded
|
237
|
+
config = JSON.parse config_file_string
|
238
|
+
@@username = config["username"]
|
239
|
+
@@password = config["password"]
|
240
|
+
@@tenant_id = config["tenant_id"]
|
241
|
+
@@public_key = config["public_key"]
|
242
|
+
@@authtoken = config["authtoken"]
|
243
|
+
@@config_loaded = true
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
def self.save_config!
|
248
|
+
s = JSON.generate({
|
249
|
+
username: @@username,
|
250
|
+
password: @@password,
|
251
|
+
tenant_id: @@tenant_id,
|
252
|
+
public_key: @@public_key,
|
253
|
+
authtoken: @@authtoken,
|
254
|
+
})
|
255
|
+
File.open(config_file_path, 'w').write s
|
256
|
+
end
|
257
|
+
|
258
|
+
def self.tenant_id
|
259
|
+
@@tenant_id
|
260
|
+
end
|
261
|
+
|
262
|
+
def self.authtoken
|
263
|
+
# @@authtoken || (authenticate!; @@authtoken)
|
264
|
+
@@authtoken
|
265
|
+
end
|
266
|
+
|
267
|
+
def self.public_key
|
268
|
+
@@public_key
|
269
|
+
end
|
270
|
+
|
271
|
+
def self.image_ref_from_os(os)
|
272
|
+
dictionary = {
|
273
|
+
'ubuntu' => '2b03327f-d453-4c7d-91c9-8b9924b6ea88', # Ubuntu 14.04 amd64
|
274
|
+
'centos66' => 'fa67ec7b-b9b4-4633-9012-fc5a6303aba7', # CentOS 6.6 (owncloud 8) (default)
|
275
|
+
'centos67' => '91944101-df61-4c41-b7c5-76cebfc48318', # CentOS 6.7
|
276
|
+
'centos71' => 'edc9457e-e4a8-4974-8217-c254d215b460', # CentOS 7.1
|
277
|
+
'arch' => 'b5c921c5-2f71-4cfe-9c5a-5783ce0be87b', # Arch
|
278
|
+
}
|
279
|
+
if dictionary.keys.include? os
|
280
|
+
dictionary[os]
|
281
|
+
else
|
282
|
+
STDERR.print <<EOS
|
283
|
+
select os name from the following list:
|
284
|
+
|
285
|
+
#{dictionary.keys.map { |e| " #{e}" }.join("\n")}
|
286
|
+
EOS
|
287
|
+
exit 1
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
def self.flavor_ref(ram)
|
292
|
+
dictionary = {
|
293
|
+
'g-1gb' => '7eea7469-0d85-4f82-8050-6ae742394681',
|
294
|
+
'g-2gb' => '294639c7-72ba-43a5-8ff2-513c8995b869',
|
295
|
+
'g-4gb' => '62e8fb4b-6a26-46cd-be13-e5bbf5614d15',
|
296
|
+
'g-8gb' => '965affd4-d9e8-4ffb-b9a9-624d63e2d83f',
|
297
|
+
'g-16gb' => '3aa001cd-95b6-46c9-a91e-e62d6f7f06a3',
|
298
|
+
'g-32gb' => 'a20905c6-3733-46c4-81cc-458c7dca1bae',
|
299
|
+
'g-64gb' => 'c2a97b05-1b4b-4038-bbcb-343201659279',
|
300
|
+
}
|
301
|
+
if dictionary.keys.include? ram
|
302
|
+
dictionary[ram]
|
303
|
+
else
|
304
|
+
STDERR.print <<EOS
|
305
|
+
select ram flavor name from the following list:
|
306
|
+
|
307
|
+
#{dictionary.keys.map { |e| " #{e}" }.join("\n")}
|
308
|
+
EOS
|
309
|
+
exit 1
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
def self.randstr
|
314
|
+
['0'..'9', 'a'..'z', 'A'..'Z'].map(&:to_a).flatten.sample(60).join
|
315
|
+
end
|
316
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: conoha
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ka
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-05 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.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
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
|
+
description: ConoHa VPS CLI Tool
|
42
|
+
email:
|
43
|
+
- ka.kaosf@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".travis.yml"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/conoha
|
55
|
+
- bin/console
|
56
|
+
- bin/setup
|
57
|
+
- conoha.gemspec
|
58
|
+
- lib/conoha.rb
|
59
|
+
- lib/conoha/version.rb
|
60
|
+
homepage: https://github.com/kaosf/conoha
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.4.5.1
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: ConoHa VPS CLI Tool
|
84
|
+
test_files: []
|
85
|
+
has_rdoc:
|