PackerFiles 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (195) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/PackerFiles.gemspec +36 -0
  6. data/README.md +32 -0
  7. data/Rakefile +21 -0
  8. data/bin/pkf +5 -0
  9. data/lib/PackerFiles/CLI/OS.rb +44 -0
  10. data/lib/PackerFiles/CLI/Root.rb +41 -0
  11. data/lib/PackerFiles/Core/Base.rb +23 -0
  12. data/lib/PackerFiles/Core/CDImage.rb +185 -0
  13. data/lib/PackerFiles/Core/Disk.rb +135 -0
  14. data/lib/PackerFiles/Core/Exceptions.rb +65 -0
  15. data/lib/PackerFiles/Core/Hypervisor.rb +96 -0
  16. data/lib/PackerFiles/Core/Keyboard.rb +38 -0
  17. data/lib/PackerFiles/Core/Locale.rb +62 -0
  18. data/lib/PackerFiles/Core/LogicalVolume.rb +41 -0
  19. data/lib/PackerFiles/Core/Network.rb +67 -0
  20. data/lib/PackerFiles/Core/Packages.rb +30 -0
  21. data/lib/PackerFiles/Core/Partition.rb +41 -0
  22. data/lib/PackerFiles/Core/TimeZone.rb +45 -0
  23. data/lib/PackerFiles/Core/User.rb +46 -0
  24. data/lib/PackerFiles/Core/VolumeGroup.rb +50 -0
  25. data/lib/PackerFiles/Core/example/CDImage.txt +75 -0
  26. data/lib/PackerFiles/Core/example/Disk.txt +29 -0
  27. data/lib/PackerFiles/Core/example/Hypervisor.txt +111 -0
  28. data/lib/PackerFiles/Core/example/Keyboard.txt +28 -0
  29. data/lib/PackerFiles/Core/example/Locale.txt +31 -0
  30. data/lib/PackerFiles/Core/example/Network.txt +68 -0
  31. data/lib/PackerFiles/Core/example/Packages.txt +22 -0
  32. data/lib/PackerFiles/Core/example/TimeZone.txt +36 -0
  33. data/lib/PackerFiles/Core/example/User.txt +48 -0
  34. data/lib/PackerFiles/OS/Builder.rb +116 -0
  35. data/lib/PackerFiles/OS/CentOS/CD.rb +81 -0
  36. data/lib/PackerFiles/OS/CentOS/Kickstart.rb +64 -0
  37. data/lib/PackerFiles/OS/CentOS/Server.rb +170 -0
  38. data/lib/PackerFiles/OS/CentOS/Templates/Base_erb.rb +4 -0
  39. data/lib/PackerFiles/OS/CentOS/Templates/Disk_erb.rb +35 -0
  40. data/lib/PackerFiles/OS/CentOS/Templates/Keyboard_erb.rb +4 -0
  41. data/lib/PackerFiles/OS/CentOS/Templates/Locale_erb.rb +4 -0
  42. data/lib/PackerFiles/OS/CentOS/Templates/Network_erb.rb +17 -0
  43. data/lib/PackerFiles/OS/CentOS/Templates/Packages_erb.rb +34 -0
  44. data/lib/PackerFiles/OS/CentOS/Templates/Tail_erb.rb +15 -0
  45. data/lib/PackerFiles/OS/CentOS/Templates/TimeZone_erb.rb +10 -0
  46. data/lib/PackerFiles/OS/CentOS/Templates/User_erb.rb +20 -0
  47. data/lib/PackerFiles/OS/CentOS/Templates/boot_command_erb.rb +16 -0
  48. data/lib/PackerFiles/OS/CentOS/Templates/command_as_root_erb.rb +1 -0
  49. data/lib/PackerFiles/OS/CentOS/Templates/disable_root_erb.rb +1 -0
  50. data/lib/PackerFiles/OS/CentOS/Templates/enable_root_erb.rb +1 -0
  51. data/lib/PackerFiles/OS/CentOS/Templates/shutdown_command_erb.rb +1 -0
  52. data/lib/PackerFiles/OS/Debian/Apt.rb +42 -0
  53. data/lib/PackerFiles/OS/Debian/CD.rb +65 -0
  54. data/lib/PackerFiles/OS/Debian/Mirrors.rb +73 -0
  55. data/lib/PackerFiles/OS/Debian/Preseed.rb +64 -0
  56. data/lib/PackerFiles/OS/Debian/Server.rb +169 -0
  57. data/lib/PackerFiles/OS/Debian/Templates/Apt_erb.rb +18 -0
  58. data/lib/PackerFiles/OS/Debian/Templates/Disk_erb.rb +69 -0
  59. data/lib/PackerFiles/OS/Debian/Templates/Keyboard_erb.rb +5 -0
  60. data/lib/PackerFiles/OS/Debian/Templates/Locale_erb.rb +7 -0
  61. data/lib/PackerFiles/OS/Debian/Templates/Mirrors_erb.rb +9 -0
  62. data/lib/PackerFiles/OS/Debian/Templates/Network_erb.rb +19 -0
  63. data/lib/PackerFiles/OS/Debian/Templates/Packages_erb.rb +6 -0
  64. data/lib/PackerFiles/OS/Debian/Templates/TimeZone_erb.rb +6 -0
  65. data/lib/PackerFiles/OS/Debian/Templates/User_erb.rb +14 -0
  66. data/lib/PackerFiles/OS/Debian/Templates/boot_command_erb.rb +24 -0
  67. data/lib/PackerFiles/OS/Debian/Templates/command_as_root_erb.rb +1 -0
  68. data/lib/PackerFiles/OS/Debian/Templates/disable_root_erb.rb +5 -0
  69. data/lib/PackerFiles/OS/Debian/Templates/enable_root_erb.rb +1 -0
  70. data/lib/PackerFiles/OS/Debian/Templates/shutdown_command_erb.rb +1 -0
  71. data/lib/PackerFiles/OS/Debian/example/Apt.txt +55 -0
  72. data/lib/PackerFiles/OS/DocGenerator.rb +51 -0
  73. data/lib/PackerFiles/OS/Finder.rb +96 -0
  74. data/lib/PackerFiles/OS/RHEL/CD.rb +32 -0
  75. data/lib/PackerFiles/OS/RHEL/Fedora.rb +59 -0
  76. data/lib/PackerFiles/OS/RHEL/FedoraCD.rb +68 -0
  77. data/lib/PackerFiles/OS/RHEL/Server.rb +32 -0
  78. data/lib/PackerFiles/OS/RHEL/Templates/Fedora_Tail_erb.rb +14 -0
  79. data/lib/PackerFiles/OS/RHEL/Templates/boot_command_fedora_erb.rb +16 -0
  80. data/lib/PackerFiles/OS/SUSE/Templates/Base_erb.xml +32 -0
  81. data/lib/PackerFiles/OS/SUSE/Templates/Disk_erb.xml +110 -0
  82. data/lib/PackerFiles/OS/SUSE/Templates/Keyboard_erb.xml +7 -0
  83. data/lib/PackerFiles/OS/SUSE/Templates/Locale_erb.xml +18 -0
  84. data/lib/PackerFiles/OS/SUSE/Templates/Network_erb.xml +143 -0
  85. data/lib/PackerFiles/OS/SUSE/Templates/Packages_erb.xml +29 -0
  86. data/lib/PackerFiles/OS/SUSE/Templates/Tail_erb.xml +4 -0
  87. data/lib/PackerFiles/OS/SUSE/Templates/TimeZone_erb.xml +15 -0
  88. data/lib/PackerFiles/OS/SUSE/Templates/User_erb.xml +57 -0
  89. data/lib/PackerFiles/OS/SUSE/Templates/boot_command_erb.rb +23 -0
  90. data/lib/PackerFiles/OS/SUSE/Templates/command_as_root_erb.rb +1 -0
  91. data/lib/PackerFiles/OS/SUSE/Templates/disable_root_erb.rb +1 -0
  92. data/lib/PackerFiles/OS/SUSE/Templates/enable_root_erb.rb +1 -0
  93. data/lib/PackerFiles/OS/SUSE/Templates/shutdown_command_erb.rb +1 -0
  94. data/lib/PackerFiles/OS/Ubuntu/CD.rb +81 -0
  95. data/lib/PackerFiles/OS/Ubuntu/Desktop.rb +50 -0
  96. data/lib/PackerFiles/OS/Ubuntu/DesktopCD.rb +16 -0
  97. data/lib/PackerFiles/OS/Ubuntu/Mirrors.rb +103 -0
  98. data/lib/PackerFiles/OS/Ubuntu/Server.rb +78 -0
  99. data/lib/PackerFiles/OS/Ubuntu/Templates/Apt_erb.rb +18 -0
  100. data/lib/PackerFiles/OS/Ubuntu/Templates/boot_command_desktop_erb.rb +36 -0
  101. data/lib/PackerFiles/OS/Ubuntu/Templates/boot_command_erb.rb +30 -0
  102. data/lib/PackerFiles/OS/Ubuntu/Templates/ubiquity_erb.rb +8 -0
  103. data/lib/PackerFiles/OS/example/Doc.txt +8 -0
  104. data/lib/PackerFiles/Provision/Base.rb +20 -0
  105. data/lib/PackerFiles/Provision/ChefSolo.rb +90 -0
  106. data/lib/PackerFiles/Provision/ChefSoloHelper.rb +72 -0
  107. data/lib/PackerFiles/Provision/Copy.rb +22 -0
  108. data/lib/PackerFiles/Provision/ExternalScript.rb +43 -0
  109. data/lib/PackerFiles/Provision/InlineScript.rb +37 -0
  110. data/lib/PackerFiles/Provision/Provisioners.rb +87 -0
  111. data/lib/PackerFiles/Provision/example/Provisioners.txt +21 -0
  112. data/lib/PackerFiles/Utils/AutoZone.rb +96 -0
  113. data/lib/PackerFiles/Utils/FastestURL.rb +73 -0
  114. data/lib/PackerFiles/Utils/Generator.rb +34 -0
  115. data/lib/PackerFiles/Utils/HashSerializer.rb +110 -0
  116. data/lib/PackerFiles/Utils/Size.rb +44 -0
  117. data/lib/PackerFiles/Utils/TypeAccessor.rb +71 -0
  118. data/lib/PackerFiles/Virtual/Hypervisors.rb +72 -0
  119. data/lib/PackerFiles/Virtual/KVM.rb +119 -0
  120. data/lib/PackerFiles/Virtual/KVMConverter.rb +79 -0
  121. data/lib/PackerFiles/Virtual/VMWare.rb +108 -0
  122. data/lib/PackerFiles/Virtual/VMWareConverter.rb +78 -0
  123. data/lib/PackerFiles/Virtual/VirtualBox.rb +98 -0
  124. data/lib/PackerFiles/Virtual/VirtualBoxConverter.rb +75 -0
  125. data/lib/PackerFiles/Virtual/example/Hypervisors.txt +23 -0
  126. data/lib/PackerFiles/version.rb +3 -0
  127. data/lib/PackerFiles.rb +44 -0
  128. data/spec/core/builder_spec.rb +84 -0
  129. data/spec/core/cdimage_spec.rb +159 -0
  130. data/spec/core/disk_spec.rb +191 -0
  131. data/spec/core/keyboard_spec.rb +36 -0
  132. data/spec/core/locale_spec.rb +73 -0
  133. data/spec/core/network_spec.rb +96 -0
  134. data/spec/core/packages_spec.rb +18 -0
  135. data/spec/core/timezone_spec.rb +43 -0
  136. data/spec/core/user_spec.rb +44 -0
  137. data/spec/core/volume_group_spec.rb +53 -0
  138. data/spec/os/centos/cd_spec.rb +12 -0
  139. data/spec/os/centos/data/Server-Script-Provisioner.rb +57 -0
  140. data/spec/os/centos/data/Server.rb +55 -0
  141. data/spec/os/centos/data/chef-solo-provisioner.rb +58 -0
  142. data/spec/os/centos/finder_spec.rb +22 -0
  143. data/spec/os/centos/templates/boot_command_spec.rb +57 -0
  144. data/spec/os/centos/templates/disk_spec.rb +79 -0
  145. data/spec/os/centos/templates/keyboard_spec.rb +18 -0
  146. data/spec/os/centos/templates/locale_spec.rb +26 -0
  147. data/spec/os/centos/templates/network_spec.rb +38 -0
  148. data/spec/os/centos/templates/packages_spec.rb +18 -0
  149. data/spec/os/centos/templates/timezone_spec.rb +37 -0
  150. data/spec/os/centos/templates/user_spec.rb +24 -0
  151. data/spec/os/debian/apt_spec.rb +50 -0
  152. data/spec/os/debian/cd_spec.rb +30 -0
  153. data/spec/os/debian/data/7zip.tar.gz +0 -0
  154. data/spec/os/debian/data/All-sections.rb +60 -0
  155. data/spec/os/debian/data/Chef-Solo-Provisioner.rb +60 -0
  156. data/spec/os/debian/data/Copy-Provisioner.rb +61 -0
  157. data/spec/os/debian/data/External-Script-Provisioner.rb +69 -0
  158. data/spec/os/debian/data/Missing-CDImage.rb +53 -0
  159. data/spec/os/debian/data/Missing-VMWare-KVM-sections.rb +51 -0
  160. data/spec/os/debian/data/Missing-sections.rb +53 -0
  161. data/spec/os/debian/data/Script-Provisioner.rb +62 -0
  162. data/spec/os/debian/data/chef-solo-cookbooks/git_setup/Berksfile.lock +32 -0
  163. data/spec/os/debian/data/chef-solo-cookbooks/git_setup/README.md +81 -0
  164. data/spec/os/debian/data/chef-solo-cookbooks/git_setup/attributes/default.rb +3 -0
  165. data/spec/os/debian/data/chef-solo-cookbooks/git_setup/metadata.rb +11 -0
  166. data/spec/os/debian/data/chef-solo-cookbooks/git_setup/recipes/default.rb +30 -0
  167. data/spec/os/debian/data/chef-solo.json +5 -0
  168. data/spec/os/debian/data/test-script.sh +4 -0
  169. data/spec/os/debian/finder_spec.rb +59 -0
  170. data/spec/os/debian/mirrors_spec.rb +18 -0
  171. data/spec/os/debian/preseed_spec.rb +56 -0
  172. data/spec/os/debian/server_spec.rb +59 -0
  173. data/spec/os/debian/templates/apt_spec.rb +20 -0
  174. data/spec/os/debian/templates/boot_command_spec.rb +56 -0
  175. data/spec/os/debian/templates/disk_spec.rb +81 -0
  176. data/spec/os/debian/templates/keyboard_spec.rb +18 -0
  177. data/spec/os/debian/templates/locale_spec.rb +36 -0
  178. data/spec/os/debian/templates/mirrors_spec.rb +16 -0
  179. data/spec/os/debian/templates/network_spec.rb +38 -0
  180. data/spec/os/debian/templates/packages_spec.rb +17 -0
  181. data/spec/os/debian/templates/timezone_spec.rb +36 -0
  182. data/spec/os/debian/templates/user_spec.rb +25 -0
  183. data/spec/os/finder_spec.rb +21 -0
  184. data/spec/os/rhel/data/Fedora.rb +45 -0
  185. data/spec/os/rhel/data/Server-Custom.rb +54 -0
  186. data/spec/os/rhel/data/Server.rb +45 -0
  187. data/spec/os/rhel/finder_spec.rb +21 -0
  188. data/spec/os/ubuntu/cd_spec.rb +28 -0
  189. data/spec/os/ubuntu/data/Desktop.rb +61 -0
  190. data/spec/os/ubuntu/data/Server.rb +61 -0
  191. data/spec/os/ubuntu/finder_spec.rb +17 -0
  192. data/spec/os/ubuntu/mirrors_spec.rb +18 -0
  193. data/spec/utils/autozone_spec.rb +33 -0
  194. data/spec/virtual/virtual_box_spec.rb +16 -0
  195. metadata +405 -0
@@ -0,0 +1,111 @@
1
+
2
+ # Define Hypervisor parameters for this OS
3
+ <% if @obj.nil? -%>
4
+ #hypervisors.<%= @name -%> do |hyper|
5
+ <% else -%>
6
+ hypervisors.<%= @name -%> do |hyper|
7
+ <% end -%>
8
+
9
+ # No. of CPUs
10
+ <% if @obj.nil? || @obj.cpu_count.nil? -%>
11
+ #hyper.cpu_count = 1
12
+ <% else -%>
13
+ hyper.cpu_count = <%= @obj.cpu_count %>
14
+ <% end -%>
15
+
16
+ # Enable CPU Hot plug?
17
+ <% if @obj.nil? || @obj.cpu_hot_plug.nil? -%>
18
+ #hyper.cpu_hot_plug = false
19
+ <% else -%>
20
+ hyper.cpu_hot_plug = <%= @obj.cpu_hot_plug %>
21
+ <% end -%>
22
+
23
+ # CPU Execution Cap
24
+ <% if @obj.nil? || @obj.cpu_execution_cap.nil? -%>
25
+ #hyper.cpu_execution_cap = 100
26
+ <% else -%>
27
+ hyper.cpu_execution_cap = <%= @obj.cpu_execution_cap %>
28
+ <% end -%>
29
+
30
+ # RAM Size
31
+ <% if @obj.nil? || @obj.ram_size.nil? -%>
32
+ #hyper.ram_size = '1GiB'
33
+ <% else -%>
34
+ hyper.ram_size = '<%= @obj.ram_size -%>'
35
+ <% end -%>
36
+
37
+ # Video ram size
38
+ <% if @obj.nil? || @obj.video_ram_size.nil? -%>
39
+ #hyper.video_ram_size = '1GiB'
40
+ <% else -%>
41
+ hyper.video_ram_size = '<%= @obj.video_ram_size -%>'
42
+ <% end -%>
43
+
44
+ # Is ACPI enabled?
45
+ <% if @obj.nil? || @obj.acpi_enabled.nil? -%>
46
+ #hyper.acpi_enabled = true
47
+ <% else -%>
48
+ hyper.acpi_enabled = <%= @obj.acpi_enabled %>
49
+ <% end -%>
50
+
51
+ # Should PAE (Processor Address Extensions) enabled?
52
+ <% if @obj.nil? || @obj.pae_enabled.nil? -%>
53
+ #hyper.pae_enabled = true
54
+ <% else -%>
55
+ hyper.pae_enabled = <%= @obj.pae_enabled %>
56
+ <% end -%>
57
+
58
+ # Should H/w Virtualization for Guest be enabled
59
+ <% if @obj.nil? || @obj.hw_virt_enabled.nil? -%>
60
+ #hyper.hw_virt_enabled = true
61
+ <% else -%>
62
+ hyper.hw_virt_enabled = <%= @obj.hw_virt_enabled %>
63
+ <% end -%>
64
+
65
+ # Should nested paging for guest be enabled
66
+ <% if @obj.nil? || @obj.hw_nested_pages.nil? -%>
67
+ #hyper.hw_nested_pages = true
68
+ <% else -%>
69
+ hyper.hw_nested_pages = <%= @obj.hw_nested_pages %>
70
+ <% end -%>
71
+
72
+ # Should Hypervisor use large pages for this guest
73
+ <% if @obj.nil? || @obj.use_large_pages.nil? -%>
74
+ #hyper.use_large_pages = true
75
+ <% else -%>
76
+ hyper.use_large_pages = <%= @obj.use_large_pages %>
77
+ <% end -%>
78
+
79
+ # Should the guest run in unrestricted mode
80
+ <% if @obj.nil? || @obj.unrestricted_guest_mode.nil? -%>
81
+ #hyper.unrestricted_guest_mode = false
82
+ <% else -%>
83
+ hyper.unrestricted_guest_mode = <%= @obj.unrestricted_guest_mode %>
84
+ <% end -%>
85
+
86
+ # Should 3d acceleration be enabled for Video
87
+ <% if @obj.nil? || @obj.video_3d_acceleration.nil? -%>
88
+ #hyper.video_3d_acceleration = false
89
+ <% else -%>
90
+ hyper.video_3d_acceleration = <%= @obj.video_3d_acceleration %>
91
+ <% end -%>
92
+
93
+ # Should EFI firmware be used instead of bios
94
+ <% if @obj.nil? || @obj.use_efi.nil? -%>
95
+ #hyper.use_efi = false
96
+ <% else -%>
97
+ hyper.use_efi = <%= @obj.use_efi %>
98
+ <% end -%>
99
+
100
+ # Guest memory balloon size
101
+ <% if @obj.nil? || @obj.guest_balloon_size.nil? -%>
102
+ #hyper.guest_balloon_size = '0GiB'
103
+ <% else -%>
104
+ hyper.guest_balloon_size = '<%= @obj.guest_balloon_size -%>'
105
+ <% end -%>
106
+
107
+ <% if @obj.nil? -%>
108
+ #end
109
+ <% else -%>
110
+ end
111
+ <% end -%>
@@ -0,0 +1,28 @@
1
+
2
+ # Define Keyboard layout for this OS
3
+ <% if @obj.nil? -%>
4
+ #os.<%= @name -%> do |keyboard|
5
+ <% else -%>
6
+ os.<%= @name -%> do |keyboard|
7
+ <% end -%>
8
+
9
+ # Layout code for the keyboard to be used for this OS.
10
+ <% if @obj.nil? || @obj.layout.nil? -%>
11
+ #keyboard.layout = 'us'
12
+ <% else -%>
13
+ keyboard.layout = '<%= @obj.layout -%>'
14
+ <% end -%>
15
+
16
+ # Layout Variant for the keyboard to be used for this OS.
17
+ # Usually this is not required.
18
+ <% if @obj.nil? || @obj.variant.nil? -%>
19
+ #keyboard.variant = 'us'
20
+ <% else -%>
21
+ #keyboard.variant = '<%= @obj.variant -%>'
22
+ <% end -%>
23
+
24
+ <% if @obj.nil? -%>
25
+ #end
26
+ <% else -%>
27
+ end
28
+ <% end -%>
@@ -0,0 +1,31 @@
1
+
2
+ # Define Locales for this OS
3
+ <% if @obj.nil? -%>
4
+ #os.<%= @name -%> do |locale|
5
+ <% else -%>
6
+ os.<%= @name -%> do |locale|
7
+ <% end -%>
8
+
9
+ # The default locale for the OS. The Values are standard Locale values.
10
+ # They can also be prefixed with a specified encoding. If no encoding
11
+ # is specified then by default, it is 'UTF-8' (e.g.) 'en_US.UTF-8'
12
+ <% if @obj.nil? || @obj.default.nil? -%>
13
+ #locale.default = 'en_US'
14
+ <% else -%>
15
+ locale.default = "<%= @obj.default -%>"
16
+ <% end -%>
17
+
18
+ # Additional locales that ought to be installed for this OS. Depending
19
+ # upon the OS, the Installer will install additional language packs to
20
+ # support these locales.
21
+ <% if @obj.nil? || @obj.supported.nil? -%>
22
+ #locale.supported = ['en_IN', 'en_GB']
23
+ <% else -%>
24
+ locale.supported = <%= @obj.supported.to_s %>
25
+ <% end -%>
26
+
27
+ <% if @obj.nil? -%>
28
+ #end
29
+ <% else -%>
30
+ end
31
+ <% end -%>
@@ -0,0 +1,68 @@
1
+
2
+ # Define Network Options for this OS
3
+ <% if @obj.nil? -%>
4
+ #os.<%= @name -%> do |net|
5
+ <% else -%>
6
+ os.<%= @name -%> do |net|
7
+ <% end -%>
8
+
9
+ # The Name of the Network interface. This is mandatory, even though it is
10
+ # only useful for some Operating Systems.
11
+ <% if @obj.nil? || @obj.interface.nil? -%>
12
+ #net.interface = 'eth0'
13
+ <% else -%>
14
+ net.interface = '<%= @obj.interface -%>'
15
+ <% end -%>
16
+
17
+ # The type of the Network. This can be a combination of the following.
18
+ # PackerFiles::Core::Network::IPV4 => Specifies a IPV4 network.
19
+ # PackerFiles::Core::Network::IPV6 => Specifies a IPV6 network.
20
+ # PackerFiles::Core::Network::STATIC => Specifies a Static network.
21
+ <% if @obj.nil? || @obj.type.nil? -%>
22
+ #net.type = PackerFiles::Core::Network::IPV4
23
+ <% else -%>
24
+ <% value = '' -%>
25
+ <% if (@obj.type & PackerFiles::Core::Network::IPV4) > 0 -%>
26
+ <% value += 'PackerFiles::Core::Network::IPV4' -%>
27
+ <% elsif (@obj.type & PackerFiles::Core::Network::IPV6) > 0 -%>
28
+ <% value += 'PackerFiles::Core::Network::IPV6' -%>
29
+ <% end -%>
30
+ <% if (@obj.type & PackerFiles::Core::Network::STATIC) > 0 -%>
31
+ <% value += ' | PackerFiles::Core::Network::STATIC' -%>
32
+ <% end -%>
33
+ net.type = <%= value %>
34
+ <% end -%>
35
+
36
+ # Static IP address for the interface. Useful only of you set the type as Static.
37
+ <% if @obj.nil? || @obj.ip.nil? -%>
38
+ #net.ip = '10.10.10.10'
39
+ <% else -%>
40
+ net.ip = '<%= @obj.ip -%>'
41
+ <% end -%>
42
+
43
+ # Static network mask for the interface. Useful only of you set the type as Static.
44
+ <% if @obj.nil? || @obj.mask.nil? -%>
45
+ #net.mask = '255.0.0.0'
46
+ <% else -%>
47
+ net.mask = '<%= @obj.mask -%>'
48
+ <% end -%>
49
+
50
+ # Static Gateway address for the interface. Useful only of you set the type as Static.
51
+ <% if @obj.nil? || @obj.gateway.nil? -%>
52
+ #net.gateway = '10.10.10.11'
53
+ <% else -%>
54
+ net.gateway = '<%= @obj.gateway -%>'
55
+ <% end -%>
56
+
57
+ # Static DNS servers for the interface. Useful only of you set the type as Static.
58
+ <% if @obj.nil? || @obj.dns.nil? -%>
59
+ #net.dns = ['10.10.10.10', '20.10.10.10']
60
+ <% else -%>
61
+ net.dns = <%= @obj.dns.to_s %>
62
+ <% end -%>
63
+
64
+ <% if @obj.nil? -%>
65
+ #end
66
+ <% else -%>
67
+ end
68
+ <% end -%>
@@ -0,0 +1,22 @@
1
+
2
+ # Define Packages for this OS to be installed during OS Installation.
3
+ <% if @obj.nil? -%>
4
+ #os.<%= @name -%> do |pkg|
5
+ <% else -%>
6
+ os.<%= @name -%> do |pkg|
7
+ <% end -%>
8
+
9
+ # List of Packages that needs to be installed. Notice the "+=" as
10
+ # this construct always adds to the default packages particular to
11
+ # the given OS.
12
+ <% if @obj.nil? || @obj.list.nil? -%>
13
+ #pkg.list += ['open-ssh-server']
14
+ <% else -%>
15
+ pkg.list += <%= @obj.list.to_s %>
16
+ <% end -%>
17
+
18
+ <% if @obj.nil? -%>
19
+ #end
20
+ <% else -%>
21
+ end
22
+ <% end -%>
@@ -0,0 +1,36 @@
1
+
2
+ # Define TimeZone for this OS
3
+ <% if @obj.nil? -%>
4
+ #os.<%= @name -%> do |timezone|
5
+ <% else -%>
6
+ os.<%= @name -%> do |timezone|
7
+ <% end -%>
8
+
9
+ # Should the OS use UTC. By default this is true.
10
+ <% if @obj.nil? || @obj.utc.nil? -%>
11
+ #timezone.utc = true
12
+ <% else -%>
13
+ timezone.utc = <%= @obj.utc %>
14
+ <% end -%>
15
+
16
+ # Specify the timezone for this OS. If you do not want to specify
17
+ # it be sure to enable the auto option to discover the time zone
18
+ # automatically based on the host IP address.
19
+ <% if @obj.nil? || @obj.zone.nil? -%>
20
+ #timezone.zone = 'US/Eastern'
21
+ <% else -%>
22
+ timezone.zone = '<%= @obj.zone -%>'
23
+ <% end -%>
24
+
25
+ # Set this to true, if you want timezone to be automatic.
26
+ <% if @obj.nil? || @obj.auto.nil? -%>
27
+ #timezone.auto = false
28
+ <% else -%>
29
+ timezone.auto = <%= @obj.auto %>
30
+ <% end -%>
31
+
32
+ <% if @obj.nil? -%>
33
+ #end
34
+ <% else -%>
35
+ end
36
+ <% end -%>
@@ -0,0 +1,48 @@
1
+
2
+ # Define Initial User for this OS
3
+ <% if @obj.nil? -%>
4
+ #os.<%= @name -%> do |user|
5
+ <% else -%>
6
+ os.<%= @name -%> do |user|
7
+ <% end -%>
8
+
9
+ # User Login ID. This parameter is mandatory.
10
+ <% if @obj.nil? || @obj.login.nil? -%>
11
+ #user.login = 'login-id'
12
+ <% else -%>
13
+ user.login = '<%= @obj.login -%>'
14
+ <% end -%>
15
+
16
+ # User Full name . This parameter is mandatory.
17
+ <% if @obj.nil? || @obj.name.nil? -%>
18
+ #user.name = 'User Full Name'
19
+ <% else -%>
20
+ user.name = '<%= @obj.name -%>'
21
+ <% end -%>
22
+
23
+ # User Password . This parameter is mandatory.
24
+ <% if @obj.nil? || @obj.password.nil? -%>
25
+ #user.password = 'PASSWORD-CHANGE-ME'
26
+ <% else -%>
27
+ user.password = '<%= @obj.password -%>'
28
+ <% end -%>
29
+
30
+ # User ID . This parameter is Optional.
31
+ <% if @obj.nil? || @obj.uid.nil? -%>
32
+ #user.uid = 1000
33
+ <% else -%>
34
+ user.uid = <%= @obj.uid %>
35
+ <% end -%>
36
+
37
+ # Groups to which the user belongs to. This is an optional setting.
38
+ <% if @obj.nil? || @obj.groups.nil? -%>
39
+ #user.groups = []
40
+ <% else -%>
41
+ user.groups = <%= @obj.groups.to_s %>
42
+ <% end -%>
43
+
44
+ <% if @obj.nil? -%>
45
+ #end
46
+ <% else -%>
47
+ end
48
+ <% end -%>
@@ -0,0 +1,116 @@
1
+ # Requires
2
+ require 'Core/CDImage'
3
+ require 'Core/Exceptions'
4
+ require 'Virtual/Hypervisors'
5
+ require 'Provision/Provisioners'
6
+ require 'Utils/Generator'
7
+ require 'Utils/TypeAccessor'
8
+
9
+ module PackerFiles
10
+
11
+ # The Builder class is used as the base for building OS classes
12
+ # that generate all the files required for Packer to work properly for
13
+ # a given OS
14
+ class Builder < Utils::TypeAccessor
15
+
16
+ # attr_accessor for output directory
17
+ attr_accessor :OutDir
18
+
19
+ # Type accessors for mandatory common objects
20
+ type_accessor Core::CDImage
21
+ type_accessor Virtual::Hypervisors
22
+
23
+ # Type accessor for optional Provisioners.
24
+ type_accessor Provisioners, 'Provision', true
25
+
26
+ # Versions supported by this class
27
+ def self.versions
28
+ []
29
+ end
30
+
31
+ # Name of this class as exposed to others
32
+ def name
33
+ self.class.name.gsub('PackerFiles::','')
34
+ end
35
+
36
+ # Name of the http directory
37
+ def http_dir
38
+ File.join(@OutDir, 'http')
39
+ end
40
+
41
+ # Name of the top level JSON file
42
+ def packer_json_file
43
+ rel = self.CDImage.release
44
+ arch = self.CDImage.arch
45
+ file = self.name.gsub('::', '-') + "-#{rel}-#{arch}.json"
46
+ File.join(@OutDir, file)
47
+ end
48
+
49
+ # Base class function that needs to be called first to handle
50
+ # parameter validation.
51
+ def Generate
52
+ if @OutDir.nil?
53
+ raise ArgumentError.new('Need to provide output directory')
54
+ end
55
+
56
+ # Track through all the accessors in the ancestry tree and check
57
+ # if non-optional type accessors are missing.
58
+ index = self.class.ancestors.index(Builder)
59
+ ancestors = self.class.ancestors.slice(0, index + 1 )
60
+ ancestors.each do |klass|
61
+ hash = klass.type_accessors
62
+ next if hash.nil?
63
+ hash.each_pair do |func, type_data|
64
+ opt = type_data.last
65
+ obj = self.method(func).call
66
+ raise Utils::MissingAccessor.new(func, self.name) if obj.nil? && !opt
67
+ end
68
+ end
69
+
70
+ # Normalize CD Image by calling the cd image hook of the derived class.
71
+ cd_image_hook
72
+ self.CDImage.normalize
73
+
74
+ # Call Hook for derived classes to add their functionality.
75
+ generate_hook
76
+
77
+ # Generate Packer File
78
+ generate_packer_file
79
+
80
+ end
81
+
82
+ # Generate the Various Packer File components
83
+ private
84
+ def generate_packer_file
85
+
86
+ # Manage various packer file components via the generator
87
+ gen = Utils::Generator.new
88
+
89
+ # handle hypervisors
90
+ self.Hypervisors.convert(gen, self)
91
+
92
+ # handle provisioners
93
+ self.Provision.convert(gen, self) if !self.Provision.nil?
94
+
95
+ # Finally generate the JSON for packer
96
+ gen.create_json(packer_json_file)
97
+
98
+ end
99
+
100
+ # Various hook functions
101
+ def generate_hook; end
102
+ def cd_image_hook; end
103
+ def vbox_converter_hook(gen); end
104
+ def vmware_converter_hook(gen); end
105
+ def kvm_converter_hook(gen); end
106
+ def boot_command; end
107
+ def shutdown_command; end
108
+ def guest_os_type; end
109
+ def vmware_guest_os_type; end
110
+ def vmware_guest_os_flavor; end
111
+ def run_command_as_root; end
112
+ def enable_root_for_user; end
113
+ def disable_root_for_user; end
114
+
115
+ end
116
+ end
@@ -0,0 +1,81 @@
1
+ # Requires
2
+ require 'uri'
3
+ require 'open-uri'
4
+ require "Core/CDImage"
5
+ require "Core/Exceptions"
6
+ require "Utils/AutoZone"
7
+
8
+ # An implementation for CDImage which lists all available CentOS CD Mirrors
9
+ module PackerFiles
10
+ module CentOS
11
+ class CD < Core::CDImageImpl
12
+
13
+ # Index URL which contains all the CentOS Download mirror list
14
+ @@index = 'http://www.centos.org/download/full-mirrorlist.csv'
15
+
16
+ # Override method for getting the ISO name
17
+ def get_iso_name_pattern
18
+ 'CentOS-@release@.*-@arch@.*-DVD1.*.iso'
19
+ end
20
+
21
+ # Override method for getting checksums
22
+ def get_check_sum_pattern
23
+ 'md5sum.txt'
24
+ end
25
+
26
+ # Override method for checksum type
27
+ def get_check_sum_type
28
+ 'md5'
29
+ end
30
+
31
+ # Override method for getting index URLs.
32
+ def index_urls
33
+ mirrors = get_mirrors
34
+ geo = get_matched_mirror_lines(mirrors)
35
+ http = geo.map{|m| m[4].gsub('"', '')}
36
+ http.map{|m| URI::join(m, '@release@/', 'isos/', '@arch@/').to_s}
37
+ end
38
+
39
+ # Read the full mirror list CSV file and convert it into a searchable
40
+ # array.
41
+ private
42
+ def get_mirrors
43
+ content = open(@@index) {|f| f.read}
44
+ top_arr = content.split("\n")
45
+ top_arr.map {|line| line.split(",")}
46
+ end
47
+
48
+ # Get matched mirror entries, given a country code and region code
49
+ private
50
+ def get_matched_mirror_lines(mirrors)
51
+ json = Utils::AutoZone.new.JSON
52
+ country_code = json['country_code']
53
+ country_name = json['country']
54
+ region_code = json['region_code']
55
+
56
+ # Check if country code matches and if it does, then try to
57
+ # match region code as well.
58
+ cc = mirrors.select {|m| m[0] == '"' + country_code + '"'}
59
+ if !cc.empty?
60
+ region = cc.select {|m| m[1] == '"' + region_code + '"'}
61
+ return region if !region.empty?
62
+ return cc
63
+ end
64
+
65
+ # Country code does not match. Try matching country name
66
+ cn = mirrors.select {|m| m[1] == '"' + country_name + '"'}
67
+ return cn if !cn.empty?
68
+
69
+ # OK. even that is not working. Let us try matching country name
70
+ # on the first element
71
+ cp = mirrors.select {|m| m[0] == '"' + country_name + '"'}
72
+ if cp.empty?
73
+ raise Core::EmptyArrayException.new('No Mirror for CentOS?')
74
+ else
75
+ return cp
76
+ end
77
+ end
78
+
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,64 @@
1
+ # Requires
2
+ require 'rubygems'
3
+
4
+ # OS class that handles details for generating Kickstart files for CentOS
5
+ # Servers.
6
+ module PackerFiles
7
+ module CentOS
8
+
9
+ class Kickstart
10
+
11
+ # Constructor. The Kickstart file name is the name of the file
12
+ # that will be written to.
13
+ def initialize(filename)
14
+ @kickstart = filename
15
+ create_file
16
+ end
17
+
18
+ # Serializes the given object and write out the content
19
+ # in the output file.
20
+ def convert(obj, os_name)
21
+ file = erb_file(obj, os_name)
22
+ content = PackerFiles.evaluate_erb(file, { "obj" => obj })
23
+ add_content(content)
24
+ end
25
+
26
+ # Evaluate a partially specified file name (should be in the Gem's
27
+ # file list though) and add the content to the @kickstart file
28
+ def eval_file(file_name, hash)
29
+ erb_file = PackerFiles.DirPath(file_name).first
30
+ content = PackerFiles.evaluate_erb(erb_file, hash)
31
+ add_content(content)
32
+ end
33
+
34
+ # Given an object, figure out the class name and return back the correct
35
+ # erb file name.
36
+ private
37
+ def erb_file(obj, os_name)
38
+
39
+ erb_file = File.join(os_name, obj.class.name.gsub(/.*::/,'') + '_erb.rb')
40
+ erb_path = PackerFiles.DirPath(erb_file)
41
+
42
+ if erb_path.nil? || erb_path.empty?
43
+ raise RuntimeError.new("Template Path #{erb_file} does not exist")
44
+ end
45
+ return erb_path.first
46
+ end
47
+
48
+ # Create a new file with no content
49
+ private
50
+ def create_file
51
+ basename = File.dirname(@kickstart)
52
+ FileUtils.mkdir_p(basename) if !Dir.exist?(basename)
53
+ File.open(@kickstart, 'w') {|f| f.write ''}
54
+ end
55
+
56
+ # Add content to the preseed file
57
+ private
58
+ def add_content(content)
59
+ File.open(@kickstart, 'a') {|f| f.write(content) }
60
+ end
61
+
62
+ end
63
+ end
64
+ end