Class: VagrantPlugins::ProviderIijGp::Action::SetLabel

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-iijgp/action/set_label.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ SetLabel

Returns a new instance of SetLabel.



5
6
7
8
# File 'lib/vagrant-iijgp/action/set_label.rb', line 5

def initialize(app, env)
  @app = app
  @logger = Log4r::Logger.new("vagrant_iijgp::action::set_label")
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/vagrant-iijgp/action/set_label.rb', line 10

def call(env)
  gp = env[:machine].provider_config.gp_service_code
  gc = env[:machine].id

  vm = env[:iijapi].gp(gp).gc(gc)
  label = env[:machine].provider_config.label || env[:machine].name.to_s || Time.now.strftime('%F %T')

  @logger.info("Setting the label of the VM [#{gp}/#{gc}]: #{label}")
  vm.label = label

  @app.call(env)
end