stork 0.1.0.pre → 0.2.0.pre

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 (49) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.ruby-version +1 -1
  4. data/Gemfile.lock +7 -8
  5. data/README.md +521 -4
  6. data/bin/stork +19 -5
  7. data/bin/storkctl +39 -9
  8. data/box/Vagrantfile +41 -0
  9. data/box/bootstrap.sh +317 -0
  10. data/box/integration.sh +33 -0
  11. data/lib/stork/builder.rb +78 -24
  12. data/lib/stork/client/plugins/host_actions.rb +12 -0
  13. data/lib/stork/client/plugins/host_list.rb +1 -1
  14. data/lib/stork/client/plugins/host_reload.rb +16 -0
  15. data/lib/stork/client/plugins/host_show.rb +1 -1
  16. data/lib/stork/client/plugins/host_sync.rb +16 -0
  17. data/lib/stork/collections.rb +1 -0
  18. data/lib/stork/configuration.rb +51 -92
  19. data/lib/stork/database.rb +96 -0
  20. data/lib/stork/deploy/command.rb +8 -0
  21. data/lib/stork/deploy/install_script.rb +3 -5
  22. data/lib/stork/deploy/kickstart_binding.rb +4 -6
  23. data/lib/stork/deploy/section.rb +11 -7
  24. data/lib/stork/deploy/snippet_binding.rb +15 -10
  25. data/lib/stork/plugin.rb +24 -5
  26. data/lib/stork/pxe.rb +2 -2
  27. data/lib/stork/resource/base.rb +0 -2
  28. data/lib/stork/resource/delegator.rb +0 -2
  29. data/lib/stork/resource/host.rb +23 -23
  30. data/lib/stork/resource/logical_volume.rb +1 -1
  31. data/lib/stork/server/application.rb +75 -13
  32. data/lib/stork/server/control.rb +82 -21
  33. data/lib/stork/version.rb +1 -1
  34. data/lib/stork.rb +4 -3
  35. data/specs/builder_spec.rb +5 -1
  36. data/specs/configuration_spec.rb +16 -133
  37. data/specs/database_spec.rb +33 -0
  38. data/specs/deploy_snippet_binding_spec.rb +15 -0
  39. data/specs/kickstart_spec.rb +1 -0
  40. data/specs/pxe_spec.rb +2 -2
  41. data/specs/resource_host_spec.rb +121 -261
  42. data/specs/scripts/kssetup.sh +2 -2
  43. data/specs/server_spec.rb +46 -24
  44. data/specs/spec_helper.rb +3 -2
  45. data/specs/stork/bundles/hosts/example.org.rb +2 -1
  46. data/specs/stork/bundles/public/file.txt +5 -0
  47. data/specs/stork/config.rb +1 -0
  48. data/stork.gemspec +3 -1
  49. metadata +43 -4
data/bin/storkctl CHANGED
@@ -18,16 +18,28 @@ require 'ostruct'
18
18
  class StorkCtlApp
19
19
  def initialize
20
20
  @options = OpenStruct.new
21
- @options.config = "/etc/stork/config.rb"
21
+ @options.config = ENV['STORK_CONFIG'] || "/etc/stork/config.rb"
22
+ @options.daemonize = false
23
+ @options.debug = false
22
24
  @options.command = :start
23
25
  end
24
26
 
25
27
  def parse
26
28
  opts = OptionParser.new do |o|
27
29
  o.banner = "Usage: storkctl start|stop|restart [options]"
28
- o.on("-c", "--config FILE", "Read configuration from the specified file") do |config|
30
+ o.on("-c", "--config FILE", "Read configuration from the specified file.") do |config|
29
31
  @options.config = config
30
32
  end
33
+ o.on("-d", "--daemonize", "Daemonize stork.") do
34
+ @options.daemonize = true
35
+ end
36
+ o.on("-D", "--debug", "Turn on debug output") do
37
+ @options.debug = true
38
+ end
39
+ o.on("-h", "--help", "Print this help message") do
40
+ puts opts.help
41
+ exit 1
42
+ end
31
43
  end
32
44
 
33
45
  action = :"#{ARGV.shift}"
@@ -35,28 +47,46 @@ class StorkCtlApp
35
47
  puts opts.help
36
48
  exit 1
37
49
  end
50
+
38
51
  @options.command = action
39
52
  opts.parse!
53
+ load_or_create_config
40
54
  end
41
55
 
42
- def build
43
- @configuration = Stork::Configuration.from_file(@options.config)
44
- @collection = Stork::Builder.load(@configuration).collection
56
+ def load_or_create_config
57
+ unless File.exist?(@options.config)
58
+ Stork::Configuration.to_file(@options.config)
59
+ end
60
+ Stork::Configuration.from_file(@options.config)
45
61
  end
46
62
 
47
63
  def run
64
+ @control = Stork::Server::Control.new(@options)
65
+
48
66
  case @options.command
49
67
  when :start
50
- Stork::Server::Control.start(@configuration, @collection)
68
+ if @options.daemonize
69
+ start_daemon
70
+ else
71
+ @control.start
72
+ end
51
73
  when :stop
52
- Stork::Server::Control.stop(@configuration, @collection)
74
+ @control.stop
53
75
  when :restart
54
- Stork::Server::Control.restart(@configuration, @collection)
76
+ @restart.restart
77
+ end
78
+ end
79
+
80
+ def start_daemon
81
+ if Process.respond_to?(:daemon)
82
+ Process.daemon(true)
83
+ @control.start
84
+ else
85
+ abort 'Process.daemon requires Ruby >= 1.9'
55
86
  end
56
87
  end
57
88
  end
58
89
 
59
90
  app = StorkCtlApp.new
60
91
  app.parse
61
- app.build
62
92
  app.run
data/box/Vagrantfile ADDED
@@ -0,0 +1,41 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ VAGRANTFILE_API_VERSION = "2"
5
+
6
+ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
7
+ config.vm.box = "centos-6.5"
8
+ config.vm.box_url = "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-6.5_chef-provisionerless.box"
9
+ config.vm.provision :shell, path: "bootstrap.sh"
10
+
11
+ # config.vm.network "forwarded_port", guest: 80, host: 8080
12
+ config.vm.network "private_network", ip: "10.10.1.10"
13
+
14
+ # config.vm.network "public_network"
15
+ # config.ssh.forward_agent = true
16
+
17
+ config.vm.synced_folder File.expand_path(File.dirname(__FILE__) + "/../"), "/mnt/stork"
18
+
19
+ config.vm.provider "virtualbox" do |vb|
20
+ # Don't boot with headless mode
21
+ vb.memory = 1024
22
+ # Use VBoxManage to customize the VM. For example to change memory:
23
+ vb.customize ["modifyvm", :id, "--memory", "1024"]
24
+ vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
25
+ end
26
+
27
+ # Enable provisioning with chef solo, specifying a cookbooks path, roles
28
+ # path, and data_bags path (all relative to this Vagrantfile), and adding
29
+ # some recipes and/or roles.
30
+ #
31
+ # config.vm.provision "chef_solo" do |chef|
32
+ # chef.cookbooks_path = "../my-recipes/cookbooks"
33
+ # chef.roles_path = "../my-recipes/roles"
34
+ # chef.data_bags_path = "../my-recipes/data_bags"
35
+ # chef.add_recipe "mysql"
36
+ # chef.add_role "web"
37
+ #
38
+ # # You may also specify custom JSON attributes:
39
+ # chef.json = { mysql_password: "foo" }
40
+ # end
41
+ end
data/box/bootstrap.sh ADDED
@@ -0,0 +1,317 @@
1
+ #!/bin/bash
2
+ # bootstrap.sh
3
+ # set -x
4
+ ###############################################################################
5
+ # Install and start ntp
6
+ ###############################################################################
7
+ yum -y install ntp
8
+ ntpdate pool.ntp.org
9
+ /etc/init.d/ntpd start && chkconfig ntpd on
10
+
11
+ ###############################################################################
12
+ # Install tftp and configure it for PXE boot.
13
+ ###############################################################################
14
+ yum -y install syslinux-tftpboot tftp-server
15
+ cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/.
16
+ cp /usr/share/syslinux/menu.c32 /var/lib/tftpboot/.
17
+ mkdir /var/lib/tftpboot/pxelinux.cfg
18
+ mkdir /var/lib/tftpboot/distros
19
+ sed -i -re 's/(\s+disable\s+=) yes/\1 no/' /etc/xinetd.d/tftp
20
+ service xinetd start && chkconfig xinetd on
21
+ # Put the default in there.
22
+ cat > /var/lib/tftpboot/pxelinux.cfg/default << 'EOF'
23
+ DEFAULT local
24
+ PROMPT 0
25
+ TIMEOUT 0
26
+ TOTALTIMEOUT 0
27
+ ONTIMEOUT local
28
+ LABEL local
29
+ LOCALBOOT -1
30
+ EOF
31
+
32
+ # Download a couple of netboot distros
33
+ MIRROR5="http://mirror.centos.org/centos-5/5.10/os/x86_64/images/pxeboot"
34
+ MIRROR6="http://mirror.centos.org/centos-6/6.5/os/x86_64/images/pxeboot"
35
+ pushd /var/lib/tftpboot/distros
36
+ echo "Downloading a few pxeboot kernels and images"
37
+ curl -s $MIRROR5/initrd.img > centos-5.10-initrd.img
38
+ curl -s $MIRROR5/vmlinuz > centos-5.10-vmlinuz
39
+ curl -s $MIRROR6/initrd.img > centos-6.5-initrd.img
40
+ curl -s $MIRROR6/vmlinuz > centos-6.5-vmlinuz
41
+ popd
42
+
43
+ ###############################################################################
44
+ # Install dhcp. and configure it.
45
+ ###############################################################################
46
+ yum -y install dhcp
47
+ cat > /etc/dhcp/dhcpd.conf << 'EOF'
48
+ default-lease-time 600;
49
+ max-lease-time 7200;
50
+ authoritative;
51
+ log-facility local7;
52
+
53
+ subnet 10.10.1.0 netmask 255.255.255.0 {
54
+ range 10.10.1.120 10.10.1.200;
55
+ allow booting;
56
+ allow bootp;
57
+ next-server 10.10.1.10;
58
+ filename "pxelinux.0";
59
+ option domain-name "vbox.local";
60
+ option domain-name-servers 10.10.1.10;
61
+ option routers 10.10.1.10;
62
+ option broadcast-address 10.10.1.255;
63
+ host head.vbox.local {
64
+ option host-name "head";
65
+ option domain-name "vbox.local";
66
+ ddns-hostname "head";
67
+ ddns-domainname "vbox.local";
68
+ hardware ethernet 02:16:3f:c3:00:02;
69
+ fixed-address 10.10.1.101;
70
+ }
71
+ host node-101.vbox.local {
72
+ option host-name "node-101";
73
+ option domain-name "vbox.local";
74
+ ddns-hostname "node-101";
75
+ ddns-domainname "vbox.local";
76
+ hardware ethernet 02:16:3f:c3:01:01;
77
+ fixed-address 10.10.1.101;
78
+ }
79
+ host node-102.vbox.local {
80
+ option host-name "node-102";
81
+ option domain-name "vbox.local";
82
+ ddns-hostname "node-102";
83
+ ddns-domainname "vbox.local";
84
+ hardware ethernet 02:16:3f:c3:01:02;
85
+ fixed-address 10.10.1.102;
86
+ }
87
+ host node-103.vbox.local {
88
+ option host-name "node-103";
89
+ option domain-name "vbox.local";
90
+ ddns-hostname "node-103";
91
+ ddns-domainname "vbox.local";
92
+ hardware ethernet 02:16:3f:c3:01:03;
93
+ fixed-address 10.10.1.103;
94
+ }
95
+ }
96
+ EOF
97
+ /etc/init.d/dhcpd start && chkconfig dhcpd on
98
+
99
+ ###############################################################################
100
+ # Install DNS and configure it and make some network adjustments.
101
+ ###############################################################################
102
+ yum -y install bind bind-utils
103
+
104
+ cat > /etc/named.conf << 'EOF'
105
+ options {
106
+ listen-on port 53 { 127.0.0.1; 10.10.1.10; };
107
+ directory "/var/named";
108
+ version "0.nunya";
109
+ forwarders { 10.0.2.3; };
110
+ allow-transfer { none; };
111
+ allow-query { localhost; };
112
+ statistics-file "data/named_stats.txt";
113
+ memstatistics-file "data/named_mem_stats.txt";
114
+ dnssec-enable no;
115
+ dnssec-validation no;
116
+ };
117
+
118
+ logging {
119
+ channel default_debug {
120
+ file "data/named.run";
121
+ severity dynamic;
122
+ };
123
+ };
124
+
125
+ zone "." IN {
126
+ type hint;
127
+ file "named.ca";
128
+ };
129
+
130
+ zone "vbox.local" IN {
131
+ type master;
132
+ file "vbox.local.zone";
133
+ allow-update { none; };
134
+ };
135
+
136
+ zone "1.10.10.in-addr.arpa" IN {
137
+ type master;
138
+ file "vbox.local.db";
139
+ allow-update { none; };
140
+ };
141
+
142
+ include "/etc/named.rfc1912.zones";
143
+ include "/etc/named.root.key";
144
+ EOF
145
+
146
+ cat > /var/named/vbox.local.zone << 'EOF'
147
+ $TTL 1D;
148
+ $ORIGIN vbox.local.
149
+ @ IN SOA @ root.vbox.local. (
150
+ 2014062501 ; serial
151
+ 3h ; refresh
152
+ 1w ; retry
153
+ 1w ; expire
154
+ 3h) ; min
155
+ @ 1D IN NS stork
156
+ stork 1D IN A 10.10.1.10
157
+ chef 1D IN CNAME stork
158
+ head 1D IN A 10.10.1.100
159
+ node-101 1D IN A 10.10.1.101
160
+ node-102 1D IN A 10.10.1.102
161
+ node-103 1D IN A 10.10.1.103
162
+ EOF
163
+
164
+ cat > /var/named/vbox.local.db << 'EOF'
165
+ $TTL 1D;
166
+ @ IN SOA stork.vbox.local. root.vbox.local. (
167
+ 2014062501 ; serial
168
+ 3H ; refresh
169
+ 15 ; retry
170
+ 1w ; expire
171
+ 3h) ; min
172
+ NS stork.vbox.local.
173
+ 10 PTR stork.vbox.local.
174
+ 100 PTR head.vbox.local.
175
+ 101 PTR node-101.vbox.local.
176
+ 102 PTR node-102.vbox.local.
177
+ 103 PTR node-103.vbox.local.
178
+ EOF
179
+
180
+ /etc/init.d/named start && chkconfig named on
181
+
182
+ ###############################################################################
183
+ # Create ssh keys
184
+ ###############################################################################
185
+ pushd ~vagrant/.ssh
186
+ ssh-keygen -t rsa -N "" -f id_rsa -N ""
187
+ chown vagrant:vagrant id_rsa*
188
+ popd
189
+
190
+ ###############################################################################
191
+ # Chef setup with chef server and a few basic cookbooks for testing.
192
+ ###############################################################################
193
+ pushd /tmp
194
+ wget https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-server-11.0.12-1.el6.x86_64.rpm
195
+ yum -y localinstall chef-server-11.0.12-1.el6.x86_64.rpm
196
+ chef-server-ctl reconfigure
197
+ wget https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-11.12.8-2.el6.x86_64.rpm
198
+ yum -y localinstall chef-11.12.8-2.el6.x86_64.rpm
199
+ popd
200
+
201
+ # Just utilize the admin user that is already created
202
+ pushd /root
203
+ mkdir .chef
204
+ cat > .chef/knife.rb << 'EOF'
205
+ log_level :info
206
+ log_location STDOUT
207
+ node_name 'admin'
208
+ client_key '/etc/chef-server/admin.pem'
209
+ validation_client_name 'chef-validator'
210
+ validation_key '/etc/chef-server/chef-validator.pem'
211
+ chef_server_url 'https://stork.vbox.local:443'
212
+ syntax_check_cache_path '/root/.chef/syntax_check_cache'
213
+ EOF
214
+ popd
215
+
216
+ ###############################################################################
217
+ # Set up EPEL and a few tools
218
+ ###############################################################################
219
+ pushd /tmp
220
+ wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
221
+ yum -y localinstall epel-release-6-8.noarch.rpm
222
+ yum -y install git sqlite-devel
223
+ popd
224
+
225
+ ###############################################################################
226
+ # RVM setup and Ruby 2.0.0 installation
227
+ ###############################################################################
228
+ curl -sSL https://get.rvm.io | bash -s stable
229
+ source /usr/local/rvm/scripts/rvm
230
+ type rvm | head -1
231
+ rvm install 2.0.0
232
+
233
+ ###############################################################################
234
+ # Install and start stork
235
+ ###############################################################################
236
+ pushd /mnt/stork
237
+ rvm use 2.0.0@stork --create
238
+ su vagrant -c 'rake build'
239
+ gem install pkg/*.gem --no-rdoc --no-ri
240
+ popd
241
+
242
+ # Create the configuration
243
+ mkdir /etc/stork
244
+ pushd /etc/stork
245
+
246
+ cat > /etc/stork/config.rb << 'EOF'
247
+ # Stork configuration file"
248
+ path "/etc/stork"
249
+ bundle_path "/etc/stork/bundles"
250
+ authorized_keys_file "/etc/stork/authorized_keys"
251
+ pxe_path "/var/lib/tftpboot/pxelinux.cfg"
252
+ log_file "/var/log/stork.log"
253
+ pid_file "/var/log/stork.pid"
254
+ server "stork.vbox.local"
255
+ port 5000
256
+ bind "0.0.0.0"
257
+ timezone "America/Los_Angeles"
258
+ EOF
259
+
260
+ # Create the authorized keys file
261
+ cat /home/vagrant/.ssh/id_rsa.pub > /etc/stork/authorized_keys
262
+ # Get the example bundles
263
+ git clone https://github.com/rlyon/stork-bundle.git bundles
264
+
265
+ cat > /usr/bin/stork_start << 'EOF'
266
+ #!/bin/bash
267
+ source /usr/local/rvm/scripts/rvm
268
+ rvm use 2.0.0@stork
269
+ storkctl start
270
+ EOF
271
+ chmod 755 /usr/bin/stork_start
272
+
273
+ cat > /usr/bin/stork_update << 'EOF'
274
+ #!/bin/bash
275
+ source /usr/local/rvm/scripts/rvm
276
+ rvm use 2.0.0@stork
277
+ cd /mnt/stork
278
+ rake install
279
+ EOF
280
+ chmod 755 /usr/bin/stork_update
281
+
282
+ mkdir ~vagrant/.stork
283
+ ln -s /etc/stork/config.rb ~vagrant/.stork/client.rb
284
+ chown -R vagrant:vagrant ~vagrant/.stork
285
+
286
+ # Make sure that RVM uses the system ruby as default.
287
+ rvm reset
288
+
289
+
290
+
291
+ ###############################################################################
292
+ # Networking adjustments
293
+ ###############################################################################
294
+ echo "PEERDNS=no" >> /etc/sysconfig/network-scripts/ifcfg-eth0
295
+ cat > /etc/resolv.conf << 'EOF'
296
+ options single-request-reopen
297
+ nameserver 127.0.0.1
298
+ EOF
299
+
300
+ /etc/init.d/network restart
301
+
302
+ ###############################################################################
303
+ # Turn on NATing so we can use this as the gateway for our isolated test vms
304
+ ###############################################################################
305
+ sed -i -re 's/(net.ipv4.ip_forward\s+=) 0/\1 1/' /etc/sysctl.conf
306
+ sysctl -p /etc/sysctl.conf
307
+ /etc/init.d/iptables start
308
+ iptables -A FORWARD -i eth1 -j ACCEPT
309
+ iptables -A FORWARD -o eth1 -j ACCEPT
310
+ iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
311
+ /etc/init.d/iptables save
312
+
313
+ ###############################################################################
314
+ # Since we now have a TFTP, SysLinux, DHCP, DNS, Nating and Stork shared on a
315
+ # mounted directory, we can set up a simple vbox config which will enable us to
316
+ # go through the entire install process on a laptop.
317
+ ###############################################################################
@@ -0,0 +1,33 @@
1
+ #!/bin/sh
2
+
3
+ # Make sure that virtualbox is not running dhcp on the host interface
4
+ VBoxManage dhcpserver remove --netname HostInterfaceNetworking-vboxnet0
5
+
6
+ ID=$(date "+%Y%M%H%m%d%S")
7
+ MAC=$(echo $1 | sed 's/://g' | tr '[:lower:]' '[:upper:]')
8
+
9
+ VBoxManage createvm --name stork_pxe_$ID --ostype RedHat_64 --register
10
+
11
+ VBoxManage createhd --filename stork_pxe_$ID.vmdk --format VMDK --size 4000 --variant Standard
12
+ VBoxManage storagectl stork_pxe_$ID --name "IDE Controller" --add ide --controller PIIX4 --hostiocache on --bootable on
13
+ VBoxManage storageattach stork_pxe_$ID --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium stork_pxe_$ID.vmdk
14
+
15
+ VBoxManage modifyvm stork_pxe_$ID --nic1 hostonly
16
+ VBoxManage modifyvm stork_pxe_$ID --cableconnected1 on
17
+ VBoxManage modifyvm stork_pxe_$ID --hostonlyadapter1 vboxnet0
18
+ VBoxManage modifyvm stork_pxe_$ID --macaddress1 $MAC
19
+ VBoxManage modifyvm stork_pxe_$ID --nictype1 82540EM
20
+ VBoxManage modifyvm stork_pxe_$ID --intnet1 intnet
21
+
22
+ VBoxManage modifyvm stork_pxe_$ID --boot1 net
23
+ VBoxManage modifyvm stork_pxe_$ID --boot2 disk
24
+ VBoxManage modifyvm stork_pxe_$ID --boot3 none
25
+ VBoxManage modifyvm stork_pxe_$ID --boot4 none
26
+
27
+ VBoxManage modifyvm stork_pxe_$ID --memory 1024
28
+
29
+ VBoxManage modifyvm stork_pxe_$ID --acpi on
30
+ VBoxManage modifyvm stork_pxe_$ID --ioapic on
31
+ VBoxManage modifyvm stork_pxe_$ID --rtcuseutc on
32
+
33
+ VBoxManage startvm stork_pxe_$ID
data/lib/stork/builder.rb CHANGED
@@ -1,33 +1,36 @@
1
1
  module Stork
2
- # The Builder object loads all of the configuration files and parses them
2
+ # The Builder object loads all of the definition files and parses them
3
3
  # to build a collection of resources
4
4
  #
5
- # === Attributes
6
- # * +configuration+ - The configuration containing the paths to the resource
7
- # files.
8
5
  class Builder
9
6
  attr_reader :collection
10
- attr_reader :configuration
11
-
12
- def initialize(configuration)
13
- @configuration = configuration
7
+ # Initialize the builder object. Create a new collection.
8
+ #
9
+ def initialize
14
10
  @collection = Stork::Collections.new
15
11
  end
16
12
 
17
- def self.load(configuration)
18
- builder = Builder.new(configuration)
13
+ # Load the resource definition files. The snippets and templates
14
+ # are first read in. Then the rest of the resources will be evalutated
15
+ # and added to the collections.
16
+ #
17
+ # == Returns:
18
+ # A builder object that contains the the resource collections
19
+ #
20
+ def self.load
21
+ builder = Builder.new
19
22
  delegator = BuilderDelegator.new(builder)
20
23
 
21
24
  # Load in snippets and templates
22
- delegator.snippets(configuration.snippets_path)
23
- delegator.templates(configuration.templates_path)
25
+ delegator.snippets(Configuration[:snippets_path])
26
+ delegator.templates(Configuration[:templates_path])
24
27
 
25
28
  load_paths = [
26
- configuration.distros_path,
27
- configuration.chefs_path,
28
- configuration.networks_path,
29
- configuration.layouts_path,
30
- configuration.hosts_path
29
+ Configuration[:distros_path],
30
+ Configuration[:chefs_path],
31
+ Configuration[:networks_path],
32
+ Configuration[:layouts_path],
33
+ Configuration[:hosts_path]
31
34
  ]
32
35
 
33
36
  load_paths.each do |path|
@@ -38,52 +41,96 @@ module Stork
38
41
  builder
39
42
  end
40
43
 
41
- # Expose a limited number of methods for DSL parsing from files. Allow
42
- # delegation of the host, layout, network, chef, distro, templates and
43
- # snippets blocks.
44
+ # Expose a limited number of resource methods for DSL parsing from
45
+ # files. Allow delegation of the host, layout, network, chef, distro,
46
+ # templates and snippets blocks.
47
+ #
48
+ # == Parameters
49
+ # obj::
50
+ # The Builder object that is being delegated.
44
51
  #
45
- # ==== Attributes
46
- # * +obj+ - The Builder object that is being delegated.
47
- class BuilderDelegator
52
+ class BuilderDelegator
48
53
  def initialize(obj)
49
54
  @delegated = obj
50
55
  end
51
56
 
57
+ # Build and add a host to the resource collection.
58
+ #
59
+ # == Parameters:
60
+ # name::
61
+ # The fully qualified domain name of the host.
62
+ #
63
+ #
52
64
  def host(name, &block)
53
65
  @delegated.collection.hosts.add(
54
66
  Resource::Host.build(
55
67
  name,
56
- configuration: @delegated.configuration,
57
68
  collection: @delegated.collection,
58
69
  &block
59
70
  )
60
71
  )
61
72
  end
62
73
 
74
+
75
+ # Build and add a layout to the resource collection.
76
+ #
77
+ # == Parameters:
78
+ # name::
79
+ # A unique name to identify the layout.
80
+ #
81
+ #
63
82
  def layout(name, &block)
64
83
  @delegated.collection.layouts.add(
65
84
  Resource::Layout.build(name, &block)
66
85
  )
67
86
  end
68
87
 
88
+ # Build and add a network to the resource collection.
89
+ #
90
+ # == Parameters:
91
+ # name::
92
+ # A unique name to identify the network.
93
+ #
94
+ #
69
95
  def network(name, &block)
70
96
  @delegated.collection.networks.add(
71
97
  Resource::Network.build(name, &block)
72
98
  )
73
99
  end
74
100
 
101
+ # Build and add a chef server to the resource collection.
102
+ #
103
+ # == Parameters:
104
+ # name::
105
+ # A unique name to identify the chef server.
106
+ #
107
+ #
75
108
  def chef(name, &block)
76
109
  @delegated.collection.chefs.add(
77
110
  Resource::Chef.build(name, &block)
78
111
  )
79
112
  end
80
113
 
114
+ # Build and add a distro to the resource collection.
115
+ #
116
+ # == Parameters:
117
+ # name::
118
+ # A unique name to identify the distro.
119
+ #
120
+ #
81
121
  def distro(name, &block)
82
122
  @delegated.collection.distros.add(
83
123
  Resource::Distro.build(name, &block)
84
124
  )
85
125
  end
86
126
 
127
+ # Read and add a template to the resource collection.
128
+ #
129
+ # == Parameters:
130
+ # name::
131
+ # A unique name to identify the template.
132
+ #
133
+ #
87
134
  def templates(path)
88
135
  Dir.glob(path + '/*.erb') do |file|
89
136
  @delegated.collection.templates.add(
@@ -92,6 +139,13 @@ module Stork
92
139
  end
93
140
  end
94
141
 
142
+ # Read and add a snippet to the resource collection.
143
+ #
144
+ # == Parameters:
145
+ # name::
146
+ # A unique name to identify the snippet.
147
+ #
148
+ #
95
149
  def snippets(path)
96
150
  Dir.glob(path + '/*.erb') do |file|
97
151
  @delegated.collection.snippets.add(
@@ -0,0 +1,12 @@
1
+ module HostActionsPlugin
2
+ class HostActions < Stork::Plugin
3
+ banner "stork host actions (options)"
4
+
5
+ def run
6
+ data = fetch('actions')
7
+ data['hosts'].each do |host|
8
+ print(host['name'], host['action'].upcase, pad: 32)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -3,7 +3,7 @@ module HostListPlugin
3
3
  banner "stork host list (options)"
4
4
 
5
5
  def run
6
- data = fetch('/hosts')
6
+ data = fetch('hosts')
7
7
  data['hosts'].sort.each do |host|
8
8
  puts host
9
9
  end
@@ -0,0 +1,16 @@
1
+ module HostReloadPlugin
2
+ class HostReload < Stork::Plugin
3
+ banner "stork host reload (options)"
4
+
5
+ def run
6
+ response = RestClient.get "#{stork}/api/v1/reload"
7
+ if response.code == 200
8
+ puts "OK"
9
+ else
10
+ data = JSON.parse(response)
11
+ puts "Error: #{data['message']}"
12
+ exit 1
13
+ end
14
+ end
15
+ end
16
+ end