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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5ba67d06a8c97f3882fac1ff37cc025d3d64a7f1
4
- data.tar.gz: 7520d469eec780d23438d6985d92e2cf87c75678
3
+ metadata.gz: d2ddcd65fb8f4196960205752361d591aa7ff7f4
4
+ data.tar.gz: a37e9aa6c729f372e941149f8797c34598a9432b
5
5
  SHA512:
6
- metadata.gz: 5a2b239695545db654fe3ad1b01e11e84f2a17da16753f79c9dfea8fee940cfe9b2bf3b1e5c0daf40442df1c2a0817c9783cfb9524902121be993d5aaab24677
7
- data.tar.gz: ca94497f4fc039bb66504cecbee41223ab61e11952b775f0949d1354dcedb6f1e5704ca1bf3e15a4fe9b20ff3451edf23678ee2a11ded8fae6ac587d07bda0e5
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
@@ -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
- # get external ip address
20
- i["networkInterfaces"].each do |ni|
21
- ni["accessConfigs"].each do |ac|
22
- if ac["name"].downcase.include?("nat") && ac["type"].downcase.include?("nat")
23
- if ip = ac["natIP"]
24
- str = "#{ip} #{i["name"]}"
25
- list << str
26
- raise HostError.new
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
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module GcloudHosts
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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.0
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-16 00:00:00.000000000 Z
11
+ date: 2016-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler