Class: Kitchen::Driver::Oci

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

Overview

Oracle OCI driver for Kitchen.

Author:

  • Stephen Pearson <stephen.pearson@oracle.com>

Instance Method Summary collapse

Instance Method Details

#create(state) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/kitchen/driver/oci.rb', line 76

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

  state = process_windows_options(state)

  instance_id = launch_instance(state)

  state[:server_id] = instance_id
  state[:hostname] = instance_ip(instance_id)

  instance.transport.connection(state).wait_until_ready

  state[:volumes] = process_volumes_list(state)
  state[:volume_attachments] = process_volume_attachments(state)

  return unless config[:post_create_script]

  info('Running post create script')
  script = config[:post_create_script]
  instance.transport.connection(state).execute(script)
end

#destroy(state) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/kitchen/driver/oci.rb', line 98

def destroy(state)
  return unless state[:server_id]

  instance.transport.connection(state).close

  if state[:volume_attachments]
    state[:volume_attachments].each do |attachment|
      volume_detach(attachment)
    end
  end

  if state[:volumes]
    state[:volumes].each do |vol|
      volume_delete(vol[:id])
    end
  end

  if instance_type == 'compute'
    comp_api.terminate_instance(state[:server_id])
  elsif instance_type == 'dbaas'
    dbaas_api.terminate_db_system(state[:server_id])
  end

  state.delete(:server_id)
  state.delete(:hostname)
end

#process_freeform_tags(freeform_tags) ⇒ Object



125
126
127
128
129
130
131
132
133
# File 'lib/kitchen/driver/oci.rb', line 125

def process_freeform_tags(freeform_tags)
  prov = instance.provisioner.instance_variable_get(:@config)
  tags = %w[run_list policyfile]
  tags.each do |tag|
    freeform_tags[tag] = prov[tag.to_sym].join(',') unless prov[tag.to_sym].nil? || prov[tag.to_sym].empty?
  end
  freeform_tags[:kitchen] = true
  freeform_tags
end

#process_windows_options(state) ⇒ Object



135
136
137
138
139
140
141
142
143
# File 'lib/kitchen/driver/oci.rb', line 135

def process_windows_options(state)
  state[:username] = config[:winrm_user] if config[:setup_winrm]
  if config[:setup_winrm] == true &&
     config[:password].nil? &&
     state[:password].nil?
    state[:password] = config[:winrm_password] || random_password
  end
  state
end