right_link 5.9.0

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 (199) hide show
  1. data/actors/agent_manager.rb +88 -0
  2. data/actors/instance_scheduler.rb +321 -0
  3. data/actors/instance_services.rb +64 -0
  4. data/actors/instance_setup.rb +567 -0
  5. data/bin/cloud +25 -0
  6. data/bin/cook_runner +44 -0
  7. data/bin/deploy +120 -0
  8. data/bin/enroll +385 -0
  9. data/bin/rad +32 -0
  10. data/bin/rchk +29 -0
  11. data/bin/rnac +39 -0
  12. data/bin/rs_connect +33 -0
  13. data/bin/rs_log_level +31 -0
  14. data/bin/rs_ohai +28 -0
  15. data/bin/rs_reenroll +31 -0
  16. data/bin/rs_run_recipe +34 -0
  17. data/bin/rs_run_right_script +34 -0
  18. data/bin/rs_shutdown +33 -0
  19. data/bin/rs_tag +33 -0
  20. data/bin/rs_thunk +33 -0
  21. data/bin/rstat +31 -0
  22. data/bin/system +16 -0
  23. data/ext/Rakefile +18 -0
  24. data/init/config.yml +5 -0
  25. data/init/init.rb +79 -0
  26. data/lib/chef/ohai_setup.rb +51 -0
  27. data/lib/chef/plugins/cloud.rb +91 -0
  28. data/lib/chef/plugins/cloudstack.rb +23 -0
  29. data/lib/chef/plugins/ec2.rb +23 -0
  30. data/lib/chef/plugins/linux/block_device2.rb +24 -0
  31. data/lib/chef/plugins/rackspace.rb +23 -0
  32. data/lib/chef/plugins/rightscale.rb +125 -0
  33. data/lib/chef/plugins/windows/network.rb +114 -0
  34. data/lib/chef/plugins.rb +74 -0
  35. data/lib/chef/providers/dns_dnsmadeeasy_provider.rb +81 -0
  36. data/lib/chef/providers/dns_resource.rb +100 -0
  37. data/lib/chef/providers/executable_schedule_provider.rb +70 -0
  38. data/lib/chef/providers/executable_schedule_resource.rb +144 -0
  39. data/lib/chef/providers/remote_recipe_provider.rb +86 -0
  40. data/lib/chef/providers/remote_recipe_resource.rb +101 -0
  41. data/lib/chef/providers/right_link_tag_provider.rb +73 -0
  42. data/lib/chef/providers/right_link_tag_resource.rb +59 -0
  43. data/lib/chef/providers/right_script_provider.rb +190 -0
  44. data/lib/chef/providers/right_script_resource.rb +113 -0
  45. data/lib/chef/providers/rs_shutdown_provider.rb +75 -0
  46. data/lib/chef/providers/rs_shutdown_resource.rb +55 -0
  47. data/lib/chef/providers/server_collection_provider.rb +66 -0
  48. data/lib/chef/providers/server_collection_resource.rb +93 -0
  49. data/lib/chef/providers/windows/powershell_provider.rb +151 -0
  50. data/lib/chef/providers/windows/powershell_resource.rb +111 -0
  51. data/lib/chef/providers/windows/unsupported_provider.rb +51 -0
  52. data/lib/chef/right_providers.rb +55 -0
  53. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/ChefNodeCmdlet.csproj +104 -0
  54. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/ChefNodeCmdlet.dll-Help.xml +141 -0
  55. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/Exceptions.cs +182 -0
  56. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetChefNodeCommand.cs +58 -0
  57. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetChefNodeRequest.cs +46 -0
  58. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetChefNodeResponse.cs +45 -0
  59. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetCurrentResourceCommand.cs +58 -0
  60. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetCurrentResourceRequest.cs +46 -0
  61. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetCurrentResourceResponse.cs +45 -0
  62. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetNewResourceCommand.cs +58 -0
  63. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetNewResourceRequest.cs +46 -0
  64. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetNewResourceResponse.cs +45 -0
  65. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetNextActionCommand.cs +178 -0
  66. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetNextActionRequest.cs +67 -0
  67. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetNextActionResponse.cs +58 -0
  68. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetNodeValueCommandBase.cs +142 -0
  69. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetNodeValueRequestBase.cs +64 -0
  70. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetNodeValueResponseBase.cs +69 -0
  71. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/JsonTransport.cs +110 -0
  72. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/PipeClient.cs +158 -0
  73. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/PipeServer.cs +142 -0
  74. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/Properties/AssemblyInfo.cs +16 -0
  75. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/ProtocolConstants.cs +55 -0
  76. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/ProtocolUtilities.cs +77 -0
  77. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/ReadMe.txt +53 -0
  78. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetChefNodeCommand.cs +59 -0
  79. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetChefNodeRequest.cs +46 -0
  80. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetChefNodeResponse.cs +58 -0
  81. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetCurrentResourceCommand.cs +59 -0
  82. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetCurrentResourceRequest.cs +46 -0
  83. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetCurrentResourceResponse.cs +40 -0
  84. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetNewResourceCommand.cs +59 -0
  85. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetNewResourceRequest.cs +46 -0
  86. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetNewResourceResponse.cs +40 -0
  87. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetNodeValueCommandBase.cs +293 -0
  88. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetNodeValueRequestBase.cs +75 -0
  89. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetNodeValueResponseBase.cs +45 -0
  90. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/Transport.cs +91 -0
  91. data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet.sln +35 -0
  92. data/lib/chef/windows/ChefNodeCmdlet/TestChefNodeCmdlet/Program.cs +374 -0
  93. data/lib/chef/windows/ChefNodeCmdlet/TestChefNodeCmdlet/Properties/AssemblyInfo.cs +16 -0
  94. data/lib/chef/windows/ChefNodeCmdlet/TestChefNodeCmdlet/TestChefNodeCmdlet.csproj +65 -0
  95. data/lib/chef/windows/ChefNodeCmdlet/TestNextActionCmdlet/Program.cs +136 -0
  96. data/lib/chef/windows/ChefNodeCmdlet/TestNextActionCmdlet/Properties/AssemblyInfo.cs +36 -0
  97. data/lib/chef/windows/ChefNodeCmdlet/TestNextActionCmdlet/ReadMe.txt +46 -0
  98. data/lib/chef/windows/ChefNodeCmdlet/TestNextActionCmdlet/TestNextActionCmdlet.csproj +68 -0
  99. data/lib/chef/windows/bin/Newtonsoft.Json.dll +0 -0
  100. data/lib/chef/windows/chef_node_server.rb +463 -0
  101. data/lib/chef/windows/dynamic_powershell_provider.rb +296 -0
  102. data/lib/chef/windows/pipe_server.rb +283 -0
  103. data/lib/chef/windows/powershell_host.rb +285 -0
  104. data/lib/chef/windows/powershell_pipe_server.rb +136 -0
  105. data/lib/chef/windows/powershell_provider_base.rb +92 -0
  106. data/lib/chef/windows/scripts/run_loop.ps1 +105 -0
  107. data/lib/clouds/cloud.rb +557 -0
  108. data/lib/clouds/cloud_factory.rb +250 -0
  109. data/lib/clouds/cloud_utilities.rb +244 -0
  110. data/lib/clouds/clouds/azure.rb +106 -0
  111. data/lib/clouds/clouds/cloudstack.rb +114 -0
  112. data/lib/clouds/clouds/ec2.rb +113 -0
  113. data/lib/clouds/clouds/eucalyptus.rb +46 -0
  114. data/lib/clouds/clouds/google.rb +102 -0
  115. data/lib/clouds/clouds/none.rb +76 -0
  116. data/lib/clouds/clouds/openstack.rb +30 -0
  117. data/lib/clouds/clouds/rackspace-ng.rb +54 -0
  118. data/lib/clouds/clouds/rackspace.rb +78 -0
  119. data/lib/clouds/clouds/softlayer.rb +91 -0
  120. data/lib/clouds/metadata_formatter.rb +108 -0
  121. data/lib/clouds/metadata_provider.rb +128 -0
  122. data/lib/clouds/metadata_source.rb +87 -0
  123. data/lib/clouds/metadata_sources/certificate_metadata_source.rb +207 -0
  124. data/lib/clouds/metadata_sources/config_drive_metadata_source.rb +129 -0
  125. data/lib/clouds/metadata_sources/file_metadata_source.rb +74 -0
  126. data/lib/clouds/metadata_sources/http_metadata_source.rb +277 -0
  127. data/lib/clouds/metadata_sources/selective_metadata_source.rb +122 -0
  128. data/lib/clouds/metadata_tree_climber.rb +144 -0
  129. data/lib/clouds/metadata_writer.rb +155 -0
  130. data/lib/clouds/metadata_writers/dictionary_metadata_writer.rb +72 -0
  131. data/lib/clouds/metadata_writers/ruby_metadata_writer.rb +76 -0
  132. data/lib/clouds/metadata_writers/shell_metadata_writer.rb +121 -0
  133. data/lib/clouds/register_clouds.rb +34 -0
  134. data/lib/clouds.rb +32 -0
  135. data/lib/gem_dependencies.rb +83 -0
  136. data/lib/git_hooks/commit-msg.rb +7 -0
  137. data/lib/instance/agent_config.rb +168 -0
  138. data/lib/instance/agent_watcher.rb +233 -0
  139. data/lib/instance/audit_cook_stub.rb +104 -0
  140. data/lib/instance/audit_proxy.rb +247 -0
  141. data/lib/instance/bundle_queue.rb +104 -0
  142. data/lib/instance/cook/agent_connection.rb +109 -0
  143. data/lib/instance/cook/audit_logger.rb +165 -0
  144. data/lib/instance/cook/audit_stub.rb +142 -0
  145. data/lib/instance/cook/ca-bundle.crt +2794 -0
  146. data/lib/instance/cook/chef_state.rb +211 -0
  147. data/lib/instance/cook/cook.rb +306 -0
  148. data/lib/instance/cook/cook_state.rb +298 -0
  149. data/lib/instance/cook/cookbook_path_mapping.rb +66 -0
  150. data/lib/instance/cook/cookbook_repo_retriever.rb +190 -0
  151. data/lib/instance/cook/executable_sequence.rb +765 -0
  152. data/lib/instance/cook/external_parameter_gatherer.rb +190 -0
  153. data/lib/instance/cook/repose_downloader.rb +349 -0
  154. data/lib/instance/cook/shutdown_request_proxy.rb +121 -0
  155. data/lib/instance/cook.rb +41 -0
  156. data/lib/instance/downloader.rb +208 -0
  157. data/lib/instance/duplicable.rb +67 -0
  158. data/lib/instance/exceptions.rb +49 -0
  159. data/lib/instance/executable_sequence_proxy.rb +278 -0
  160. data/lib/instance/instance_commands.rb +577 -0
  161. data/lib/instance/instance_state.rb +633 -0
  162. data/lib/instance/json_utilities.rb +102 -0
  163. data/lib/instance/login_manager.rb +533 -0
  164. data/lib/instance/login_user_manager.rb +522 -0
  165. data/lib/instance/message_encoder.rb +118 -0
  166. data/lib/instance/multi_thread_bundle_queue.rb +232 -0
  167. data/lib/instance/operation_context.rb +60 -0
  168. data/lib/instance/options_bag.rb +65 -0
  169. data/lib/instance/payload_formatter.rb +46 -0
  170. data/lib/instance/policy.rb +53 -0
  171. data/lib/instance/policy_audit.rb +100 -0
  172. data/lib/instance/policy_manager.rb +146 -0
  173. data/lib/instance/reenroll_manager.rb +104 -0
  174. data/lib/instance/right_scripts_cookbook.rb +181 -0
  175. data/lib/instance/shutdown_request.rb +221 -0
  176. data/lib/instance/single_thread_bundle_queue.rb +189 -0
  177. data/lib/instance/volume_management.rb +450 -0
  178. data/lib/instance.rb +50 -0
  179. data/lib/repo_conf_generators/apt_conf_generators.rb +106 -0
  180. data/lib/repo_conf_generators/gem_conf_generators.rb +80 -0
  181. data/lib/repo_conf_generators/rightscale_conf_generators.rb +254 -0
  182. data/lib/repo_conf_generators/rightscale_key.pub +17 -0
  183. data/lib/repo_conf_generators/yum_conf_generators.rb +225 -0
  184. data/lib/repo_conf_generators.rb +30 -0
  185. data/lib/run_shell.rb +28 -0
  186. data/scripts/agent_checker.rb +571 -0
  187. data/scripts/agent_controller.rb +247 -0
  188. data/scripts/agent_deployer.rb +148 -0
  189. data/scripts/bundle_runner.rb +336 -0
  190. data/scripts/cloud_controller.rb +176 -0
  191. data/scripts/log_level_manager.rb +142 -0
  192. data/scripts/ohai_runner.rb +33 -0
  193. data/scripts/reenroller.rb +193 -0
  194. data/scripts/server_importer.rb +293 -0
  195. data/scripts/shutdown_client.rb +183 -0
  196. data/scripts/system_configurator.rb +367 -0
  197. data/scripts/tagger.rb +381 -0
  198. data/scripts/thunker.rb +356 -0
  199. metadata +418 -0
@@ -0,0 +1,144 @@
1
+ #
2
+ # Copyright (c) 2009-2011 RightScale Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ # To install the chef gem:
24
+ # sudo gem sources -a http://gems.opscode.com
25
+ # sudo gem install chef ohai
26
+
27
+ require 'fileutils'
28
+
29
+ class Chef
30
+
31
+ class Resource
32
+
33
+ # ExecutableSchedule chef resource.
34
+ # Allows defining the schedule(cron) for a right script or a recipe
35
+ class ExecutableSchedule < Chef::Resource
36
+
37
+ # Initialize ExecutableSchedule resource with default values
38
+ #
39
+ # === Parameters
40
+ # name(String):: Name of the schedule
41
+ def initialize(name, run_context=nil)
42
+ super(name, run_context)
43
+ @cron_resource = Chef::Resource::Cron.new(name)
44
+ @cron_resource.user('rightscale')
45
+ @resource_name = :executable_schedule
46
+ recipe nil
47
+ recipe_id nil
48
+ right_script nil
49
+ right_script_id nil
50
+ @action = :create
51
+ @allowed_actions.push(:create, :delete)
52
+ end
53
+
54
+ # (Chef::Resource::Cron) Underlying cron resource
55
+ attr_accessor :cron_resource
56
+
57
+ # (String) Schedule name
58
+ def name(arg=nil)
59
+ @cron_resource.name(arg)
60
+ end
61
+
62
+ # (String) Schedule minute
63
+ def minute(arg=nil)
64
+ @cron_resource.minute(arg)
65
+ end
66
+
67
+ # (String) Schedule hour
68
+ def hour(arg=nil)
69
+ @cron_resource.hour(arg)
70
+ end
71
+
72
+ # (String) Schedule day
73
+ def day(arg=nil)
74
+ @cron_resource.day(arg)
75
+ end
76
+
77
+ # (String) Schedule month
78
+ def month(arg=nil)
79
+ @cron_resource.month(arg)
80
+ end
81
+
82
+ # (String) Schedule weekday
83
+ def weekday(arg=nil)
84
+ @cron_resource.weekday(arg)
85
+ end
86
+
87
+ # (String) recipe name for the schedule
88
+ def recipe(arg=nil)
89
+ set_or_return(
90
+ :recipe,
91
+ arg,
92
+ :kind_of => [ String ]
93
+ )
94
+
95
+ @cron_resource.command "rs_run_recipe -n #{arg}" if arg
96
+ end
97
+
98
+ # (String) recipe id for the schedule
99
+ def recipe_id(arg=nil)
100
+ if Integer(arg) < 0 then raise RangeError end
101
+ if arg.is_a?(Integer)
102
+ converted_arg = arg.to_s
103
+ else
104
+ converted_arg = arg
105
+ end
106
+ set_or_return(
107
+ :recipe_id,
108
+ converted_arg,
109
+ :kind_of => [ String ]
110
+ )
111
+
112
+ @cron_resource.command "rs_run_recipe -i #{converted_arg}" if arg
113
+ end
114
+
115
+ # (String) RightScript's name for the schedule
116
+ def right_script(arg=nil)
117
+ set_or_return(
118
+ :right_script,
119
+ arg,
120
+ :kind_of => [ String ]
121
+ )
122
+
123
+ @cron_resource.command "rs_run_right_script -n #{arg}" if arg
124
+ end
125
+
126
+ # (String) RightScript's id for the schedule
127
+ def right_script_id(arg=nil)
128
+ if Integer(arg) < 0 then raise RangeError end
129
+ if arg.is_a?(Integer)
130
+ converted_arg = arg.to_s
131
+ else
132
+ converted_arg = arg
133
+ end
134
+ set_or_return(
135
+ :right_script_id,
136
+ converted_arg,
137
+ :kind_of => [ String ]
138
+ )
139
+
140
+ @cron_resource.command "rs_run_right_script -i #{converted_arg}" if arg
141
+ end
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,86 @@
1
+ #
2
+ # Copyright (c) 2009-2011 RightScale Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ class Chef
24
+
25
+ class Provider
26
+
27
+ # RemoteRecipe chef provider.
28
+ class RemoteRecipe < Chef::Provider
29
+
30
+ # No concept of a 'current' resource for RemoteRecipe execution, this is a no-op
31
+ #
32
+ # === Return
33
+ # true:: Always return true
34
+ def load_current_resource
35
+ true
36
+ end
37
+
38
+ # Actually run RemoteRecipe
39
+ #
40
+ # === Return
41
+ # true:: Always return true
42
+ def action_run
43
+ tags = @new_resource.recipients_tags
44
+ recipients = @new_resource.recipients
45
+ agent_options = RightScale::OptionsBag.load
46
+ attributes = { :remote_recipe => { :tags => tags,
47
+ :from => agent_options[:identity] } }
48
+ attributes.merge!(@new_resource.attributes) if @new_resource.attributes
49
+ payload = { :recipe => @new_resource.recipe, :json => attributes.to_json }
50
+ if recipients && !recipients.empty?
51
+ target = if (s = recipients.size) == 1
52
+ 'one remote instance'
53
+ else
54
+ "#{s} remote instances"
55
+ end
56
+ Chef::Log.info("Scheduling execution of #{@new_resource.recipe.inspect} on #{target}")
57
+ recipients.each do |recipient|
58
+ RightScale::Cook.instance.send_push('/instance_scheduler/execute', payload, recipient)
59
+ end
60
+ end
61
+ if tags && !tags.empty?
62
+ selector = (@new_resource.scope == :single ? :any : :all)
63
+ target_tag = if tags.size == 1
64
+ "tag #{tags.first.inspect}"
65
+ else
66
+ "tags #{tags.map { |t| t.inspect }.join(', ') }"
67
+ end
68
+ target = if selector == :all
69
+ "all instances with #{target_tag}"
70
+ else
71
+ "one instance with #{target_tag}"
72
+ end
73
+ Chef::Log.info("Scheduling execution of #{@new_resource.recipe.inspect} on #{target}")
74
+ RightScale::Cook.instance.send_push('/instance_scheduler/execute', payload, {:tags => tags, :selector => selector})
75
+ end
76
+ true
77
+ end
78
+
79
+ end
80
+
81
+ end
82
+
83
+ end
84
+
85
+ # self-register
86
+ Chef::Platform.platforms[:default].merge!(:remote_recipe => Chef::Provider::RemoteRecipe)
@@ -0,0 +1,101 @@
1
+ #
2
+ # Copyright (c) 2009-2011 RightScale Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ class Chef
24
+ class Resource
25
+
26
+ # Recipe that should be run on a remote RightLink agent
27
+ #
28
+ class RemoteRecipe < Chef::Resource
29
+
30
+ # Initialize log resource with a name as the string to log
31
+ #
32
+ # === Parameters
33
+ # name(String):: Message to log
34
+ # collection(Array):: Collection of included recipes
35
+ # node(Chef::Node):: Node where resource will be used
36
+ def initialize(name, run_context=nil)
37
+ super(name, run_context)
38
+ @resource_name = :remote_recipe
39
+ @scope = :all
40
+ @action = :run
41
+ @allowed_actions.push(:run)
42
+ end
43
+
44
+ # Name of recipe that should be run remotely
45
+ def recipe(arg=nil)
46
+ set_or_return(
47
+ :recipe,
48
+ arg,
49
+ :kind_of => [ String ]
50
+ )
51
+ end
52
+
53
+ # Override attributes that should be used to run the remote recipe
54
+ def attributes(arg=nil)
55
+ set_or_return(
56
+ :attributes,
57
+ arg,
58
+ :kind_of => [ Hash ]
59
+ )
60
+ end
61
+
62
+ # List of ids of agents that should run the recipe
63
+ # These ids should have been retrieved using the :from attribute
64
+ # of a remote recipe previously run on this agent
65
+ def recipients(arg=nil)
66
+ converted_arg = arg.is_a?(String) ? [ arg ] : arg
67
+ set_or_return(
68
+ :recipients,
69
+ converted_arg,
70
+ :kind_of => [ Array ]
71
+ )
72
+ end
73
+
74
+ # List of tags used to route the request
75
+ # Only instances that expose *all* of the tags in this list
76
+ # will run the recipe
77
+ def recipients_tags(arg=nil)
78
+ converted_arg = arg.is_a?(String) ? [ arg ] : arg
79
+ set_or_return(
80
+ :recipient_tags,
81
+ converted_arg,
82
+ :kind_of => [ Array ]
83
+ )
84
+ end
85
+
86
+ # Scope of remote recipe: whether a single or all potential recipients
87
+ # should run the recipe.
88
+ # Only applies when used in conjunction with +recipients_tags+
89
+ # Defaults to :all
90
+ def scope(arg=nil)
91
+ set_or_return(
92
+ :scope,
93
+ arg,
94
+ :equal_to => [ :single, :all ]
95
+ )
96
+ end
97
+ end
98
+ end
99
+ end
100
+
101
+
@@ -0,0 +1,73 @@
1
+ #
2
+ # Copyright (c) 2009-2012 RightScale Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ class Chef
24
+
25
+ class Provider
26
+
27
+ # RightLinkTag chef provider.
28
+ class RightLinkTag < Chef::Provider
29
+
30
+ # Load current
31
+ #
32
+ # === Return
33
+ # true:: Always return true
34
+ def load_current_resource
35
+ true
36
+ end
37
+
38
+ # Publish tag
39
+ #
40
+ # === Return
41
+ # true:: Always return true
42
+ def action_publish
43
+ RightScale::Cook.instance.add_tag(@new_resource.name, @new_resource.timeout)
44
+ true
45
+ end
46
+
47
+ # Remove tag
48
+ #
49
+ # === Return
50
+ # true:: Always return true
51
+ def action_remove
52
+ RightScale::Cook.instance.remove_tag(@new_resource.name, @new_resource.timeout)
53
+ true
54
+ end
55
+
56
+ # Load current tags
57
+ #
58
+ # === Return
59
+ # true:: Always return true
60
+ def action_load
61
+ tags = RightScale::Cook.instance.load_tags(@new_resource.timeout)
62
+ node[:right_link_tags] = tags
63
+ true
64
+ end
65
+
66
+ end
67
+
68
+ end
69
+
70
+ end
71
+
72
+ # self-register
73
+ Chef::Platform.platforms[:default].merge!(:right_link_tag => Chef::Provider::RightLinkTag)
@@ -0,0 +1,59 @@
1
+ #
2
+ # Copyright (c) 2009-2012 RightScale Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ class Chef
24
+ class Resource
25
+
26
+ # Tag exposed by RightLink agent
27
+ #
28
+ class RightLinkTag < Chef::Resource
29
+
30
+ # Initialize tag resource
31
+ #
32
+ # === Parameters
33
+ # name(String):: Tag name
34
+ # collection(Array):: Collection of included recipes
35
+ # node(Chef::Node):: Node where resource will be used
36
+ def initialize(name, run_context=nil)
37
+ super(name, run_context)
38
+ @resource_name = :right_link_tag
39
+ @action = :publish
40
+ @timeout = 120
41
+ @allowed_actions.push(:publish, :remove, :load)
42
+ end
43
+
44
+ # (Fixnum) Common timeout parameter for command line tools
45
+ def timeout(arg=nil)
46
+ set_or_return(
47
+ :timeout,
48
+ arg,
49
+ :kind_of => [ Fixnum ]
50
+ )
51
+ end
52
+
53
+ end
54
+
55
+ end
56
+
57
+ end
58
+
59
+
@@ -0,0 +1,190 @@
1
+ #
2
+ # Copyright (c) 2009-2012 RightScale Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ require 'fileutils'
24
+ require 'right_popen'
25
+ require 'chef/mixin/command'
26
+
27
+ class Chef
28
+
29
+ class Provider
30
+
31
+ # RightScript chef provider.
32
+ class RightScript < Chef::Provider
33
+
34
+ include Chef::Mixin::Command
35
+
36
+ # No concept of a 'current' resource for RightScript execution, this is a no-op
37
+ #
38
+ # === Return
39
+ # true:: Always return true
40
+ def load_current_resource
41
+ true
42
+ end
43
+
44
+ # runs the RightScript in a child process.
45
+ #
46
+ # === Return
47
+ # true:: Always return true
48
+ #
49
+ # === Raise
50
+ # RightScale::Exceptions::Exec:: Invalid process exit status
51
+ def action_run
52
+ nickname = @new_resource.name
53
+ display_version = @new_resource.display_version || ''
54
+ run_started_at = Time.now
55
+ platform = RightScale::Platform
56
+ current_state = all_state
57
+
58
+ # 1. Setup audit and environment
59
+ begin
60
+ meta_data = ::File.join(RightScale::AgentConfig.cloud_state_dir, 'meta-data-cache.rb')
61
+ #metadata does not exist on all clouds, hence the conditional
62
+ load(meta_data) if ::File.exists?(meta_data)
63
+ rescue Exception => e
64
+ ::Chef::Log.info("Could not load cloud metadata; script will execute without metadata in environment!")
65
+ RightScale::Log.error("Failed loading cloud metadata", e)
66
+ end
67
+ begin
68
+ user_data = ::File.join(RightScale::AgentConfig.cloud_state_dir, 'user-data.rb')
69
+ #user-data should always exist
70
+ load(user_data)
71
+ rescue Exception => e
72
+ ::Chef::Log.info("Could not load user data; script will execute without user data in environment!")
73
+ RightScale::Log.error("Failed loading user data", e)
74
+ end
75
+ @new_resource.parameters.each { |key, val| ENV[key] = val }
76
+
77
+ # Provide the customary RightScript environment metadata
78
+ ENV['ATTACH_DIR'] = ENV['RS_ATTACH_DIR'] = @new_resource.cache_dir
79
+ ENV['RS_ALREADY_RUN'] = current_state[:chef_state].past_scripts.include?(nickname) ? 'true' : nil
80
+ ENV['RS_REBOOT'] = current_state[:cook_state].reboot? ? 'true' : nil
81
+
82
+ # RightScripts expect to find RS_DISTRO, RS_DIST and RS_ARCH in the environment.
83
+ # Massage the distro name into the format they expect (all lower case, one word, no release info).
84
+ if platform.linux?
85
+ distro = platform.flavor.downcase
86
+ ENV['RS_DISTRO'] = distro
87
+ ENV['RS_DIST'] = distro
88
+ arch_info=`uname -i`.downcase + `uname -m`.downcase
89
+ if arch_info =~ /i386/ || arch_info =~ /i686/
90
+ ENV['RS_ARCH'] = "i386"
91
+ elsif arch_info =~ /64/
92
+ ENV['RS_ARCH'] = "x86_64"
93
+ else
94
+ ENV['RS_ARCH'] = "unknown"
95
+ end
96
+ end
97
+
98
+ # Add Cloud-Independent Attributes
99
+ if node[:cloud]
100
+ ENV['RS_CLOUD_PROVIDER'] = node[:cloud][:provider]
101
+ instance_public_ip = node[:cloud][:public_ipv4] || (node[:cloud][:public_ips].is_a?(Array) && node[:cloud][:public_ips].first)
102
+ if instance_public_ip
103
+ ENV['RS_PUBLIC_IP'] = instance_public_ip
104
+ else
105
+ ::Chef::Log.info("Could not retrieve instance public IP")
106
+ end
107
+ instance_private_ip = node[:cloud][:local_ipv4] || (node[:cloud][:private_ips].is_a?(Array) && node[:cloud][:private_ips].first)
108
+ if instance_private_ip
109
+ ENV['RS_PRIVATE_IP'] = instance_private_ip
110
+ else
111
+ ::Chef::Log.info("Could not retrieve instance private IP")
112
+ end
113
+ else
114
+ ::Chef::Log.info("Could not retrieve cloud information")
115
+ end
116
+
117
+ # 2. Fork and wait
118
+ # Bit of a hack here just so we can create a new audit section each time a RightScript is run
119
+ name_and_version = display_version.empty? ?
120
+ "'#{nickname}'" :
121
+ "'#{nickname}' #{display_version}"
122
+
123
+ Chef::Log.logger.create_new_section("RightScript: #{name_and_version}")
124
+
125
+ status = run_script_file(@new_resource.source_file)
126
+ duration = Time.now - run_started_at
127
+ # Security paranoia: wipe inputs from env so next script can't see them
128
+ @new_resource.parameters.each { |key, _| ENV[key] = nil }
129
+
130
+ # 3. Handle process exit status
131
+ if status
132
+ ::Chef::Log.info("Script exit status: #{status.exitstatus}")
133
+ else
134
+ ::Chef::Log.info("Script exit status: UNKNOWN; presumed success")
135
+ end
136
+ ::Chef::Log.info("Script duration: #{duration}")
137
+
138
+ if !status || status.success?
139
+ current_state[:chef_state].record_script_execution(nickname)
140
+ @new_resource.updated_by_last_action(true)
141
+
142
+ # a script may have requested reboot via rs_shutdown command line
143
+ # tool. if the script requested immediate shutdown then we must call
144
+ # exit here to interrupt the Chef converge (assuming any subsequent
145
+ # boot recipes are pending). otherwise, defer shutdown until scripts/
146
+ # recipes finish or another script escalates to an immediate shutdown.
147
+ exit 0 if RightScale::ShutdownRequestProxy.instance.immediately?
148
+ else
149
+ raise RightScale::Exceptions::Exec,
150
+ "RightScript < #{name_and_version} > #{RightScale::SubprocessFormatting.reason(status)}"
151
+ end
152
+
153
+ true
154
+ end
155
+
156
+ protected
157
+
158
+ # Provides a view of the current state objects (instance, chef, ...)
159
+ #
160
+ # == Returns
161
+ # result(Hash):: States:
162
+ # :cook_state(RightScale::CookState):: current cook state
163
+ # :chef_state(RightScale::ChefState):: current chef state
164
+ def all_state
165
+ result = {:cook_state => RightScale::CookState, :chef_state => RightScale::ChefState}
166
+ end
167
+
168
+ # Runs the given RightScript.
169
+ #
170
+ # === Parameters
171
+ # script_file_path(String):: script file path
172
+ #
173
+ # == Returns
174
+ # result(Status):: result of running script
175
+ def run_script_file(script_file_path)
176
+ platform = RightScale::Platform
177
+ shell = platform.shell
178
+ command = shell.format_shell_command(script_file_path)
179
+
180
+ return exec_right_popen(command)
181
+ end
182
+
183
+ end
184
+
185
+ end
186
+
187
+ end
188
+
189
+ # self-register
190
+ Chef::Platform.platforms[:default].merge!(:right_script => Chef::Provider::RightScript)