Class: BoxGrinder::BbcloudDeliveryPlugin

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

Instance Method Summary collapse

Instance Method Details

#accountObject



55
56
57
58
59
60
# File 'lib/delivery/bbcloud-delivery-plugin.rb', line 55

def 
  @account ||= @exec_helper.execute("brightbox-accounts -s list").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

#appliance_nameObject



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

def appliance_name
  "#{@appliance_config.name}-#{@appliance_config.version}.#{@appliance_config.release}-#{@appliance_config.os.name}-#{@appliance_config.os.version}-#{current_platform}"
end

#curl_commandObject



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

def curl_command
  "curl -# -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

#disk_imageObject



62
63
64
# File 'lib/delivery/bbcloud-delivery-plugin.rb', line 62

def disk_image
  @previous_deliverables[:disk]
end

#execute(type = :bbcloud) ⇒ Object



25
26
27
28
29
30
# File 'lib/delivery/bbcloud-delivery-plugin.rb', line 25

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

#ftp_hashObject



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

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

#image_idObject



46
47
48
49
50
51
52
53
# File 'lib/delivery/bbcloud-delivery-plugin.rb', line 46

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



41
42
43
44
# File 'lib/delivery/bbcloud-delivery-plugin.rb', line 41

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

#register_image_commandObject



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

def register_image_command
  "brightbox-images register -a #{@appliance_config.hardware.arch} -s #{target_name} -n '#{appliance_name}' -d '#{@appliance_config.summary}'"
end

#target_nameObject



70
71
72
# File 'lib/delivery/bbcloud-delivery-plugin.rb', line 70

def target_name
  File.basename(disk_image)
end

#uploadObject



32
33
34
35
36
37
38
39
# File 'lib/delivery/bbcloud-delivery-plugin.rb', line 32

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