right_link 5.9.0

Sign up to get free protection for your applications and to get access to all the features.
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,113 @@
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
+ require 'right_agent'
29
+
30
+ class Chef
31
+
32
+ class Resource
33
+
34
+ # RightScript chef resource.
35
+ # Allows defining recipes which wrap RightScripts.
36
+ #
37
+ # === Example
38
+ # right_script "APP Mephisto bootstrap configure v2" do
39
+ # source_file '/tmp/my_right_script'
40
+ # parameters['APPLICATION'] 'My Mephisto App'
41
+ # parameters['DB_SCHEMA_NAME'] 'db_schema'
42
+ # parameters['RAILS_ENV'] 'production'
43
+ # cache_dir '/var/cache/rightscale/app_mephisto'
44
+ # end
45
+ class RightScript < Chef::Resource
46
+
47
+ # Default directory used to cache RightScript source
48
+ DEFAULT_CACHE_DIR_ROOT = ::File.join(RightScale::Platform.filesystem.cache_dir, 'rightscale')
49
+
50
+ # Initialize RightScript resource with default values
51
+ #
52
+ # === Parameters
53
+ # name(String):: Nickname of RightScript
54
+ # collection(Array):: Collection of included recipes
55
+ # node(Chef::Node):: Node where resource will be used
56
+ def initialize(name, run_context=nil)
57
+ super(name, run_context)
58
+ @resource_name = :right_script
59
+ @cache_dir = ::File.join(DEFAULT_CACHE_DIR_ROOT, RightScale::AgentIdentity.generate)
60
+ @parameters = {}
61
+ @display_version = nil
62
+ @action = :run
63
+ @allowed_actions.push(:run)
64
+ end
65
+
66
+ # (String) RightScript nickname
67
+ def nickname(arg=nil)
68
+ set_or_return(
69
+ :nickname,
70
+ arg,
71
+ :kind_of => [ String ]
72
+ )
73
+ end
74
+
75
+ # (String) Path to file containing RightScript source code
76
+ def source_file(arg=nil)
77
+ set_or_return(
78
+ :source_file,
79
+ arg,
80
+ :kind_of => [ String ]
81
+ )
82
+ end
83
+
84
+ # (Hash) RightScript parameters values keyed by names
85
+ def parameters(arg=nil)
86
+ set_or_return(
87
+ :parameters,
88
+ arg,
89
+ :kind_of => [ Hash ]
90
+ )
91
+ end
92
+
93
+ # (String) Displayable version for RightScript (revision, etc.) or nil
94
+ def display_version(arg=nil)
95
+ set_or_return(
96
+ :display_version,
97
+ arg,
98
+ :kind_of => [ String ]
99
+ )
100
+ end
101
+
102
+ # (String) Path to directory where attachments source should be saved
103
+ def cache_dir(arg=nil)
104
+ set_or_return(
105
+ :cache_dir,
106
+ arg,
107
+ :kind_of => [ String ]
108
+ )
109
+ end
110
+
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,75 @@
1
+ #
2
+ # Copyright (c) 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
+ # Scriptable system reboot chef provider.
28
+ class RsShutdown < 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
+ # Schedules a reboot.
39
+ #
40
+ # === Return
41
+ # true:: Always return true
42
+ def action_reboot
43
+ RightScale::ShutdownRequestProxy.submit(:level => ::RightScale::ShutdownRequest::REBOOT, :immediately => @new_resource.immediately)
44
+ exit 0 if @new_resource.immediately
45
+ true
46
+ end
47
+
48
+ # Schedules a reboot.
49
+ #
50
+ # === Return
51
+ # true:: Always return true
52
+ def action_stop
53
+ RightScale::ShutdownRequestProxy.submit(:level => ::RightScale::ShutdownRequest::STOP, :immediately => @new_resource.immediately)
54
+ exit 0 if @new_resource.immediately
55
+ true
56
+ end
57
+
58
+ # Schedules a reboot.
59
+ #
60
+ # === Return
61
+ # true:: Always return true
62
+ def action_terminate
63
+ RightScale::ShutdownRequestProxy.submit(:level => ::RightScale::ShutdownRequest::TERMINATE, :immediately => @new_resource.immediately)
64
+ exit 0 if @new_resource.immediately
65
+ true
66
+ end
67
+
68
+ end
69
+
70
+ end
71
+
72
+ end
73
+
74
+ # self-register
75
+ Chef::Platform.platforms[:default].merge!(:rs_shutdown => Chef::Provider::RsShutdown)
@@ -0,0 +1,55 @@
1
+ #
2
+ # Copyright (c) 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
+ # Scriptable system shutdown chef resource.
27
+ class RsShutdown < Chef::Resource
28
+
29
+ # Initialize rs_shutdown resource
30
+ #
31
+ # === Parameters
32
+ # name(String):: Tag name
33
+ # run_context(Chef::RunContext):: Run context or nil
34
+ def initialize(name, run_context=nil)
35
+ super(name, run_context)
36
+ @resource_name = :rs_shutdown
37
+ @action = :reboot
38
+ @immediately = false
39
+ @allowed_actions.push(:reboot, :stop, :terminate)
40
+ end
41
+
42
+ # (String) RightScript nickname
43
+ def immediately(arg=nil)
44
+ set_or_return(
45
+ :immediately,
46
+ arg,
47
+ :kind_of => [ TrueClass, FalseClass ]
48
+ )
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -0,0 +1,66 @@
1
+ # Copyright (c) 2009-2011 RightScale Inc
2
+ #
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
+ # ServerCollection chef provider.
28
+ # Allows retrieving a set of servers by tags
29
+ class ServerCollection < Chef::Provider
30
+
31
+ # Initialize condition variable used to synchronize chef and EM threads
32
+ def initialize(node, resource, collection=nil, definitions={}, cookbook_loader=nil)
33
+ super(node, resource)
34
+ end
35
+
36
+ # This provider doesn't actually change any state on the server
37
+ #
38
+ # === Return
39
+ # true:: Always return true
40
+ def load_current_resource
41
+ true
42
+ end
43
+
44
+ # Get the tagged servers *synchronously*
45
+ #
46
+ # === Return
47
+ # true:: Always return true
48
+ def action_load
49
+ node[:server_collection] ||= {}
50
+ node[:server_collection][@new_resource.name] = {}
51
+ return unless @new_resource.tags && !@new_resource.tags.empty?
52
+
53
+ result = RightScale::Cook.instance.query_tags(@new_resource.tags, @new_resource.agent_ids, @new_resource.timeout)
54
+ collection = result.inject({}) { |res, (k, v)| res[k] = v['tags']; res }
55
+ node[:server_collection][@new_resource.name] = collection
56
+ true
57
+ end
58
+
59
+ end # ServerCollection
60
+
61
+ end # Provider
62
+
63
+ end # Chef
64
+
65
+ # self-register
66
+ Chef::Platform.platforms[:default].merge!(:server_collection => Chef::Provider::ServerCollection)
@@ -0,0 +1,93 @@
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
+ # Servers with associated tags
27
+ #
28
+ class ServerCollection < Chef::Resource
29
+
30
+ # Initialize resource
31
+ #
32
+ # === Parameters
33
+ # name(String):: Collection 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 = :server_collection
39
+ @action = :load
40
+ @allowed_actions.push(:load)
41
+ @timeout = 120
42
+ end
43
+
44
+ # List of agent ids whose tags should be retrieved
45
+ #
46
+ # === Parameters
47
+ # arg(String|Array):: List of agent ids (or single agent id) to set
48
+ # nil:: Return list instead of setting
49
+ #
50
+ # === Return
51
+ # (Array):: List of agent ids
52
+ def agent_ids(arg=nil)
53
+ converted_arg = arg.is_a?(String) ? [ arg ] : arg
54
+ set_or_return(
55
+ :agent_ids,
56
+ converted_arg,
57
+ :kind_of => [ Array ]
58
+ )
59
+ end
60
+
61
+ # List of tags used to query agents and associated tags
62
+ #
63
+ # === Parameters
64
+ # arg(String|Array):: List of tags (or single tag) to set
65
+ # nil:: Return list instead of setting
66
+ #
67
+ # === Return
68
+ # (Array):: List of tags
69
+ def tags(arg=nil)
70
+ converted_arg = arg.is_a?(String) ? [ arg ] : arg
71
+ set_or_return(
72
+ :tags,
73
+ converted_arg,
74
+ :kind_of => [ Array ]
75
+ )
76
+ end
77
+
78
+ # (Fixnum) Common timeout parameter for command line tools
79
+ def timeout(arg=nil)
80
+ set_or_return(
81
+ :timeout,
82
+ arg,
83
+ :kind_of => [ Fixnum ]
84
+ )
85
+ end
86
+
87
+ end
88
+
89
+ end
90
+
91
+ end
92
+
93
+
@@ -0,0 +1,151 @@
1
+ #
2
+ # Copyright (c) 2010-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
+ require 'fileutils'
24
+ require 'chef/provider/execute'
25
+ require File.normalize_path(File.join(File.dirname(__FILE__), '..', '..', 'windows', 'chef_node_server'))
26
+
27
+ class Chef
28
+
29
+ class Provider
30
+
31
+ # Powershell chef provider.
32
+ class Powershell < Chef::Provider::Execute
33
+
34
+ # use a unique dir name instead of cluttering temp directory with leftover
35
+ # scripts like the original script provider.
36
+ SCRIPT_TEMP_DIR_PATH = ::File.join(::Dir.tmpdir, "chef-powershell-06D9AC00-8D64-4213-A46A-611FBAFB4426")
37
+
38
+ # No concept of a 'current' resource for Powershell execution, this is a no-op
39
+ #
40
+ # === Return
41
+ # true:: Always return true
42
+ def load_current_resource
43
+ true
44
+ end
45
+
46
+ # runs the PowerShell script in a child process.
47
+ #
48
+ # === Return
49
+ # true:: Always return true
50
+ #
51
+ # === Raise
52
+ # RightScale::Exceptions::Exec:: Invalid process exit status
53
+ def action_run
54
+ nickname = @new_resource.name
55
+ source = @new_resource.source
56
+ script_file_path = @new_resource.source_path
57
+ environment = @new_resource.environment
58
+ current_state = all_state
59
+
60
+ # 1. Write script source into file, if necessary.
61
+ if script_file_path
62
+ (raise RightScale::Exceptions::Exec, "Missing script file \"#{script_file_path}\"") unless ::File.file?(script_file_path)
63
+ else
64
+ FileUtils.mkdir_p(SCRIPT_TEMP_DIR_PATH)
65
+ script_file_path = ::File.join(SCRIPT_TEMP_DIR_PATH, "powershell_provider_source.ps1")
66
+ ::File.open(script_file_path, "w") { |f| f.write(source) }
67
+ end
68
+
69
+ begin
70
+ # 2. Setup environment.
71
+ environment = {} if environment.nil?
72
+ environment['RS_ALREADY_RUN'] = current_state[:chef_state].past_scripts.include?(nickname) ? '1' : nil
73
+ environment['RS_REBOOT'] = current_state[:cook_state].reboot?
74
+ @new_resource.environment(environment)
75
+
76
+ # 3. execute and wait
77
+ RightScale::Windows::ChefNodeServer.instance.start(:node => node)
78
+
79
+ # new_resource points to the powershell script resource in this limited
80
+ # context. there is no current resource in script execution context.
81
+ RightScale::Windows::ChefNodeServer.instance.new_resource = @new_resource
82
+
83
+ command = format_command(script_file_path)
84
+ @new_resource.command(command)
85
+ ::Chef::Log.info("Running \"#{nickname}\"")
86
+ super
87
+
88
+ # super provider raises an exception on failure, so record success at
89
+ # this point.
90
+ current_state[:chef_state].record_script_execution(nickname)
91
+ @new_resource.updated_by_last_action(true)
92
+
93
+ # a script may have requested reboot via rs_shutdown command line
94
+ # tool. if the script requested immediate shutdown then we must call
95
+ # exit here to interrupt the Chef converge (assuming any subsequent
96
+ # boot recipes are pending). otherwise, defer shutdown until scripts/
97
+ # recipes finish or another script escalates to an immediate shutdown.
98
+ exit 0 if RightScale::ShutdownRequestProxy.instance.immediately?
99
+ ensure
100
+ (FileUtils.rm_rf(SCRIPT_TEMP_DIR_PATH) rescue nil) if ::File.directory?(SCRIPT_TEMP_DIR_PATH)
101
+ end
102
+
103
+ true
104
+ end
105
+
106
+ protected
107
+
108
+ TEMP_DIR_NAME = 'powershell_provider-B6169A26-91B5-4e3e-93AD-F0B4F6EF107E'
109
+ SOURCE_WINDOWS_PATH = ::File.normalize_path(::File.join(::File.dirname(__FILE__), '..', '..', 'windows'))
110
+ LOCAL_WINDOWS_BIN_PATH = RightScale::Platform.filesystem.ensure_local_drive_path(::File.join(SOURCE_WINDOWS_PATH, 'bin'), TEMP_DIR_NAME)
111
+ CHEF_NODE_CMDLET_DLL_PATH = ::File.normalize_path(::File.join(LOCAL_WINDOWS_BIN_PATH, 'ChefNodeCmdlet.dll')).gsub("/", "\\")
112
+
113
+ # Provides a view of the current state objects (instance, chef, ...)
114
+ #
115
+ # == Returns
116
+ # result(Hash):: States:
117
+ # :cook_state(RightScale::CookState):: current cook state
118
+ # :chef_state(RightScale::ChefState):: current chef state
119
+ def all_state
120
+ result = {:cook_state => RightScale::CookState, :chef_state => RightScale::ChefState}
121
+ end
122
+
123
+
124
+ # Formats a command to run the given powershell script.
125
+ #
126
+ # === Parameters
127
+ # script_file_path(String):: powershell script file path
128
+ #
129
+ # == Returns
130
+ # command(String):: command to execute
131
+ def format_command(script_file_path)
132
+ platform = RightScale::Platform
133
+ shell = platform.shell
134
+
135
+ # import ChefNodeCmdlet.dll to allow powershell scripts to call get-ChefNode, etc.
136
+ lines_before_script = ["import-module #{CHEF_NODE_CMDLET_DLL_PATH}"]
137
+
138
+ # enable debug and verbose powershell output if log level allows for it.
139
+ if ::Chef::Log.debug?
140
+ lines_before_script << "$VerbosePreference = 'Continue'"
141
+ lines_before_script << "$DebugPreference = 'Continue'"
142
+ end
143
+ return shell.format_powershell_command4(@new_resource.interpreter, lines_before_script, nil, script_file_path)
144
+ end
145
+
146
+ end
147
+ end
148
+ end
149
+
150
+ # self-register
151
+ Chef::Platform.platforms[:windows][:default].merge!(:powershell => Chef::Provider::Powershell)
@@ -0,0 +1,111 @@
1
+ #
2
+ # Copyright (c) 2010-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
+ require 'fileutils'
24
+ require 'chef/resource/script'
25
+
26
+ class Chef
27
+
28
+ class Resource
29
+
30
+ # Powershell chef resource.
31
+ # Allows defining recipes which wrap Powershell v1.0 scripts.
32
+ #
33
+ # === Example
34
+ # powershell "My Powershell Script" do
35
+ # source "write-output \"Running powershell v1.0 script\""
36
+ # end
37
+ class Powershell < Chef::Resource::Script
38
+
39
+ # Initialize Powershell resource with default values
40
+ #
41
+ # === Parameters
42
+ # name(String):: Nickname of Powershell
43
+ # collection(Array):: Collection of included recipes
44
+ # node(Chef::Node):: Node where resource will be used
45
+ def initialize(name, run_context=nil)
46
+ super(name, run_context)
47
+ @resource_name = :powershell
48
+ @interpreter = "powershell"
49
+ @parameters = {}
50
+ @source = nil
51
+ @source_path = nil
52
+ @action = :run
53
+ @allowed_actions.push(:run)
54
+ end
55
+
56
+ # (String) Powershell nickname
57
+ def nickname(arg=nil)
58
+ set_or_return(
59
+ :nickname,
60
+ arg,
61
+ :kind_of => [ String ]
62
+ )
63
+ end
64
+
65
+ # (String) text of Powershell source code if inline
66
+ def source(arg=nil)
67
+ set_or_return(
68
+ :source,
69
+ arg,
70
+ :kind_of => [ String ]
71
+ )
72
+ end
73
+
74
+ # (String) local path for external Powershell source file if not inline
75
+ def source_path(arg=nil)
76
+ set_or_return(
77
+ :source_path,
78
+ arg,
79
+ :kind_of => [ String ]
80
+ )
81
+ end
82
+
83
+ # (Hash) Powershell parameters values keyed by names
84
+ def parameters(arg=nil)
85
+ return environment if arg.nil?
86
+
87
+ # FIX: support Windows alpha demo-style parameters for now. document
88
+ # that they are deprecated and to use a simple hash. this method of
89
+ # parameter passing may be deprecated altogether in future.
90
+ if arg.kind_of?(Chef::Node::Attribute)
91
+ arg = arg.attribute
92
+ end
93
+
94
+ # parameters is really a duplication of the environment hash from
95
+ # the ExecuteResource, so merge the two hashes, if necessary. it seems
96
+ # valid to continue to distinguish symantically between parameters and
97
+ # environment because the user does not necessarily need to know that
98
+ # they are implemented to be the same hash.
99
+ env = environment
100
+ if env.nil?
101
+ env = arg
102
+ else
103
+ env.merge!(arg)
104
+ end
105
+ environment(env)
106
+ @parameters = @environment
107
+ end
108
+
109
+ end
110
+ end
111
+ end