gcloud_hosts 0.1.0 → 0.1.1
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 +4 -4
- data/README.md +1 -0
- data/lib/gcloud_hosts/hosts.rb +11 -9
- data/lib/gcloud_hosts/options.rb +4 -0
- data/lib/gcloud_hosts/runner.rb +1 -1
- data/lib/gcloud_hosts/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2ddcd65fb8f4196960205752361d591aa7ff7f4
|
4
|
+
data.tar.gz: a37e9aa6c729f372e941149f8797c34598a9432b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e226856a75147c8c1e1de93f53986b78af452c6db3ad022c7ef3097816cc558eccc5976cb089c4e05ad1fcd7b5b7b7a144a4539a979cad8044d01a70b50785f7
|
7
|
+
data.tar.gz: 41391e1a31adc2a4c1ab4db9ac8ed57176e5799bfef635ecc58e6bb9580bf2d873011670583a5cd366ff16dc51a779da45c1c8d596989cbdbe36ad6a09b0a75b
|
data/README.md
CHANGED
@@ -25,6 +25,7 @@ Usage: $ gcloud_hosts [options]
|
|
25
25
|
-n, --network NETWORK gcloud network to filter on. Defaults nil.
|
26
26
|
-d, --domain DOMAIN Domain to append to all hosts. Default: "c.[PROJECT].internal"
|
27
27
|
--public PUBLIC Pattern to match for public/bastion hosts. Use public IP for these. Defaults to nil
|
28
|
+
--[no-]exclude-public Exclude public hosts from list when updating hosts file. Allows them to be managed manually. Defaults to false
|
28
29
|
-f, --file FILE Hosts file to update. Defaults to /etc/hosts
|
29
30
|
-b, --backup BACKUP Path to backup original hosts file to. Defaults to FILE with '.bak' extension appended.
|
30
31
|
--[no-]dry-run Dry run, do not modify hosts file. Defaults to false
|
data/lib/gcloud_hosts/hosts.rb
CHANGED
@@ -12,18 +12,20 @@ module GcloudHosts
|
|
12
12
|
end.sort { |x,y| x["name"] <=> y["name"] }
|
13
13
|
end
|
14
14
|
|
15
|
-
def self.hosts(gcloud_path, project, network, domain, public_pattern)
|
15
|
+
def self.hosts(gcloud_path, project, network, domain, public_pattern, exclude_public)
|
16
16
|
instances(gcloud_path, project, network).inject([]) do |list, i|
|
17
17
|
begin
|
18
18
|
if public_pattern.to_s.strip != "" && i["name"].downcase.include?(public_pattern)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
if
|
24
|
-
|
25
|
-
|
26
|
-
|
19
|
+
if !exclude_public
|
20
|
+
# get external ip address
|
21
|
+
i["networkInterfaces"].each do |ni|
|
22
|
+
ni["accessConfigs"].each do |ac|
|
23
|
+
if ac["name"].downcase.include?("nat") && ac["type"].downcase.include?("nat")
|
24
|
+
if ip = ac["natIP"]
|
25
|
+
str = "#{ip} #{i["name"]}"
|
26
|
+
list << str
|
27
|
+
raise HostError.new
|
28
|
+
end
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
data/lib/gcloud_hosts/options.rb
CHANGED
@@ -12,6 +12,7 @@ module GcloudHosts
|
|
12
12
|
network: nil,
|
13
13
|
domain: nil,
|
14
14
|
public: nil,
|
15
|
+
exclude_public: false,
|
15
16
|
file: '/etc/hosts',
|
16
17
|
backup: nil,
|
17
18
|
dry_run: false,
|
@@ -41,6 +42,9 @@ module GcloudHosts
|
|
41
42
|
opts.on('--public PUBLIC', "Pattern to match for public/bastion hosts. Use public IP for these. Defaults to nil") do |opt|
|
42
43
|
@options[:public] = opt
|
43
44
|
end
|
45
|
+
opts.on('--[no-]exclude-public', "Exclude public hosts from list when updating hosts file. Allows them to be managed manually. Defaults to false") do |opt|
|
46
|
+
@options[:exclude_public] = opt
|
47
|
+
end
|
44
48
|
opts.on('-f', '--file FILE', "Hosts file to update. Defaults to /etc/hosts") do |opt|
|
45
49
|
@options[:file] = opt
|
46
50
|
end
|
data/lib/gcloud_hosts/runner.rb
CHANGED
@@ -28,7 +28,7 @@ module GcloudHosts
|
|
28
28
|
if @options[:delete]
|
29
29
|
new_hosts_list = []
|
30
30
|
else
|
31
|
-
new_hosts_list = Hosts.hosts(@options[:gcloud], project, @options[:network], domain, @options[:public])
|
31
|
+
new_hosts_list = Hosts.hosts(@options[:gcloud], project, @options[:network], domain, @options[:public], @options[:exclude_public])
|
32
32
|
end
|
33
33
|
Updater.update(new_hosts_list.join("\n"), project, @options[:file], backup, @options[:dry_run], @options[:delete])
|
34
34
|
end
|
data/lib/gcloud_hosts/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gcloud_hosts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Tongen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|