Class: GcloudHosts::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/gcloud_hosts/runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Runner

Returns a new instance of Runner.



6
7
8
# File 'lib/gcloud_hosts/runner.rb', line 6

def initialize(args)
  @options = Options.new(args).options
end

Instance Method Details

#run!Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/gcloud_hosts/runner.rb', line 10

def run!
  project = @options[:project]
  if project.to_s.strip == ""
    project = env["core"]["project"]
  end
  if project.to_s.strip == ""
    raise AuthError.new("No gcloud project specified.")
  end

  if @options[:domain]
    domain = @options[:domain].to_s.strip
  else
    domain = "c.#{project}.internal"
  end

  backup = @options[:backup] ||
    @options[:file] + '.bak'

  if @options[:delete]
    new_hosts_list = []
  else
    new_hosts_list = Hosts.hosts(@options[:gcloud], project, @options[:network], domain, @options[:public], @options[:exclude_public])
  end
  Updater.update(new_hosts_list.join("\n"), project, @options[:file], backup, @options[:dry_run], @options[:delete])
end