server-blender-manifest 0.0.14 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.14
1
+ 0.0.15
@@ -1,4 +1,7 @@
1
1
  require 'ruby-debug'
2
+ require 'shadow_puppet'
3
+ require 'puppet/darwinport_fix'
4
+ require 'puppet/dmgapp'
2
5
 
3
6
  module Blender
4
7
  module Manifest; end
@@ -7,13 +10,11 @@ module Blender
7
10
  end
8
11
  end
9
12
 
10
- require 'blender/manifest/init'
11
13
  require 'blender/manifest/nodes'
12
14
  require 'blender/manifest/roles'
13
15
  require 'blender/manifest/mixer'
14
16
 
15
17
  class Root < ::ShadowPuppet::Manifest
16
- include Blender::Manifest::Init
17
18
  include Blender::Manifest::Nodes
18
19
  include Blender::Manifest::Roles
19
20
 
@@ -22,22 +23,66 @@ class Root < ::ShadowPuppet::Manifest
22
23
  @@mixed_recipes
23
24
  end
24
25
 
26
+ # Currently running operating system
27
+ #
28
+ # @return [String] name of the OS that is running
29
+ def os
30
+ Facter.value(:operatingsystem)
31
+ end
32
+
25
33
  def execute_user_recipe
26
- raise "no RECIPE to execute" unless recipe = ENV['RECIPE']
34
+ mix "os/#{os.downcase}"
27
35
 
28
- # load OS specific recipe.
29
- _os = Facter.value(:operatingsystem).downcase
30
- unless respond_to?(_os)
31
- mix "os/#{_os}"
36
+ if :setup == @stage
37
+ # run OS specific setup recipe.
38
+ m = "#{os.downcase}_setup"
39
+ return send(m) if respond_to?(m)
32
40
  end
33
- send _os
41
+
42
+ raise "no RECIPE to execute" unless recipe = ENV['RECIPE']
43
+
44
+ # run OS specific recipe.
45
+ m = os.downcase
46
+ send m if respond_to?(m)
34
47
 
35
48
  # load user's recipe
36
49
  code = open(recipe).read
37
50
  instance_eval(code, recipe)
38
-
39
51
  end
52
+
40
53
  recipe :execute_user_recipe
54
+
55
+ def initialize(stage = :execute)
56
+ super()
57
+ @stage = stage
58
+ end
59
+
60
+ # Create a catalog of all contained Puppet Resources and apply that
61
+ # catalog to the currently running system
62
+ def apply(bucket = nil)
63
+ bucket ||= export()
64
+ catalog = bucket.to_catalog
65
+ res = catalog.apply
66
+ catalog.clear
67
+ res
68
+ end
69
+
70
+ # Execute this manifest, applying all resources defined. Execute returns
71
+ # true if successfull, and false if unsucessfull. By default, this
72
+ # will only execute a manifest that has not already been executed?.
73
+ # The +force+ argument, if true, removes this check.
74
+ def execute(force=false)
75
+ return false if executed? && !force
76
+ evaluate_recipes
77
+ ! apply.any_failed?
78
+ rescue Exception => e
79
+ STDERR.puts "\n\nException: #{e}\n#{e.backtrace * "\n"}"
80
+ false
81
+ ensure
82
+ @executed = true
83
+ end
84
+
85
+
41
86
  end
42
87
 
43
88
  include Blender::Manifest::Mixer
@@ -1,11 +1,11 @@
1
1
  module Blender
2
2
  module Manifest
3
- ROOT = File.expand_path("../manifest/root.rb", __FILE__)
4
-
5
3
  # run the root manifest with shadow_puppet of the given VERSION
6
4
  # @param [String] shadow_puppet_version the version of the shadow_puppet gem to use
7
5
  def self.run(shadow_puppet_version)
8
- system "shadow_puppet", "_#{shadow_puppet_version}_", ROOT
6
+ require 'blender/manifest/root'
7
+
8
+ Root.new(:setup).execute && Root.new.execute
9
9
  end
10
10
  end
11
11
  end
@@ -0,0 +1,96 @@
1
+ require 'puppet/provider/package'
2
+
3
+ Puppet::Type.type(:package).provide :darwinport, :parent => Puppet::Provider::Package do
4
+ desc "Package management using DarwinPorts on OS X."
5
+
6
+ commands :port => "/opt/local/bin/port"
7
+ confine :operatingsystem => "Darwin"
8
+
9
+ has_feature :versionable
10
+
11
+ def self.eachpkgashash
12
+ # list out all of the packages
13
+ open("| #{command(:port)} installed") { |process|
14
+ regex = %r{(\S+)\s+@(\S+)\s+(\S+)}
15
+ fields = [:name, :ensure, :location]
16
+ hash = {}
17
+
18
+ # now turn each returned line into a package object
19
+ process.each { |line|
20
+ next unless line =~ /\(active\)\s*$/ # ignore non-active packages
21
+ hash.clear
22
+
23
+ if match = regex.match(line)
24
+ fields.zip(match.captures) { |field,value|
25
+ hash[field] = value
26
+ }
27
+
28
+ hash.delete :location
29
+ hash[:provider] = self.name
30
+ yield hash.dup
31
+ else
32
+ raise Puppet::DevError,
33
+ "Failed to match dpkg line %s" % line
34
+ end
35
+ }
36
+ }
37
+ end
38
+
39
+ def self.instances
40
+ packages = []
41
+
42
+ eachpkgashash do |hash|
43
+ packages << new(hash)
44
+ end
45
+
46
+ return packages
47
+ end
48
+
49
+ def install
50
+ should = @resource.should(:ensure)
51
+
52
+ args = ["install", @resource[:name]]
53
+ case should
54
+ when true, false, Symbol
55
+ # pass
56
+ else
57
+ args << "@#{should}"
58
+ end
59
+ output = port(*args)
60
+ if output =~ /^Error: No port/
61
+ raise Puppet::ExecutionFailure, "Could not find package %s" % @resource[:name]
62
+ end
63
+ end
64
+
65
+ def query
66
+ version = nil
67
+ self.class.eachpkgashash do |hash|
68
+ if hash[:name] == @resource[:name]
69
+ return hash
70
+ end
71
+ end
72
+
73
+ return nil
74
+ end
75
+
76
+ def latest
77
+ info = port :list, @resource[:name]
78
+
79
+ if $? != 0 or info =~ /^Error/
80
+ return nil
81
+ end
82
+
83
+ ary = info.split(/\s+/)
84
+ version = ary[1].sub(/^@/, '')
85
+
86
+ return version
87
+ end
88
+
89
+ def uninstall
90
+ port :uninstall, @resource[:name]
91
+ end
92
+
93
+ def update
94
+ return install()
95
+ end
96
+ end
@@ -0,0 +1,60 @@
1
+ require 'puppet/provider/package'
2
+
3
+ Puppet::Type.type(:package).provide :dmgapp, :parent => Puppet::Provider::Package do
4
+ desc "Install Apps on Mac OSX distributed using simple .dmg files with name.app inside"
5
+
6
+ confine :exists => "/Applications"
7
+ confine :operatingsystem => "Darwin"
8
+ commands :hdiutil => "/usr/bin/hdiutil"
9
+
10
+ def self.instance_properties
11
+ Dir["/Applications/*.app"].map do |app_path|
12
+ name = File.basename(app_path)[/(.*)\.app/, 1]
13
+ {
14
+ :name => name,
15
+ :provider => :dmgapp,
16
+ :ensure => :installed
17
+ }
18
+ end
19
+ end
20
+
21
+ def self.instances
22
+ instance_properties.map {|h| new(h)}
23
+ end
24
+
25
+ def query
26
+ self.class.instance_properties.find { |h| h[:name] == name }
27
+ end
28
+
29
+ def install
30
+ source = nil
31
+ unless source = @resource[:source]
32
+ self.fail ":source required"
33
+ end
34
+ unless name = @resource[:name]
35
+ self.fail "missing resource name"
36
+ end
37
+
38
+ unless source =~ /\.dmg$/i
39
+ self.fail ":source must be a .dmg"
40
+ end
41
+
42
+ plist = hdiutil "mount", "-plist", "-nobrowse", "-readonly", "-noidme", "-mountrandom", "/tmp", source
43
+ mount_dir = plist[/<string>(.*\/tmp\/.*)<\/string>/, 1]
44
+
45
+ app_file_name = "#{name}.app"
46
+
47
+ begin
48
+ if File.exists?(app_file_path = File.join(mount_dir, app_file_name))
49
+ FileUtils.cp_r app_file_path, "/Applications/"
50
+ else
51
+ self.fail "#{app_file_name} not found: #{Dir["#{mount_dir}/*"] * " "}"
52
+ end
53
+ ensure
54
+ hdiutil "eject", mount_dir
55
+ end
56
+ end
57
+ end
58
+
59
+
60
+
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{server-blender-manifest}
8
- s.version = "0.0.14"
8
+ s.version = "0.0.15"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Vitaly Kushner"]
12
- s.date = %q{2010-06-22}
12
+ s.date = %q{2010-07-04}
13
13
  s.description = %q{This gem is part of the server-blender family (http://astrails.com/opensource/server-blender)
14
14
  It contains server-side root manifest implementation for blender recipes. See server-blender for more information.
15
15
  }
@@ -25,11 +25,12 @@ It contains server-side root manifest implementation for blender recipes. See se
25
25
  "Rakefile",
26
26
  "VERSION",
27
27
  "lib/blender/manifest.rb",
28
- "lib/blender/manifest/init.rb",
29
28
  "lib/blender/manifest/mixer.rb",
30
29
  "lib/blender/manifest/nodes.rb",
31
30
  "lib/blender/manifest/roles.rb",
32
31
  "lib/blender/manifest/root.rb",
32
+ "lib/puppet/darwinport_fix.rb",
33
+ "lib/puppet/dmgapp.rb",
33
34
  "server-blender-manifest.gemspec",
34
35
  "spec/spec.opts",
35
36
  "spec/spec_helper.rb"
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 14
9
- version: 0.0.14
8
+ - 15
9
+ version: 0.0.15
10
10
  platform: ruby
11
11
  authors:
12
12
  - Vitaly Kushner
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-22 00:00:00 +03:00
17
+ date: 2010-07-04 00:00:00 +03:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -50,11 +50,12 @@ files:
50
50
  - Rakefile
51
51
  - VERSION
52
52
  - lib/blender/manifest.rb
53
- - lib/blender/manifest/init.rb
54
53
  - lib/blender/manifest/mixer.rb
55
54
  - lib/blender/manifest/nodes.rb
56
55
  - lib/blender/manifest/roles.rb
57
56
  - lib/blender/manifest/root.rb
57
+ - lib/puppet/darwinport_fix.rb
58
+ - lib/puppet/dmgapp.rb
58
59
  - server-blender-manifest.gemspec
59
60
  - spec/spec.opts
60
61
  - spec/spec_helper.rb
@@ -1,21 +0,0 @@
1
- module Blender::Manifest::Init
2
- def self.included(base)
3
- base.class_eval do
4
- recipe :create_blender_directories
5
- end
6
- end
7
-
8
- # create blender directories
9
- # @return dependency ref for the direcotires creation
10
- def create_blender_directories
11
- @create_blender_directories ||=
12
- begin
13
- file name = "/var/lib/blender", :owner => "root", :mode => 0700
14
- dep = file(name)
15
- file name = "/var/lib/blender/logs", :owner => "root", :mode => 0755, :require => dep
16
- dep = file(name)
17
- file name = "/var/lib/blender/tmp", :owner => "root", :mode => 0755, :require => dep
18
- dep = file(name)
19
- end
20
- end
21
- end