Class: BoxGrinder::BbcloudPlatformPlugin

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

Instance Method Summary collapse

Instance Method Details

#add_default_user(guestfs) ⇒ Object



79
80
81
82
83
84
# File 'lib/platform/bbcloud-platform-plugin.rb', line 79

def add_default_user(guestfs)
  @log.debug "Adding #{default_user} user..."
  guestfs.sh("useradd #{default_user}")
  guestfs.sh("echo -e '#{default_user}\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers")
  @log.debug "User #{default_user} added."
end

#after_initObject



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

def after_init
  register_deliverable(:disk => "#{deliverable_name}.gz")

  register_supported_os('fedora', ['13', '14', '15'])
  register_supported_os('centos', ['5'])
  register_supported_os('rhel', ['5', '6'])
  register_supported_os('sl', ['5', '6'])
end

#change_configuration(guestfs_helper) ⇒ Object



104
105
106
107
108
109
110
111
112
# File 'lib/platform/bbcloud-platform-plugin.rb', line 104

def change_configuration(guestfs_helper)
  guestfs_helper.augeas do
    # disable password authentication
    set("/etc/ssh/sshd_config", "PasswordAuthentication", "no")

    # disable root login
    set("/etc/ssh/sshd_config", "PermitRootLogin", "no")
  end
end

#default_userObject



75
76
77
# File 'lib/platform/bbcloud-platform-plugin.rb', line 75

def default_user
  "brightbox"
end

#deliverable_nameObject



35
36
37
# File 'lib/platform/bbcloud-platform-plugin.rb', line 35

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

#disable_root_password(guestfs) ⇒ Object



86
87
88
89
90
# File 'lib/platform/bbcloud-platform-plugin.rb', line 86

def disable_root_password(guestfs)
  @log.debug "Disabling root password"
  guestfs.sh("usermod -L root")
  @log.debug "root password disabled - use sudo from #{default_user} account"
end

#executeObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/platform/bbcloud-platform-plugin.rb', line 39

def execute
  @linux_helper = LinuxHelper.new(:log => @log)

  @log.info "Converting #{@appliance_config.name} appliance image to use Brightbox metadata services"

  @image_helper.convert_disk(@previous_deliverables.disk, 'raw', uncompressed_disk_name)

  @image_helper.customize([uncompressed_disk_name], :automount => true) do |guestfs, guestfs_helper|
    upload_rc_local(guestfs)
    add_default_user(guestfs)
	disable_root_password(guestfs)
    change_configuration(guestfs_helper)
    execute_post(guestfs_helper)
  end

  @log.info "Image converted to Brightbox format, compressing"
  @exec_helper.execute("gzip --fast -v #{uncompressed_disk_name}")
  @log.info "Disk compressed"
end

#execute_post(guestfs_helper) ⇒ Object



64
65
66
67
68
69
70
71
72
73
# File 'lib/platform/bbcloud-platform-plugin.rb', line 64

def execute_post(guestfs_helper)
  if @appliance_config.post['bbcloud']
    @appliance_config.post['bbcloud'].each do |cmd|
      guestfs_helper.sh(cmd, :arch => @appliance_config.hardware.arch)
    end
    @log.debug "Post commands from appliance definition file executed."
  else
    @log.debug "No commands specified, skipping."
  end
end

#uncompressed_disk_nameObject



59
60
61
# File 'lib/platform/bbcloud-platform-plugin.rb', line 59

def uncompressed_disk_name
  @uncompressed_name ||= File.join(File.dirname(@deliverables.disk), File.basename(@deliverables.disk, '.gz'))
end

#upload_rc_local(guestfs) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/platform/bbcloud-platform-plugin.rb', line 92

def upload_rc_local(guestfs)
  @log.debug "Uploading '/etc/rc.local' file..."
  rc_local = Tempfile.new('rc_local')
  rc_local << guestfs.read_file("/etc/rc.local") + File.read("#{File.dirname(__FILE__)}/src/rc_local")
  rc_local.flush

  guestfs.upload(rc_local.path, "/etc/rc.local")

  rc_local.close
  @log.debug "'/etc/rc.local' file uploaded."
end