Class: BoxGrinder::BbcloudDeliveryPlugin

Inherits:
BasePlugin
  • Object
show all
Defined in:
lib/delivery/bbcloud-delivery-plugin.rb

Instance Method Summary collapse

Instance Method Details

#accountObject



66
67
68
69
70
71
# File 'lib/delivery/bbcloud-delivery-plugin.rb', line 66

def 
  @account ||= @exec_helper.execute("brightbox-accounts -s list 2>/dev/null").split[0]
rescue RuntimeError => e
  @log.error e.message
  raise PluginValidationError, "Make sure the that brightbox cloud API tools are installed. Use 'brightbox-config client_add' to add the api client details for your account." 
end

#after_initObject



26
27
28
29
30
31
32
33
34
# File 'lib/delivery/bbcloud-delivery-plugin.rb', line 26

def after_init
  set_default_config_value('description', default_description)
  set_default_config_value('name', default_name)
  set_default_config_value('username', default_username)
  set_default_config_value('mode', default_mode)
  set_default_config_value('public', default_public)
  validate_mode
  validate_public
end

#curl_commandObject



85
86
87
# File 'lib/delivery/bbcloud-delivery-plugin.rb', line 85

def curl_command
  "curl #{if ENV['INSECURE'] then "-k" end} -# -u #{ftp_hash['library_ftp_user']}:#{ftp_hash['library_ftp_password']} --ftp-ssl-control -T #{disk_image} ftp://#{ftp_hash['library_ftp_host']}/incoming/#{target_name}"
end

#default_descriptionObject



93
94
95
# File 'lib/delivery/bbcloud-delivery-plugin.rb', line 93

def default_description
  @appliance_config.summary
end

#default_modeObject



97
98
99
# File 'lib/delivery/bbcloud-delivery-plugin.rb', line 97

def default_mode
  'virtio'
end

#default_nameObject



89
90
91
# File 'lib/delivery/bbcloud-delivery-plugin.rb', line 89

def default_name
  @appliance_config.name
end

#default_publicObject



105
106
107
# File 'lib/delivery/bbcloud-delivery-plugin.rb', line 105

def default_public
  'false'
end

#default_usernameObject



101
102
103
# File 'lib/delivery/bbcloud-delivery-plugin.rb', line 101

def default_username
  'brightbox'
end

#disk_imageObject



73
74
75
# File 'lib/delivery/bbcloud-delivery-plugin.rb', line 73

def disk_image
  @previous_deliverables[:disk]
end

#execute(type = :bbcloud) ⇒ Object



36
37
38
39
40
41
# File 'lib/delivery/bbcloud-delivery-plugin.rb', line 36

def execute( type = :bbcloud )
  @log.info "Adding '#{@plugin_config['name']}' appliance to Brightbox Cloud..." 
  @log.info "Using Brightbox account id #{}"
  upload
  register_image
end

#ftp_hashObject



77
78
79
# File 'lib/delivery/bbcloud-delivery-plugin.rb', line 77

def ftp_hash
  @ftp_hash ||= Hash[*(@exec_helper.execute("brightbox-accounts -s reset_ftp_password #{} 2>/dev/null").split(/[\t\n]/))]
end

#image_idObject



57
58
59
60
61
62
63
64
# File 'lib/delivery/bbcloud-delivery-plugin.rb', line 57

def image_id
  @image_id ||=
	if @exec_helper.execute(register_image_command) =~ /img-\w{5}/
	  Regexp.last_match[0]
	else
	  raise "Failed to obtain an image id from the registration command"
	end
end

#register_imageObject



52
53
54
55
# File 'lib/delivery/bbcloud-delivery-plugin.rb', line 52

def register_image
  @log.info "Registering appliance as #{image_id} under account #{} with the name '#{@plugin_config['name']}'"
  @log.info "Run 'brightbox-images show #{image_id}' to check registration progress"
end

#register_image_commandObject



125
126
127
# File 'lib/delivery/bbcloud-delivery-plugin.rb', line 125

def register_image_command
  "brightbox-images register -a #{@appliance_config.hardware.arch} -s #{target_name} -n '#{@plugin_config['name']}' -d '#{@plugin_config['description']}' -u '#{@plugin_config['username']}' -m '#{@plugin_config['mode']}' -p '#{@plugin_config['public']}'"
end

#target_nameObject



81
82
83
# File 'lib/delivery/bbcloud-delivery-plugin.rb', line 81

def target_name
  File.basename(disk_image)
end

#uploadObject



43
44
45
46
47
48
49
50
# File 'lib/delivery/bbcloud-delivery-plugin.rb', line 43

def upload
  @log.info "Uploading to #{ftp_hash['library_ftp_host']} with secure FTP"
  if system curl_command
    @log.info "Appliance #{@plugin_config['name']} uploaded."
  else
    raise "An error occurred while uploading files."
  end
end

#validate_modeObject



109
110
111
112
113
114
115
# File 'lib/delivery/bbcloud-delivery-plugin.rb', line 109

def validate_mode
  case @plugin_config['mode']
  when 'compatibility', 'virtio'
  else
    raise PluginValidationError, "Valid values for #{@plugin_info[:full_name]} plugin 'mode' option are 'compatibility' or 'virtio'"
  end
end

#validate_publicObject



117
118
119
120
121
122
123
# File 'lib/delivery/bbcloud-delivery-plugin.rb', line 117

def validate_public
  case @plugin_config['public']
  when 'true', 'false'
  else
    raise PluginValidationError, "Valid values for #{@plugin_info[:full_name]} plugin 'public' option are 'true' or 'false'"
  end
end