Top Level Namespace
Defined Under Namespace
Modules: VagrantPlugins Classes: IgnitionDiskGenerator
Constant Summary collapse
- VAGRANT_INSECURE_KEY =
Vagrant insecure key
"ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key"- HOSTNAME_REGEX =
/^(?=.{1,255}$)[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?)*\.?$/
Instance Method Summary collapse
- #hostname_entry(hostname) ⇒ Object
- #ignition_template ⇒ Object
- #ip_entry(ip) ⇒ Object
- #merge_ignition(ignition_path, hostname, ip, env) ⇒ Object
- #ssh_entry ⇒ Object
- #vmdk_gen(ignition_path, vmdk_name, config_drive, hostname, ip, env) ⇒ Object
Instance Method Details
#hostname_entry(hostname) ⇒ Object
7 8 9 |
# File 'lib/vagrant-ignition/action/merge_ignition.rb', line 7 def hostname_entry(hostname) {filesystem: "root", path: "/etc/hostname", contents: {source: "data:,%s" % hostname, verification: {}}, mode: 0644, user: {id: 0}, group: {id: 0}} end |
#ignition_template ⇒ Object
3 4 5 |
# File 'lib/vagrant-ignition/action/merge_ignition.rb', line 3 def ignition_template() {ignition: {version: "2.0.0", config: {}}, storage: {}, networkd: {}, passwd: {}} end |
#ip_entry(ip) ⇒ Object
11 12 13 |
# File 'lib/vagrant-ignition/action/merge_ignition.rb', line 11 def ip_entry(ip) {name: "00-eth1.network", contents: "[Match]\nName=eth1\n\n[Network]\nAddress=%s" % ip} end |
#merge_ignition(ignition_path, hostname, ip, env) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/vagrant-ignition/action/merge_ignition.rb', line 24 def merge_ignition(ignition_path, hostname, ip, env) if !ignition_path.nil? ign_file = File.new(ignition_path, "rb") config = JSON.parse(File.read(ign_file), :symbolize_names => true) else config = ignition_template() # set this so the write function at the end can be simple ignition_path = "config.ign" end # Handle hostname if !hostname.nil? if !(hostname =~ (HOSTNAME_REGEX)).nil? config[:storage] ||= {:files => []} config[:storage][:files] ||= [] config[:storage][:files] += [hostname_entry(hostname)] else env[:machine].ui.info "WARNING: Invalid hostname specified in config.ignition.hostname; ignoring hostname for Ignition Config Drive" end end # Handle eth1 if !ip.nil? config[:networkd] ||= {:units => []} config[:networkd][:units] ||= [] config[:networkd][:units] += [ip_entry(ip)] end # Handle ssh key config[:passwd] ||= {:users => []} config[:passwd][:users] ||= [] if config[:passwd][:users].select {|user| user[:name] == "core"} != [] config[:passwd][:users].select{|user| user[:name] == "core"}[0][:sshAuthorizedKeys] ||= [] config[:passwd][:users].select{|user| user[:name] == "core"}[0][:sshAuthorizedKeys] += [VAGRANT_INSECURE_KEY] else config[:passwd][:users] += [ssh_entry()] end File.open(ignition_path + ".merged","w") do |f| f.write(config.to_json) end end |
#ssh_entry ⇒ Object
18 19 20 |
# File 'lib/vagrant-ignition/action/merge_ignition.rb', line 18 def ssh_entry() {name: "core", sshAuthorizedKeys: [VAGRANT_INSECURE_KEY]} end |
#vmdk_gen(ignition_path, vmdk_name, config_drive, hostname, ip, env) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/vagrant-ignition/action/vmdk_gen.rb', line 5 def vmdk_gen(ignition_path, vmdk_name, config_drive, hostname, ip, env) merge_ignition(ignition_path, hostname, ip, env) if !ignition_path.nil? IgnitionDiskGenerator.create_disk(ignition_path + ".merged", config_drive) else IgnitionDiskGenerator.create_disk("config.ign.merged", config_drive) end if File.exist?(vmdk_name) File.delete(vmdk_name) end env[:machine].provider.driver.execute("internalcommands", "createrawvmdk", "-filename", "#{vmdk_name}", "-rawdisk", "#{config_drive}") end |