Class: BoxGrinder::BbcloudDeliveryPlugin
- Inherits:
-
BasePlugin
- Object
- BasePlugin
- BoxGrinder::BbcloudDeliveryPlugin
- Defined in:
- lib/delivery/bbcloud-delivery-plugin.rb
Instance Method Summary collapse
- #account ⇒ Object
- #after_init ⇒ Object
- #curl_command ⇒ Object
- #default_description ⇒ Object
- #default_mode ⇒ Object
- #default_name ⇒ Object
- #default_public ⇒ Object
- #default_username ⇒ Object
- #disk_image ⇒ Object
- #execute(type = :bbcloud) ⇒ Object
- #ftp_hash ⇒ Object
- #image_id ⇒ Object
- #register_image ⇒ Object
- #register_image_command ⇒ Object
- #target_name ⇒ Object
- #upload ⇒ Object
- #validate_mode ⇒ Object
- #validate_public ⇒ Object
Instance Method Details
#account ⇒ Object
66 67 68 69 70 71 |
# File 'lib/delivery/bbcloud-delivery-plugin.rb', line 66 def account @account ||= @exec_helper.execute("brightbox-accounts -s list 2>/dev/null").split[0] rescue RuntimeError => e @log.error e. 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_init ⇒ Object
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_command ⇒ Object
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_description ⇒ Object
93 94 95 |
# File 'lib/delivery/bbcloud-delivery-plugin.rb', line 93 def default_description @appliance_config.summary end |
#default_mode ⇒ Object
97 98 99 |
# File 'lib/delivery/bbcloud-delivery-plugin.rb', line 97 def default_mode 'virtio' end |
#default_name ⇒ Object
89 90 91 |
# File 'lib/delivery/bbcloud-delivery-plugin.rb', line 89 def default_name @appliance_config.name end |
#default_public ⇒ Object
105 106 107 |
# File 'lib/delivery/bbcloud-delivery-plugin.rb', line 105 def default_public 'false' end |
#default_username ⇒ Object
101 102 103 |
# File 'lib/delivery/bbcloud-delivery-plugin.rb', line 101 def default_username 'brightbox' end |
#disk_image ⇒ Object
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 #{account}" upload register_image end |
#ftp_hash ⇒ Object
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 #{account} 2>/dev/null").split(/[\t\n]/))] end |
#image_id ⇒ Object
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_image ⇒ Object
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 #{account} with the name '#{@plugin_config['name']}'" @log.info "Run 'brightbox-images show #{image_id}' to check registration progress" end |
#register_image_command ⇒ Object
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_name ⇒ Object
81 82 83 |
# File 'lib/delivery/bbcloud-delivery-plugin.rb', line 81 def target_name File.basename(disk_image) end |
#upload ⇒ Object
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_mode ⇒ Object
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_public ⇒ Object
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 |