Class: VagrantPlugins::ProviderIijGp::Action::PrepareIIJAPI

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

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ PrepareIIJAPI

Returns a new instance of PrepareIIJAPI.



7
8
9
10
# File 'lib/vagrant-iijgp/action/prepare_iijapi.rb', line 7

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

Instance Method Details

#call(env) ⇒ Object



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/vagrant-iijgp/action/prepare_iijapi.rb', line 12

def call(env)
  config = env[:machine].provider_config

  # use the existing gc contract.
  if config.gc_service_code
    if env[:machine].id.nil?
      # first time `vagrant up`
      env[:machine].id = config.gc_service_code
    elsif config.gc_service_code != env[:machine].id
      raise Errors::MismatchServiceCode, :provider_config => config.gc_service_code, :machine_id => env[:machine].id
    end
  end

  opts = {
    :access_key => config.access_key,
    :secret_key => config.secret_key
  }
  opts[:endpoint] = config.endpoint if config.endpoint

  env[:iijapi] = IIJ::Sakagura::GP::Client.new(opts)

  @app.call(env)
end