vanagon 0.3.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +13 -0
  3. data/README.md +175 -0
  4. data/bin/build +33 -0
  5. data/bin/devkit +22 -0
  6. data/bin/repo +26 -0
  7. data/bin/ship +15 -0
  8. data/lib/vanagon.rb +8 -0
  9. data/lib/vanagon/common.rb +2 -0
  10. data/lib/vanagon/common/pathname.rb +87 -0
  11. data/lib/vanagon/common/user.rb +25 -0
  12. data/lib/vanagon/component.rb +157 -0
  13. data/lib/vanagon/component/dsl.rb +307 -0
  14. data/lib/vanagon/component/source.rb +66 -0
  15. data/lib/vanagon/component/source/git.rb +60 -0
  16. data/lib/vanagon/component/source/http.rb +158 -0
  17. data/lib/vanagon/driver.rb +112 -0
  18. data/lib/vanagon/engine/base.rb +82 -0
  19. data/lib/vanagon/engine/docker.rb +40 -0
  20. data/lib/vanagon/engine/local.rb +40 -0
  21. data/lib/vanagon/engine/pooler.rb +85 -0
  22. data/lib/vanagon/errors.rb +28 -0
  23. data/lib/vanagon/extensions/string.rb +11 -0
  24. data/lib/vanagon/optparse.rb +62 -0
  25. data/lib/vanagon/platform.rb +245 -0
  26. data/lib/vanagon/platform/deb.rb +71 -0
  27. data/lib/vanagon/platform/dsl.rb +293 -0
  28. data/lib/vanagon/platform/osx.rb +100 -0
  29. data/lib/vanagon/platform/rpm.rb +76 -0
  30. data/lib/vanagon/platform/rpm/wrl.rb +39 -0
  31. data/lib/vanagon/platform/solaris_10.rb +182 -0
  32. data/lib/vanagon/platform/solaris_11.rb +138 -0
  33. data/lib/vanagon/platform/swix.rb +35 -0
  34. data/lib/vanagon/project.rb +251 -0
  35. data/lib/vanagon/project/dsl.rb +218 -0
  36. data/lib/vanagon/utilities.rb +299 -0
  37. data/spec/fixures/component/invalid-test-fixture.json +3 -0
  38. data/spec/fixures/component/mcollective.service +1 -0
  39. data/spec/fixures/component/test-fixture.json +4 -0
  40. data/spec/lib/vanagon/common/pathname_spec.rb +103 -0
  41. data/spec/lib/vanagon/common/user_spec.rb +36 -0
  42. data/spec/lib/vanagon/component/dsl_spec.rb +443 -0
  43. data/spec/lib/vanagon/component/source/git_spec.rb +19 -0
  44. data/spec/lib/vanagon/component/source/http_spec.rb +43 -0
  45. data/spec/lib/vanagon/component/source_spec.rb +99 -0
  46. data/spec/lib/vanagon/component_spec.rb +22 -0
  47. data/spec/lib/vanagon/engine/base_spec.rb +40 -0
  48. data/spec/lib/vanagon/engine/docker_spec.rb +40 -0
  49. data/spec/lib/vanagon/engine/pooler_spec.rb +54 -0
  50. data/spec/lib/vanagon/platform/deb_spec.rb +60 -0
  51. data/spec/lib/vanagon/platform/dsl_spec.rb +128 -0
  52. data/spec/lib/vanagon/platform/rpm_spec.rb +41 -0
  53. data/spec/lib/vanagon/platform/solaris_11_spec.rb +44 -0
  54. data/spec/lib/vanagon/platform_spec.rb +53 -0
  55. data/spec/lib/vanagon/project/dsl_spec.rb +203 -0
  56. data/spec/lib/vanagon/project_spec.rb +44 -0
  57. data/spec/lib/vanagon/utilities_spec.rb +140 -0
  58. data/templates/Makefile.erb +116 -0
  59. data/templates/deb/changelog.erb +5 -0
  60. data/templates/deb/conffiles.erb +3 -0
  61. data/templates/deb/control.erb +21 -0
  62. data/templates/deb/dirs.erb +3 -0
  63. data/templates/deb/docs.erb +1 -0
  64. data/templates/deb/install.erb +3 -0
  65. data/templates/deb/postinst.erb +46 -0
  66. data/templates/deb/postrm.erb +15 -0
  67. data/templates/deb/prerm.erb +17 -0
  68. data/templates/deb/rules.erb +25 -0
  69. data/templates/osx/postinstall.erb +24 -0
  70. data/templates/osx/preinstall.erb +19 -0
  71. data/templates/osx/project-installer.xml.erb +19 -0
  72. data/templates/rpm/project.spec.erb +217 -0
  73. data/templates/solaris/10/depend.erb +3 -0
  74. data/templates/solaris/10/pkginfo.erb +13 -0
  75. data/templates/solaris/10/postinstall.erb +37 -0
  76. data/templates/solaris/10/preinstall.erb +7 -0
  77. data/templates/solaris/10/preremove.erb +6 -0
  78. data/templates/solaris/10/proto.erb +5 -0
  79. data/templates/solaris/11/p5m.erb +73 -0
  80. metadata +172 -0
@@ -0,0 +1,245 @@
1
+ require 'vanagon/platform/dsl'
2
+
3
+ class Vanagon
4
+ class Platform
5
+ attr_accessor :make, :servicedir, :defaultdir, :provisioning, :num_cores, :tar
6
+ attr_accessor :build_dependencies, :name, :vmpooler_template, :cflags, :ldflags, :settings
7
+ attr_accessor :servicetype, :patch, :architecture, :codename, :os_name, :os_version
8
+ attr_accessor :docker_image, :ssh_port, :rpmbuild, :install, :platform_triple
9
+
10
+ # Platform names currently contain some information about the platform. Fields
11
+ # within the name are delimited by the '-' character, and this regex can be used to
12
+ # extract those fields.
13
+ PLATFORM_REGEX = /^(.*)-(.*)-(.*)$/
14
+
15
+ # Loads a given platform from the configdir
16
+ #
17
+ # @param name [String] the name of the platform
18
+ # @param configdir [String] the path to the platform config file
19
+ # @return [Vanagon::Platform] the platform as specified in the platform config
20
+ # @raise if the instance_eval on Platform fails, the exception is reraised
21
+ def self.load_platform(name, configdir)
22
+ platfile = File.join(configdir, "#{name}.rb")
23
+ code = File.read(platfile)
24
+ dsl = Vanagon::Platform::DSL.new(name)
25
+ dsl.instance_eval(code, __FILE__, __LINE__)
26
+ dsl._platform
27
+ rescue => e
28
+ puts "Error loading platform '#{name}' using '#{platfile}':"
29
+ puts e
30
+ puts e.backtrace.join("\n")
31
+ raise e
32
+ end
33
+
34
+ # Generate the scripts required to add a group to the package generated.
35
+ # This will also update the group if it has changed.
36
+ #
37
+ # @param user [Vanagon::Common::User] the user to reference for the group
38
+ # @return [String] the commands required to add a group to the system
39
+ def add_group(user)
40
+ cmd_args = ["'#{user.group}'"]
41
+ cmd_args.unshift '--system' if user.is_system
42
+
43
+ groupadd_args = cmd_args.join "\s"
44
+ groupmod_args = (cmd_args - ["--system"]).join "\s"
45
+
46
+ return <<-HERE.undent
47
+ if getent group '#{user.group}' > /dev/null 2>&1; then
48
+ /usr/sbin/groupmod #{groupmod_args}
49
+ else
50
+ /usr/sbin/groupadd #{groupadd_args}
51
+ fi
52
+ HERE
53
+ end
54
+
55
+ # Generate the scripts required to add a user to the package generated.
56
+ # This will also update the user if it has changed.
57
+ #
58
+ # @param user [Vanagon::Common::User] the user to create
59
+ # @return [String] the commands required to add a user to the system
60
+ def add_user(user)
61
+ cmd_args = ["'#{user.name}'"]
62
+ cmd_args.unshift "--home '#{user.homedir}'" if user.homedir
63
+ if user.shell
64
+ cmd_args.unshift "--shell '#{user.shell}'"
65
+ elsif user.is_system
66
+ cmd_args.unshift "--shell '/usr/sbin/nologin'"
67
+ end
68
+ cmd_args.unshift "--gid '#{user.group}'" if user.group
69
+ cmd_args.unshift '--system' if user.is_system
70
+
71
+ # Collapse the cmd_args array into a string that can be used
72
+ # as an argument to `useradd`
73
+ useradd_args = cmd_args.join "\s"
74
+
75
+ # Collapse the cmd_args array into a string that can be used
76
+ # as an argument to `usermod`; If this is a system account,
77
+ # then specify it as such for user addition only (strip
78
+ # --system from usermod_args)
79
+ usermod_args = (cmd_args - ["--system"]).join "\s"
80
+
81
+ return <<-HERE.undent
82
+ if getent passwd '#{user.name}' > /dev/null 2>&1; then
83
+ /usr/sbin/usermod #{useradd_args}
84
+ else
85
+ /usr/sbin/useradd #{usermod_args}
86
+ fi
87
+ HERE
88
+ end
89
+
90
+ # Platform constructor. Takes just the name. Also sets the @name, @os_name,
91
+ # \@os_version and @architecture instance attributes as a side effect
92
+ #
93
+ # @param name [String] name of the platform
94
+ # @return [Vanagon::Platform] the platform with the given name
95
+ def initialize(name)
96
+ @name = name
97
+ @os_name = os_name
98
+ @os_version = os_version
99
+ @architecture = architecture
100
+ @ssh_port = 22
101
+ @provisioning = []
102
+ @install ||= "install"
103
+ end
104
+
105
+ # This allows instance variables to be accessed using the hash lookup syntax
106
+ def [](key)
107
+ if instance_variable_get("@#{key}")
108
+ instance_variable_get("@#{key}")
109
+ end
110
+ end
111
+
112
+ # Sets and gets the name of the operating system for the platform.
113
+ # Also has the side effect of setting the @os_name instance attribute
114
+ #
115
+ # @return [String] the operating system name as specified in the platform
116
+ def os_name
117
+ @os_name ||= @name.match(PLATFORM_REGEX)[1]
118
+ end
119
+
120
+ # Sets and gets the version of the operating system for the platform.
121
+ # Also has the side effect of setting the @os_version instance attribute
122
+ #
123
+ # @return [String] the operating system version as specified in the platform
124
+ def os_version
125
+ @os_version ||= @name.match(PLATFORM_REGEX)[2]
126
+ end
127
+
128
+ # Sets and gets the architecture of the platform.
129
+ # Also has the side effect of setting the @architecture instance attribute
130
+ #
131
+ # @return [String] the architecture of the platform
132
+ def architecture
133
+ @architecture ||= @name.match(PLATFORM_REGEX)[3]
134
+ end
135
+
136
+ # Utility matcher to determine is the platform is a debian variety
137
+ #
138
+ # @return [true, false] true if it is a debian variety, false otherwise
139
+ def is_deb?
140
+ return !!@name.match(/^(debian|ubuntu|cumulus)-.*$/)
141
+ end
142
+
143
+ # Utility matcher to determine is the platform is a redhat variety or
144
+ # uses rpm under the hood
145
+ #
146
+ # @return [true, false] true if it is a redhat variety or uses rpm
147
+ # under the hood, false otherwise
148
+ def is_rpm?
149
+ return !!@name.match(/^(aix|cisco-wrlinux|el|eos|fedora|huaweios|nxos|sles)-.*$/)
150
+ end
151
+
152
+ # Utility matcher to determine is the platform is an enterprise linux variety
153
+ #
154
+ # @return [true, false] true if it is a enterprise linux variety, false otherwise
155
+ def is_el?
156
+ return !!@name.match(/^el-.*$/)
157
+ end
158
+
159
+ # Utility matcher to determine is the platform is a sles variety
160
+ #
161
+ # @return [true, false] true if it is a sles variety, false otherwise
162
+ def is_sles?
163
+ return !!@name.match(/^sles-.*$/)
164
+ end
165
+
166
+ # Utility matcher to determine is the platform is a fedora variety
167
+ #
168
+ # @return [true, false] true if it is a fedora variety, false otherwise
169
+ def is_fedora?
170
+ return !!@name.match(/^fedora-.*$/)
171
+ end
172
+
173
+ # Utility matcher to determine is the platform is an aix variety
174
+ #
175
+ # @return [true, false] true if it is an aix variety, false otherwise
176
+ def is_aix?
177
+ return !!@name.match(/^aix-.*$/)
178
+ end
179
+
180
+ # Utility matcher to determine is the platform is an eos variety
181
+ #
182
+ # @return [true, false] true if it is an eos variety, false otherwise
183
+ def is_eos?
184
+ return !!@name.match(/^eos-.*$/)
185
+ end
186
+
187
+ # Utility matcher to determine is the platform is a HuaweiOS variety
188
+ #
189
+ # @return [true, false] true if it is a HuaweiOS variety, false otherwise
190
+ def is_huaweios?
191
+ return !!@name.match(/^huaweios-.*$/)
192
+ end
193
+
194
+ # Utility matcher to determine is the platform is an nxos variety
195
+ #
196
+ # @return [true, false] true if it is an nxos variety, false otherwise
197
+ def is_nxos?
198
+ return !!@name.match(/^nxos-.*$/)
199
+ end
200
+
201
+ # Utility matcher to determine is the platform is a cisco-wrlinux
202
+ # variety
203
+ #
204
+ # @return [true, false] true if it is a cisco-wrlinux variety, false
205
+ # otherwise
206
+ def is_cisco_wrlinux?
207
+ return !!@name.match(/^cisco-wrlinux-.*$/)
208
+ end
209
+
210
+ # Utility matcher to determine is the platform is an osx variety
211
+ #
212
+ # @return [true, false] true if it is an osx variety, false otherwise
213
+ def is_osx?
214
+ return !!@name.match(/^osx-.*$/)
215
+ end
216
+
217
+ # Utility matcher to determine is the platform is a solaris variety
218
+ #
219
+ # @return [true, false] true if it is an solaris variety, false otherwise
220
+ def is_solaris?
221
+ return !!@name.match(/^solaris-.*$/)
222
+ end
223
+
224
+ # Utility matcher to determine is the platform is a unix variety
225
+ #
226
+ # @return [true, false] true if it is a unix variety, false otherwise
227
+ def is_unix?
228
+ return !!@name.match(/^(solaris|aix|osx)-.*$/)
229
+ end
230
+
231
+ # Utility matcher to determine is the platform is a windows variety
232
+ #
233
+ # @return [true, false] true if it is a windows variety, false otherwise
234
+ def is_windows?
235
+ return !!@name.match(/^win-.*$/)
236
+ end
237
+
238
+ # Utility matcher to determine is the platform is a linux variety
239
+ #
240
+ # @return [true, false] true if it is a linux variety, false otherwise
241
+ def is_linux?
242
+ return (!is_windows? && !is_unix?)
243
+ end
244
+ end
245
+ end
@@ -0,0 +1,71 @@
1
+ class Vanagon
2
+ class Platform
3
+ class DEB < Vanagon::Platform
4
+ # The specific bits used to generate a debian package for a given project
5
+ #
6
+ # @param project [Vanagon::Project] project to build a debian package of
7
+ # @return [Array] list of commands required to build a debian package for the given project from a tarball
8
+ def generate_package(project)
9
+ target_dir = project.repo ? output_dir(project.repo) : output_dir
10
+ ["mkdir -p output/#{target_dir}",
11
+ "mkdir -p $(tempdir)/#{project.name}-#{project.version}",
12
+ "cp #{project.name}-#{project.version}.tar.gz $(tempdir)/#{project.name}_#{project.version}.orig.tar.gz",
13
+ "cat file-list >> debian/install",
14
+ "cp -pr debian $(tempdir)/#{project.name}-#{project.version}",
15
+ "gunzip -c #{project.name}-#{project.version}.tar.gz | '#{@tar}' -C '$(tempdir)/#{project.name}-#{project.version}' --strip-components 1 -xf -",
16
+ "sed -i 's/\ /?/g' $(tempdir)/#{project.name}-#{project.version}/debian/install",
17
+ "(cd $(tempdir)/#{project.name}-#{project.version}; debuild --no-lintian -uc -us)",
18
+ "cp $(tempdir)/*.deb ./output/#{target_dir}"]
19
+ end
20
+
21
+ # Method to generate the files required to build a debian package for the project
22
+ #
23
+ # @param workdir [String] working directory to stage the evaluated templates in
24
+ # @param name [String] name of the project
25
+ # @param binding [Binding] binding to use in evaluating the packaging templates
26
+ def generate_packaging_artifacts(workdir, name, binding)
27
+ deb_dir = File.join(workdir, "debian")
28
+ FileUtils.mkdir_p(deb_dir)
29
+
30
+ # Lots of templates here
31
+ ["changelog", "conffiles", "control", "docs", "dirs", "install", "postinst", "postrm", "prerm", "rules"].each do |deb_file|
32
+ erb_file(File.join(VANAGON_ROOT, "templates/deb/#{deb_file}.erb"), File.join(deb_dir, deb_file), false, { :binding => binding })
33
+ end
34
+
35
+ # These could be templates, but their content is static, so that seems weird.
36
+ File.open(File.join(deb_dir, "compat"), "w") { |f| f.puts("7") }
37
+ FileUtils.mkdir_p(File.join(deb_dir, "source"))
38
+ File.open(File.join(deb_dir, "source", "format"), "w") { |f| f.puts("3.0 (quilt)") }
39
+ end
40
+
41
+ # Method to derive the package name for the project
42
+ #
43
+ # @param project [Vanagon::Project] project to name
44
+ # @return [String] name of the debian package for this project
45
+ def package_name(project)
46
+ "#{project.name}_#{project.version}-#{project.release}#{@codename}_#{project.noarch ? 'all' : @architecture}.deb"
47
+ end
48
+
49
+ # Get the expected output dir for the debian packages. This allows us to
50
+ # use some standard tools to ship internally.
51
+ #
52
+ # @return [String] relative path to where debian packages should be staged
53
+ def output_dir(target_repo = "")
54
+ File.join("deb", @codename, target_repo)
55
+ end
56
+
57
+ # Constructor. Sets up some defaults for the debian platform and calls the parent constructor
58
+ #
59
+ # @param name [String] name of the platform
60
+ # @return [Vanagon::Platform::DEB] the deb derived platform with the given name
61
+ def initialize(name)
62
+ @name = name
63
+ @make = "/usr/bin/make"
64
+ @tar = "tar"
65
+ @patch = "/usr/bin/patch"
66
+ @num_cores = "/usr/bin/nproc"
67
+ super(name)
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,293 @@
1
+ require 'vanagon/platform/deb'
2
+ require 'vanagon/platform/rpm'
3
+ require 'vanagon/platform/rpm/wrl'
4
+ require 'vanagon/platform/swix'
5
+ require 'vanagon/platform/osx'
6
+ require 'vanagon/platform/solaris_10'
7
+ require 'vanagon/platform/solaris_11'
8
+ require 'securerandom'
9
+ require 'uri'
10
+
11
+ class Vanagon
12
+ class Platform
13
+ class DSL
14
+ # Constructor for the DSL object
15
+ #
16
+ # @param name [String] name of the platform
17
+ # @return [Vanagon::Platform::DSL] A DSL object to describe the {Vanagon::Platform}
18
+ def initialize(name)
19
+ @name = name
20
+ end
21
+
22
+ # Primary way of interacting with the DSL. Also a simple factory to get the right platform object.
23
+ #
24
+ # @param name [String] name of the platform
25
+ # @param block [Proc] DSL definition of the platform to call
26
+ def platform(name, &block)
27
+ @platform = case name
28
+ when /^(aix|cisco-wrlinux|el|fedora|nxos|sles)-/
29
+ Vanagon::Platform::RPM.new(@name)
30
+ when /^huaweios-/
31
+ Vanagon::Platform::RPM::WRL.new(@name)
32
+ when /^(cumulus|debian|ubuntu)-/
33
+ Vanagon::Platform::DEB.new(@name)
34
+ when /^eos-/
35
+ Vanagon::Platform::RPM::Swix.new(@name)
36
+ when /^osx-/
37
+ Vanagon::Platform::OSX.new(@name)
38
+ when /^solaris-10/
39
+ Vanagon::Platform::Solaris10.new(@name)
40
+ when /^solaris-11/
41
+ Vanagon::Platform::Solaris11.new(@name)
42
+ else
43
+ fail "Platform not implemented for '#{@name}' yet. Please go do so..."
44
+ end
45
+
46
+ block.call(self)
47
+ @platform
48
+ end
49
+
50
+ # Accessor for the platform.
51
+ #
52
+ # @return [Vanagon::Platform] the platform the DSL methods will be acting against
53
+ def _platform
54
+ @platform
55
+ end
56
+
57
+ # All purpose getter. This object, which is passed to the platform block,
58
+ # won't have easy access to the attributes of the @platform, so we make a
59
+ # getter for each attribute.
60
+ #
61
+ # We only magically handle get_ methods, any other methods just get the
62
+ # standard method_missing treatment.
63
+ #
64
+ def method_missing(method, *args)
65
+ attribute_match = method.to_s.match(/get_(.*)/)
66
+ if attribute_match
67
+ attribute = attribute_match.captures.first
68
+ else
69
+ super
70
+ end
71
+
72
+ @platform.send(attribute)
73
+ end
74
+
75
+ # Set the path to make for the platform
76
+ #
77
+ # @param make_cmd [String] Full path to the make command for the platform
78
+ def make(make_cmd)
79
+ @platform.make = make_cmd
80
+ end
81
+
82
+ # Set the path to tar for the platform
83
+ #
84
+ # @param tar [String] Full path to the tar command for the platform
85
+ def tar(tar_cmd)
86
+ @platform.tar = tar_cmd
87
+ end
88
+
89
+ # Set the path to rpmbuild for the platform
90
+ #
91
+ # @param rpmbuild_cmd [String] Full path to rpmbuild with arguments to be used by default
92
+ def rpmbuild(rpmbuild_cmd)
93
+ @platform.rpmbuild = rpmbuild_cmd
94
+ end
95
+
96
+ # Set the path to the install command
97
+ # @param install_cmd [String] Full path to install with arguments to be used by default
98
+ def install(install_cmd)
99
+ @platform.install = install_cmd
100
+ end
101
+
102
+ # Set the path to patch for the platform
103
+ #
104
+ # @param patch_cmd [String] Full path to the patch command for the platform
105
+ def patch(patch_cmd)
106
+ @platform.patch = patch_cmd
107
+ end
108
+
109
+ # Sets the command to retrieve the number of cores available on a platform.
110
+ #
111
+ # @param num_cores_cmd [String] the command to retrieve the number of available cores on a platform.
112
+ def num_cores(num_cores_cmd)
113
+ @platform.num_cores = num_cores_cmd
114
+ end
115
+
116
+ # Set the command to turn the target machine into a builder for vanagon
117
+ #
118
+ # @param command [String] Command to enable the target machine to build packages for the platform
119
+ def provision_with(command)
120
+ @platform.provisioning << command
121
+ end
122
+
123
+ # Set the command to install any needed build dependencies for the target machine
124
+ #
125
+ # @param command [String] Command to install build dependencies for the target machine
126
+ # @param suffix [String] shell to be run after the main command
127
+ def install_build_dependencies_with(command, suffix = nil)
128
+ @platform.build_dependencies = OpenStruct.new({ :command => command, :suffix => suffix })
129
+ end
130
+
131
+ # Set the directory where service files or init scripts live for the platform
132
+ #
133
+ # @param dir [String] Directory where service files live on the platform
134
+ def servicedir(dir)
135
+ @platform.servicedir = dir
136
+ end
137
+
138
+ # Set the directory where default or sysconfig files live for the platform
139
+ #
140
+ # @param dir [String] Directory where default or sysconfig files live on the platform
141
+ def defaultdir(dir)
142
+ @platform.defaultdir = dir
143
+ end
144
+
145
+ # Set the servicetype for the platform so that services can be installed correctly.
146
+ #
147
+ # @param type [String] service type for the platform ('sysv' for example)
148
+ def servicetype(type)
149
+ @platform.servicetype = type
150
+ end
151
+
152
+ # Set the name of this platform as the vm pooler expects it
153
+ #
154
+ # @param name [String] name of the target template to use from the vmpooler
155
+ def vmpooler_template(name)
156
+ @platform.vmpooler_template = name
157
+ end
158
+
159
+ # Set the name of this platform as the vm pooler expects it
160
+ #
161
+ # @param name [String] name that the pooler uses for this platform
162
+ # @deprecated Please use vmpooler_template instead, this will be removed in a future vanagon release.
163
+ def vcloud_name(name)
164
+ warn "vcloud_name is a deprecated platform DSL method, and will be removed in a future vanagon release. Please use vmpooler_template instead."
165
+ self.vmpooler_template(name)
166
+ end
167
+
168
+ # Set the name of the docker image to use
169
+ #
170
+ # @param name [String] name of the docker image to use
171
+ def docker_image(name)
172
+ @platform.docker_image = name
173
+ end
174
+
175
+ # Set the port for ssh to use if it's not 22
176
+ #
177
+ # @param port [Integer] port number for ssh
178
+ def ssh_port(port = 22)
179
+ @platform.ssh_port = port
180
+ end
181
+
182
+ # Set the platform_triple for the platform
183
+ #
184
+ # @param triple[String] platform_triple for use in building out compiled
185
+ # tools and cross-compilation
186
+ def platform_triple(triple)
187
+ @platform.platform_triple = triple
188
+ end
189
+
190
+ # Set any codename this platform may have (debian for example)
191
+ #
192
+ # @param name [String] codename for this platform (squeeze for example)
193
+ def codename(name)
194
+ @platform.codename = name
195
+ end
196
+
197
+ # Helper to setup a apt repository on a target system
198
+ #
199
+ # @param definition [String] the repo setup file, must be a valid uri, fetched with curl
200
+ # @param gpg_key [String] optional gpg key to be fetched via curl and installed
201
+ def apt_repo(definition, gpg_key = nil)
202
+ # i.e., definition = http://builds.delivery.puppetlabs.net/puppet-agent/0.2.1/repo_configs/deb/pl-puppet-agent-0.2.1-wheezy.list
203
+ # parse the definition and gpg_key if set to ensure they are both valid URIs
204
+ definition = URI.parse definition
205
+ gpg_key = URI.parse gpg_key if gpg_key
206
+
207
+ self.provision_with "apt-get -qq update && apt-get -qq install curl"
208
+ if definition.scheme =~ /^(http|ftp)/
209
+ if File.extname(definition.path) == '.deb'
210
+ # repo definition is an deb (like puppetlabs-release)
211
+ self.provision_with "curl -o local.deb '#{definition}' && dpkg -i local.deb; rm -f local.deb"
212
+ else
213
+ reponame = "#{SecureRandom.hex}-#{File.basename(definition.path)}"
214
+ reponame = "#{reponame}.list" if File.extname(reponame) != '.list'
215
+ self.provision_with "curl -o '/etc/apt/sources.list.d/#{reponame}' '#{definition}'"
216
+ end
217
+ end
218
+
219
+ if gpg_key
220
+ gpgname = "#{SecureRandom.hex}-#{File.basename(gpg_key.path)}"
221
+ gpgname = "#{gpgname}.gpg" if gpgname !~ /\.gpg$/
222
+ self.provision_with "curl -o '/etc/apt/trusted.gpg.d/#{gpgname}' '#{gpg_key}'"
223
+ end
224
+
225
+ self.provision_with "apt-get -qq update"
226
+ end
227
+
228
+ # Helper to setup a yum repository on a target system
229
+ #
230
+ # @param definition [String] the repo setup URI or RPM file
231
+ def yum_repo(definition)
232
+ definition = URI.parse definition
233
+
234
+ self.provision_with "rpm -q curl > /dev/null || yum -y install curl"
235
+ if definition.scheme =~ /^(http|ftp)/
236
+ if File.extname(definition.path) == '.rpm'
237
+ # repo definition is an rpm (like puppetlabs-release)
238
+ if @platform.os_version.to_i < 6
239
+ # This can likely be done with just rpm itself (minus curl) however
240
+ # with a http_proxy curl has many more options avavailable for
241
+ # usage than rpm raw does. So for the most compatibility, we have
242
+ # chosen curl.
243
+ self.provision_with "curl -o local.rpm '#{definition}'; rpm -Uvh local.rpm; rm -f local.rpm"
244
+ else
245
+ self.provision_with "yum localinstall -y '#{definition}'"
246
+ end
247
+ else
248
+ reponame = "#{SecureRandom.hex}-#{File.basename(definition.path)}"
249
+ reponame = "#{reponame}.repo" if File.extname(reponame) != '.repo'
250
+ if @platform.is_nxos? or @platform.is_cisco_wrlinux?
251
+ self.provision_with "curl -o '/etc/yum/repos.d/#{reponame}' '#{definition}'"
252
+ else
253
+ self.provision_with "curl -o '/etc/yum.repos.d/#{reponame}' '#{definition}'"
254
+ end
255
+ end
256
+ end
257
+ end
258
+
259
+ # Helper to setup a zypper repository on a target system
260
+ #
261
+ # @param definition [String] the repo setup URI or RPM file
262
+ def zypper_repo(definition)
263
+ definition = URI.parse definition
264
+ if @platform.os_version == '10'
265
+ flag = 'sa'
266
+ else
267
+ flag = 'ar'
268
+ end
269
+ self.provision_with "yes | zypper -n --no-gpg-checks install curl"
270
+ if definition.scheme =~ /^(http|ftp)/
271
+ if File.extname(definition.path) == '.rpm'
272
+ # repo definition is an rpm (like puppetlabs-release)
273
+ self.provision_with "curl -o local.rpm '#{definition}'; rpm -Uvh local.rpm; rm -f local.rpm"
274
+ else
275
+ self.provision_with "yes | zypper -n --no-gpg-checks #{flag} -t YUM --repo '#{definition}'"
276
+ end
277
+ end
278
+ end
279
+
280
+ # Generic adder for build repositories
281
+ #
282
+ # @param *args [Array<String>] List of arguments to pass on to the platform specific method
283
+ # @raise [Vanagon::Error] an arror is raised if the current platform does not define add_repository
284
+ def add_build_repository(*args)
285
+ if @platform.respond_to?(:add_repository)
286
+ self.provision_with @platform.send(:add_repository, *args)
287
+ else
288
+ raise Vanagon::Error, "Adding a build repository not defined for #{@platform.name}"
289
+ end
290
+ end
291
+ end
292
+ end
293
+ end