gce-host 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/.yardopts +6 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +210 -0
- data/Rakefile +30 -0
- data/bin/gce-host +4 -0
- data/docs/GCE.html +132 -0
- data/docs/GCE/Host.html +901 -0
- data/docs/GCE/Host/CLI.html +610 -0
- data/docs/GCE/Host/Config.html +1195 -0
- data/docs/GCE/Host/GCEClient.html +215 -0
- data/docs/GCE/Host/GCEClient/Error.html +127 -0
- data/docs/GCE/Host/GCEClient/NotFound.html +131 -0
- data/docs/GCE/Host/HashUtil.html +178 -0
- data/docs/GCE/Host/HostData.html +1658 -0
- data/docs/GCE/Host/RoleData.html +932 -0
- data/docs/GCE/Host/StringUtil.html +359 -0
- data/docs/_index.html +231 -0
- data/docs/class_list.html +58 -0
- data/docs/css/common.css +1 -0
- data/docs/css/full_list.css +57 -0
- data/docs/css/style.css +339 -0
- data/docs/file.LICENSE.html +95 -0
- data/docs/file.README.html +312 -0
- data/docs/file_list.html +63 -0
- data/docs/frames.html +26 -0
- data/docs/index.html +312 -0
- data/docs/js/app.js +219 -0
- data/docs/js/full_list.js +181 -0
- data/docs/js/jquery.js +4 -0
- data/docs/method_list.html +477 -0
- data/docs/top-level-namespace.html +112 -0
- data/example/example.conf +8 -0
- data/example/example.rb +6 -0
- data/gce-host.gemspec +26 -0
- data/lib/gce-host.rb +7 -0
- data/lib/gce/host.rb +120 -0
- data/lib/gce/host/cli.rb +151 -0
- data/lib/gce/host/config.rb +109 -0
- data/lib/gce/host/gce_client.rb +69 -0
- data/lib/gce/host/hash_util.rb +11 -0
- data/lib/gce/host/host_data.rb +227 -0
- data/lib/gce/host/role_data.rb +64 -0
- data/lib/gce/host/string_util.rb +31 -0
- data/lib/gce/host/version.rb +5 -0
- data/spec/gce_client_spec.rb +29 -0
- data/spec/host_spec.rb +199 -0
- data/spec/spec_helper.rb +22 -0
- data/terraform.tf +52 -0
- metadata +226 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 62b31646dd076986d8c0cc9bbd2c25a47c39c68d
|
4
|
+
data.tar.gz: 160b97e5f289c5e44f3391e59a4702d55a1750e8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 23878d91ddc9527713a68d263d19c77ee0b57cc875e06dbc95e162f479523fad4ac1bda7873860e0f41df275ee0f69c3cac344995c0f9756d96e2de10e80a1a4
|
7
|
+
data.tar.gz: 99db823d6e304bc8ef7071cbd14186470b55d86fdfc81f814c38d7ec3ca8d0d38a4aa31355a45457902d951f428ca67c7a56ba43484af667416212bd1b089bce
|
data/.gitignore
ADDED
data/.yardopts
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2016 Naotoshi Seo
|
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,210 @@
|
|
1
|
+
# gce-host
|
2
|
+
|
3
|
+
Search hosts on GCP GCE
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```
|
8
|
+
gem install gce-host
|
9
|
+
```
|
10
|
+
|
11
|
+
## How it works
|
12
|
+
|
13
|
+
This gems uses [metadata of GCE resources](https://cloud.google.com/compute/docs/storing-retrieving-metadata).
|
14
|
+
You can configure, but basically use `roles` key for roles.
|
15
|
+
|
16
|
+
You can manage roles of a host, and search hosts having a specified role using thease metadata with this gem.
|
17
|
+
|
18
|
+
## Configuration
|
19
|
+
|
20
|
+
You can write a configuration file located at `/etc/sysconfig/gce-host` (You can configure this path by `GCE_HOST_CONFIG_FILE` environment variable), or as environment variables:
|
21
|
+
|
22
|
+
GOOGLE API parameters:
|
23
|
+
|
24
|
+
* **AUTH_METHOD**: Authentication method. Currently, `compute_engine`, `json_key` and `application_default` is available. The default is `applilcation_default`.
|
25
|
+
* **GOOGLE_CREDENTIAL_FILE**: Path of credential file. Specify your service account json file for `json_key` authentication method.
|
26
|
+
|
27
|
+
gce-host parameters:
|
28
|
+
|
29
|
+
* **ROLES_KEY (optional)**: GCE metadata keys used to express roles. The default is `roles`
|
30
|
+
* You can assign multiple roles seperated by `ARRAY_VALUE_DELIMITER` (default: `,`)
|
31
|
+
* Also, you can express levels of roles delimited by `ROLE_VALUE_DELIMITER` (default `:`)
|
32
|
+
* Example: admin:ami, then `GCE::Host.new(role: 'admin:ami')` and also `GCE::Host.new(role1: 'admin')` returns this host
|
33
|
+
* **ROLE_VALUE_DELIMITER (optional)**: A delimiter to express levels of roles. Default is `:`
|
34
|
+
* **OPTIONAL_STRING_KEYS (optional)**: You may add optional non-array metadata keys. You can specify multiple keys like `service,status`.
|
35
|
+
* **OPTIONAL_ARRAY_KEYS (optional)**: You may add optional array metadata keys. Array allows multiple values delimited by `ARRAY_VALUE_DELIMITER` (default: `,`)
|
36
|
+
* **ARRAY_VALUE_DELIMITER (optional)**: A delimiter to express array. Default is `,`
|
37
|
+
* **LOG_LEVEL (optional)**: Log level such as `info`, `debug`, `error`. The default is `info`.
|
38
|
+
|
39
|
+
See [example.conf](./example/example.conf)
|
40
|
+
|
41
|
+
## Metadata Example
|
42
|
+
|
43
|
+
* **roles**: app:web,app:db
|
44
|
+
* **service**: awesome
|
45
|
+
* **status**: setup
|
46
|
+
|
47
|
+
## CLI Usage
|
48
|
+
|
49
|
+
### CLI Example
|
50
|
+
|
51
|
+
```
|
52
|
+
$ gce-host -j
|
53
|
+
{"hostname":"gce-host-db","roles":["foo","db:test"],"zone":"asia-northeast1-a","service":"gce-host","status":"active","tags":["master"],"instance_id":"4263858691219514807","private_ip_address":"10.240.0.6","public_ip_address":"104.198.89.55","creation_timestamp":"2016-11-22T06:51:04.650-08:00","state":"RUNNING"}
|
54
|
+
{"hostname":"gce-host-web","roles":["foo","web:test"],"zone":"asia-northeast1-a","service":"gce-host","status":"reserve","tags":["standby"],"instance_id":"8807276062743061943","private_ip_address":"10.240.0.5","public_ip_address":"104.198.87.6","creation_timestamp":"2016-11-22T06:51:04.653-08:00","state":"RUNNING"}
|
55
|
+
```
|
56
|
+
|
57
|
+
```
|
58
|
+
$ gce-host
|
59
|
+
gce-host-db
|
60
|
+
gce-host-web
|
61
|
+
```
|
62
|
+
|
63
|
+
```
|
64
|
+
$ gce-host --role1 db
|
65
|
+
gce-host-db
|
66
|
+
```
|
67
|
+
|
68
|
+
```
|
69
|
+
$ gce-host --role web:test
|
70
|
+
gce-host-web
|
71
|
+
```
|
72
|
+
|
73
|
+
```
|
74
|
+
$ gce-host --pretty-json
|
75
|
+
[
|
76
|
+
{
|
77
|
+
"hostname": "gce-host-db",
|
78
|
+
"roles": [
|
79
|
+
"foo",
|
80
|
+
"db:test"
|
81
|
+
],
|
82
|
+
"zone": "asia-northeast1-a",
|
83
|
+
"service": "gce-host",
|
84
|
+
"status": "active",
|
85
|
+
"tags": [
|
86
|
+
"master"
|
87
|
+
],
|
88
|
+
"instance_id": "4263858691219514807",
|
89
|
+
"private_ip_address": "10.240.0.6",
|
90
|
+
"public_ip_address": "104.198.89.55",
|
91
|
+
"creation_timestamp": "2016-11-22T06:51:04.650-08:00",
|
92
|
+
"state": "RUNNING"
|
93
|
+
},
|
94
|
+
{
|
95
|
+
"hostname": "gce-host-web",
|
96
|
+
"roles": [
|
97
|
+
"foo",
|
98
|
+
"web:test"
|
99
|
+
],
|
100
|
+
"zone": "asia-northeast1-a",
|
101
|
+
"service": "gce-host",
|
102
|
+
"status": "reserve",
|
103
|
+
"tags": [
|
104
|
+
"standby"
|
105
|
+
],
|
106
|
+
"instance_id": "8807276062743061943",
|
107
|
+
"private_ip_address": "10.240.0.5",
|
108
|
+
"public_ip_address": "104.198.87.6",
|
109
|
+
"creation_timestamp": "2016-11-22T06:51:04.653-08:00",
|
110
|
+
"state": "RUNNING"
|
111
|
+
}
|
112
|
+
]
|
113
|
+
```
|
114
|
+
|
115
|
+
### CLI Help
|
116
|
+
|
117
|
+
```
|
118
|
+
$ bin/gce-host --help
|
119
|
+
Usage: gce-host [options]
|
120
|
+
--hostname one,two,three name or private_dns_name
|
121
|
+
-r, --role one,two,three role
|
122
|
+
--r1, --role1 one,two,three role1, the 1st part of role delimited by :
|
123
|
+
--r2, --role2 one,two,three role2, the 2st part of role delimited by :
|
124
|
+
--r3, --role3 one,two,three role3, the 3st part of role delimited by :
|
125
|
+
--state one,two,three filter with instance state (default: running)
|
126
|
+
-a, --all list all hosts (remove default filter)
|
127
|
+
--private-ip, --ip show private ip address instead of hostname
|
128
|
+
--public-ip show public ip address instead of hostname
|
129
|
+
-i, --info show host info
|
130
|
+
-j, --jsonl show host info in line delimited json
|
131
|
+
--json show host info in json
|
132
|
+
--pretty-json show host info in pretty json
|
133
|
+
--debug debug mode
|
134
|
+
-h, --help show help
|
135
|
+
```
|
136
|
+
|
137
|
+
## Library Usage
|
138
|
+
|
139
|
+
### Library Example
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
require 'gce-host'
|
143
|
+
|
144
|
+
hosts = GCE::Host.new(role: 'db:test')
|
145
|
+
hosts.each do |host|
|
146
|
+
puts host
|
147
|
+
end
|
148
|
+
```
|
149
|
+
|
150
|
+
### Library Reference
|
151
|
+
|
152
|
+
See http://sonots.github.io/gce-host/frames.html.
|
153
|
+
|
154
|
+
## ChangeLog
|
155
|
+
|
156
|
+
See [CHANGELOG.md](CHANGELOG.md) for details.
|
157
|
+
|
158
|
+
## For Developers
|
159
|
+
|
160
|
+
### ToDo
|
161
|
+
|
162
|
+
* Use mock/stub to run test (currently, directly accessing to GCE)
|
163
|
+
* Should cache a result of list_instances in like 30 seconds?
|
164
|
+
|
165
|
+
### How to Run test
|
166
|
+
|
167
|
+
NOTE: Currently, mock is not supported yet. So, you have to create your own gcloud account, and instances.
|
168
|
+
|
169
|
+
Configure .env file as
|
170
|
+
|
171
|
+
```
|
172
|
+
AUTH_METHOD=json_key
|
173
|
+
GOOGLE_CREDENTIAL_FILE=service_acount.json
|
174
|
+
GOOGLE_PROJECT=XXXXXXXXXXXXX
|
175
|
+
OPTIONAL_STRING_KEYS=service,status
|
176
|
+
OPTIONAL_ARRAY_KEYS=tags
|
177
|
+
```
|
178
|
+
|
179
|
+
Install terraform and run to create instances for tests
|
180
|
+
|
181
|
+
```
|
182
|
+
$ brew install terraform
|
183
|
+
$ env $(cat .env) terraform plan
|
184
|
+
$ env ($cat .env) terraform apply
|
185
|
+
```
|
186
|
+
|
187
|
+
Run test
|
188
|
+
|
189
|
+
```
|
190
|
+
$ bundle exec rspec
|
191
|
+
```
|
192
|
+
|
193
|
+
After working, destory instances by commenting out `terraform.tf` and apply.
|
194
|
+
|
195
|
+
### How to Release Gem
|
196
|
+
|
197
|
+
1. Update gem.version in the gemspec
|
198
|
+
2. Update CHANGELOG.md
|
199
|
+
3. git commit && git push
|
200
|
+
4. Run `bundle exec rake release`
|
201
|
+
|
202
|
+
### How to Update doc
|
203
|
+
|
204
|
+
1. Run `bundle exec yard`
|
205
|
+
2. git commit && git push
|
206
|
+
|
207
|
+
### Licenses
|
208
|
+
|
209
|
+
See [LICENSE](LICENSE)
|
210
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- coding: utf-8; -*-
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
RSpec::Core::RakeTask.new :spec do |spec|
|
7
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
8
|
+
end
|
9
|
+
task default: :spec
|
10
|
+
rescue LoadError, NameError
|
11
|
+
# OK, they can be absent on non-development mode.
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "irb console"
|
15
|
+
task :console do
|
16
|
+
require_relative "lib/gce-host"
|
17
|
+
require 'irb'
|
18
|
+
require 'irb/completion'
|
19
|
+
ARGV.clear
|
20
|
+
IRB.start
|
21
|
+
end
|
22
|
+
task :c => :console
|
23
|
+
|
24
|
+
desc "pry console"
|
25
|
+
task :pry do
|
26
|
+
require_relative "lib/gce-host"
|
27
|
+
require 'pry'
|
28
|
+
ARGV.clear
|
29
|
+
Pry.start
|
30
|
+
end
|
data/bin/gce-host
ADDED
data/docs/GCE.html
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
6
|
+
<title>
|
7
|
+
Class: GCE
|
8
|
+
|
9
|
+
— Documentation by YARD 0.8.7.6
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
hasFrames = window.top.frames.main ? true : false;
|
19
|
+
relpath = '';
|
20
|
+
framesUrl = "frames.html#!GCE.html";
|
21
|
+
</script>
|
22
|
+
|
23
|
+
|
24
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
25
|
+
|
26
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
27
|
+
|
28
|
+
|
29
|
+
</head>
|
30
|
+
<body>
|
31
|
+
<div id="header">
|
32
|
+
<div id="menu">
|
33
|
+
|
34
|
+
<a href="_index.html">Index (G)</a> »
|
35
|
+
|
36
|
+
|
37
|
+
<span class="title">GCE</span>
|
38
|
+
|
39
|
+
|
40
|
+
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
41
|
+
</div>
|
42
|
+
|
43
|
+
<div id="search">
|
44
|
+
|
45
|
+
<a class="full_list_link" id="class_list_link"
|
46
|
+
href="class_list.html">
|
47
|
+
Class List
|
48
|
+
</a>
|
49
|
+
|
50
|
+
<a class="full_list_link" id="method_list_link"
|
51
|
+
href="method_list.html">
|
52
|
+
Method List
|
53
|
+
</a>
|
54
|
+
|
55
|
+
<a class="full_list_link" id="file_list_link"
|
56
|
+
href="file_list.html">
|
57
|
+
File List
|
58
|
+
</a>
|
59
|
+
|
60
|
+
</div>
|
61
|
+
<div class="clear"></div>
|
62
|
+
</div>
|
63
|
+
|
64
|
+
<iframe id="search_frame"></iframe>
|
65
|
+
|
66
|
+
<div id="content"><h1>Class: GCE
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
</h1>
|
71
|
+
|
72
|
+
<dl class="box">
|
73
|
+
|
74
|
+
<dt class="r1">Inherits:</dt>
|
75
|
+
<dd class="r1">
|
76
|
+
<span class="inheritName">Object</span>
|
77
|
+
|
78
|
+
<ul class="fullTree">
|
79
|
+
<li>Object</li>
|
80
|
+
|
81
|
+
<li class="next">GCE</li>
|
82
|
+
|
83
|
+
</ul>
|
84
|
+
<a href="#" class="inheritanceTree">show all</a>
|
85
|
+
|
86
|
+
</dd>
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
<dt class="r2 last">Defined in:</dt>
|
97
|
+
<dd class="r2 last">lib/gce/host.rb<span class="defines">,<br />
|
98
|
+
lib/gce/host/cli.rb,<br /> lib/gce/host/config.rb,<br /> lib/gce/host/version.rb,<br /> lib/gce/host/host_data.rb,<br /> lib/gce/host/role_data.rb,<br /> lib/gce/host/hash_util.rb,<br /> lib/gce/host/gce_client.rb,<br /> lib/gce/host/string_util.rb</span>
|
99
|
+
</dd>
|
100
|
+
|
101
|
+
</dl>
|
102
|
+
<div class="clear"></div>
|
103
|
+
|
104
|
+
<h2>Defined Under Namespace</h2>
|
105
|
+
<p class="children">
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
<strong class="classes">Classes:</strong> <span class='object_link'><a href="GCE/Host.html" title="GCE::Host (class)">Host</a></span>
|
111
|
+
|
112
|
+
|
113
|
+
</p>
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
</div>
|
124
|
+
|
125
|
+
<div id="footer">
|
126
|
+
Generated on Wed Nov 23 20:08:31 2016 by
|
127
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
128
|
+
0.8.7.6 (ruby-2.3.2).
|
129
|
+
</div>
|
130
|
+
|
131
|
+
</body>
|
132
|
+
</html>
|