Class: Kitchen::Driver::Linode

Inherits:
Base
  • Object
show all
Defined in:
lib/kitchen/driver/linode.rb

Overview

Linode driver for Kitchen.

Author:

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Linode

Returns a new instance of Linode.



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/kitchen/driver/linode.rb', line 76

def initialize(config)
  super
  # configure to retry on timeouts and rate limits by default
  Retryable.configure do |retry_config|
    retry_config.log_method   = method(:retry_log_method)
    retry_config.exception_cb = method(:retry_exception_callback)
    retry_config.on           = [Excon::Error::Timeout,
                                 Excon::Error::RequestTimeout,
                                 Excon::Error::TooManyRequests]
    retry_config.tries        = config[:api_retries]
    retry_config.sleep        = lambda { |n| 2**n } # sleep 1, 2, 4, etc. each try
  end
end

Instance Method Details

#create(state) ⇒ Object

create and boot server



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/kitchen/driver/linode.rb', line 91

def create(state)
  return if state[:linode_id]

  config_hostname
  config_label
  server = create_server

  update_state(state, server)
  info "Linode <#{state[:linode_id]}, #{state[:linode_label]}> created."
  info "Waiting for linode to boot..."
  server.wait_for { server.status == "running" }
  instance.transport.connection(state).wait_until_ready
  info "Linode <#{state[:linode_id]}, #{state[:linode_label]}> ready."
  setup_server(state) if bourne_shell?
rescue Fog::Errors::Error, Excon::Errors::Error => ex
  error "Failed to create server: #{ex.class} - #{ex.message}"
  raise ActionFailed, ex.message
end

#destroy(state) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/kitchen/driver/linode.rb', line 110

def destroy(state)
  return if state[:linode_id].nil?

  begin
    Retryable.retryable do
      server = compute.servers.get(state[:linode_id])
      server.destroy
    end
    info "Linode <#{state[:linode_id]}, #{state[:linode_label]}> destroyed."
  rescue Excon::Error::NotFound
    info "Linode <#{state[:linode_id]}, #{state[:linode_label]}> not found."
  end
  state.delete(:linode_id)
  state.delete(:linode_label)
  state.delete(:hostname)
  state.delete(:ssh_key)
  state.delete(:password)
end