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,35 @@
1
+ 
2
+ Microsoft Visual Studio Solution File, Format Version 10.00
3
+ # Visual Studio 2008
4
+ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChefNodeCmdlet", "ChefNodeCmdlet\ChefNodeCmdlet.csproj", "{F421745A-3ADE-473A-83DE-C7A3DF1B9557}"
5
+ EndProject
6
+ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestChefNodeCmdlet", "TestChefNodeCmdlet\TestChefNodeCmdlet.csproj", "{3691CA56-6927-4789-9102-0841E99B3F16}"
7
+ ProjectSection(ProjectDependencies) = postProject
8
+ {F421745A-3ADE-473A-83DE-C7A3DF1B9557} = {F421745A-3ADE-473A-83DE-C7A3DF1B9557}
9
+ EndProjectSection
10
+ EndProject
11
+ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestNextActionCmdlet", "TestNextActionCmdlet\TestNextActionCmdlet.csproj", "{9AF14C55-5808-4335-9BAA-74BD8DE5205B}"
12
+ EndProject
13
+ Global
14
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
15
+ Debug|Any CPU = Debug|Any CPU
16
+ Release|Any CPU = Release|Any CPU
17
+ EndGlobalSection
18
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
19
+ {F421745A-3ADE-473A-83DE-C7A3DF1B9557}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20
+ {F421745A-3ADE-473A-83DE-C7A3DF1B9557}.Debug|Any CPU.Build.0 = Debug|Any CPU
21
+ {F421745A-3ADE-473A-83DE-C7A3DF1B9557}.Release|Any CPU.ActiveCfg = Release|Any CPU
22
+ {F421745A-3ADE-473A-83DE-C7A3DF1B9557}.Release|Any CPU.Build.0 = Release|Any CPU
23
+ {3691CA56-6927-4789-9102-0841E99B3F16}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24
+ {3691CA56-6927-4789-9102-0841E99B3F16}.Debug|Any CPU.Build.0 = Debug|Any CPU
25
+ {3691CA56-6927-4789-9102-0841E99B3F16}.Release|Any CPU.ActiveCfg = Release|Any CPU
26
+ {3691CA56-6927-4789-9102-0841E99B3F16}.Release|Any CPU.Build.0 = Release|Any CPU
27
+ {9AF14C55-5808-4335-9BAA-74BD8DE5205B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
28
+ {9AF14C55-5808-4335-9BAA-74BD8DE5205B}.Debug|Any CPU.Build.0 = Debug|Any CPU
29
+ {9AF14C55-5808-4335-9BAA-74BD8DE5205B}.Release|Any CPU.ActiveCfg = Release|Any CPU
30
+ {9AF14C55-5808-4335-9BAA-74BD8DE5205B}.Release|Any CPU.Build.0 = Release|Any CPU
31
+ EndGlobalSection
32
+ GlobalSection(SolutionProperties) = preSolution
33
+ HideSolutionNode = FALSE
34
+ EndGlobalSection
35
+ EndGlobal
@@ -0,0 +1,374 @@
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
+ using System;
24
+ using System.Collections;
25
+ using System.IO;
26
+ using System.IO.Pipes;
27
+ using RightScale.Chef.Protocol;
28
+ using RightScale.Common.Protocol;
29
+
30
+ namespace TestChefNodeCmdlet
31
+ {
32
+ class Program
33
+ {
34
+ static void Main(string[] args)
35
+ {
36
+ // resolve persistent node path.
37
+ string nodeFilePath = null;
38
+
39
+ if (2 == args.Length && args[0] == "-nf")
40
+ {
41
+ nodeFilePath = args[1];
42
+ }
43
+ else
44
+ {
45
+ Console.WriteLine("Usage: TestChefNodeCmdlet -nf <nodefile>");
46
+ Console.WriteLine();
47
+ Console.WriteLine("The nodefile is a JSON text file containing initial values and which receives any modified node values.");
48
+ return;
49
+ }
50
+
51
+ // load initial node values, if any.
52
+ string nodeFileText = ReadTextFile(nodeFilePath);
53
+
54
+ // use JSON transport to unmarshal initial nodes.
55
+ ITransport transport = new JsonTransport();
56
+ IDictionary nodeHash = new Hashtable();
57
+
58
+ if (nodeFileText.Length > 0)
59
+ {
60
+ nodeHash = (IDictionary)transport.NormalizeDeserializedObject(transport.ConvertStringToObject<object>(nodeFileText));
61
+ }
62
+
63
+ // current and new resource hashes.
64
+ IDictionary currentResourceHash = new Hashtable();
65
+ currentResourceHash.Add("name", "test name");
66
+
67
+ IDictionary newResourceHash = new Hashtable(currentResourceHash);
68
+
69
+ // create pipe server using JSON as transport.
70
+ PipeServer pipeServer = new PipeServer(Constants.CHEF_NODE_PIPE_NAME, transport);
71
+
72
+ Console.WriteLine("Hit Ctrl+C to stop the server.");
73
+ for (; ; )
74
+ {
75
+ try
76
+ {
77
+ Console.WriteLine("Waiting for client to connect...");
78
+ pipeServer.WaitForConnection();
79
+ for (; ; )
80
+ {
81
+ // use duck typing to determine type of request.
82
+ IDictionary requestHash = (IDictionary)transport.NormalizeDeserializedObject(pipeServer.Receive<object>());
83
+
84
+ if (null == requestHash)
85
+ {
86
+ break;
87
+ }
88
+
89
+ bool validRequest = false;
90
+
91
+ if (requestHash.Contains(Constants.JSON_COMMAND_KEY))
92
+ {
93
+ if (requestHash.Contains(Constants.JSON_PATH_KEY) && requestHash.Contains(Constants.JSON_NODE_VALUE_KEY))
94
+ {
95
+ if (requestHash[Constants.JSON_COMMAND_KEY].ToString() == "SetChefNodeRequest")
96
+ {
97
+ SetChefNodeRequest request = new SetChefNodeRequest((ICollection)requestHash[Constants.JSON_PATH_KEY],
98
+ requestHash[Constants.JSON_NODE_VALUE_KEY]);
99
+ Console.WriteLine(String.Format("Received: {0}", request.ToString()));
100
+
101
+ InsertNodeHash(nodeHash, request.Path, transport.NormalizeDeserializedObject(request.NodeValue));
102
+
103
+ SetChefNodeResponse response = new SetChefNodeResponse(request.Path);
104
+ Console.WriteLine(String.Format("Responding: {0}", response.ToString()));
105
+ pipeServer.Send(response);
106
+
107
+ // save change to node file.
108
+ WriteTextFile(nodeFilePath, transport.ConvertObjectToString(nodeHash, true));
109
+ validRequest = true;
110
+ }
111
+ else if (requestHash[Constants.JSON_COMMAND_KEY].ToString() == "SetCurrentResourceRequest")
112
+ {
113
+ SetCurrentResourceRequest request = new SetCurrentResourceRequest((ICollection)requestHash[Constants.JSON_PATH_KEY],
114
+ requestHash[Constants.JSON_NODE_VALUE_KEY]);
115
+ Console.WriteLine(String.Format("Received: {0}", request.ToString()));
116
+
117
+ InsertNodeHash(currentResourceHash, request.Path, transport.NormalizeDeserializedObject(request.NodeValue));
118
+
119
+ SetCurrentResourceResponse response = new SetCurrentResourceResponse();
120
+ Console.WriteLine(String.Format("Responding: {0}", response.ToString()));
121
+ pipeServer.Send(response);
122
+ validRequest = true;
123
+ }
124
+ else if (requestHash[Constants.JSON_COMMAND_KEY].ToString() == "SetNewResourceRequest")
125
+ {
126
+ SetNewResourceRequest request = new SetNewResourceRequest((ICollection)requestHash[Constants.JSON_PATH_KEY],
127
+ requestHash[Constants.JSON_NODE_VALUE_KEY]);
128
+ Console.WriteLine(String.Format("Received: {0}", request.ToString()));
129
+
130
+ InsertNodeHash(newResourceHash, request.Path, transport.NormalizeDeserializedObject(request.NodeValue));
131
+
132
+ SetNewResourceResponse response = new SetNewResourceResponse();
133
+ Console.WriteLine(String.Format("Responding: {0}", response.ToString()));
134
+ pipeServer.Send(response);
135
+ validRequest = true;
136
+ }
137
+ }
138
+ else if (requestHash.Contains(Constants.JSON_PATH_KEY))
139
+ {
140
+ if (requestHash[Constants.JSON_COMMAND_KEY].ToString() == "GetChefNodeRequest")
141
+ {
142
+ GetChefNodeRequest request = new GetChefNodeRequest((ICollection)requestHash[Constants.JSON_PATH_KEY]);
143
+ Console.WriteLine(String.Format("Received: {0}", request.ToString()));
144
+
145
+ object nodeValue = QueryNodeHash(nodeHash, request.Path);
146
+ GetChefNodeResponse response = new GetChefNodeResponse(request.Path, nodeValue);
147
+
148
+ Console.WriteLine(String.Format("Responding: {0}", response.ToString()));
149
+ pipeServer.Send(response);
150
+ validRequest = true;
151
+ }
152
+ else if (requestHash[Constants.JSON_COMMAND_KEY].ToString() == "GetCurrentResourceRequest")
153
+ {
154
+ GetCurrentResourceRequest request = new GetCurrentResourceRequest((ICollection)requestHash[Constants.JSON_PATH_KEY]);
155
+ Console.WriteLine(String.Format("Received: {0}", request.ToString()));
156
+
157
+ object nodeValue = QueryNodeHash(currentResourceHash, request.Path);
158
+ GetCurrentResourceResponse response = new GetCurrentResourceResponse(request.Path, nodeValue);
159
+
160
+ Console.WriteLine(String.Format("Responding: {0}", response.ToString()));
161
+ pipeServer.Send(response);
162
+ validRequest = true;
163
+ }
164
+ else if (requestHash[Constants.JSON_COMMAND_KEY].ToString() == "GetNewResourceRequest")
165
+ {
166
+ GetNewResourceRequest request = new GetNewResourceRequest((ICollection)requestHash[Constants.JSON_PATH_KEY]);
167
+ Console.WriteLine(String.Format("Received: {0}", request.ToString()));
168
+
169
+ object nodeValue = QueryNodeHash(newResourceHash, request.Path);
170
+ GetNewResourceResponse response = new GetNewResourceResponse(request.Path, nodeValue);
171
+
172
+ Console.WriteLine(String.Format("Responding: {0}", response.ToString()));
173
+ pipeServer.Send(response);
174
+ validRequest = true;
175
+ }
176
+ }
177
+ }
178
+ if (false == validRequest)
179
+ {
180
+ // unknown request type; hang up and try again.
181
+ break;
182
+ }
183
+ }
184
+ }
185
+ catch (Exception e)
186
+ {
187
+ Console.WriteLine(e.Message);
188
+ }
189
+ finally
190
+ {
191
+ pipeServer.Close();
192
+ }
193
+ }
194
+ }
195
+
196
+ // Summary:
197
+ // inserts a node value at the hash depth indicated by path.
198
+ //
199
+ // Parameters:
200
+ // nodeHash:
201
+ // node hash
202
+ //
203
+ // path:
204
+ // path into hash where each array element represents a level of hash depth.
205
+ //
206
+ // nodeValue:
207
+ // node value to insert.
208
+ private static void InsertNodeHash(IDictionary nodeHash, string[] path, object nodeValue)
209
+ {
210
+ for (int pathIndex = 0, pathCount = path.Length; pathIndex < pathCount; ++pathIndex)
211
+ {
212
+ string key = path[pathIndex];
213
+
214
+ // insert node value if at end of path.
215
+ if (pathIndex + 1 == pathCount)
216
+ {
217
+ if (nodeHash.Contains(key))
218
+ {
219
+ nodeHash.Remove(key);
220
+ }
221
+ nodeHash.Add(key, nodeValue);
222
+ }
223
+ else
224
+ {
225
+ // insert/update a child hash and continue.
226
+ IDictionary subHash = null;
227
+
228
+ if (nodeHash.Contains(key))
229
+ {
230
+ object child = nodeHash[key];
231
+
232
+ if (child is IDictionary)
233
+ {
234
+ subHash = (IDictionary)child;
235
+ }
236
+ else
237
+ {
238
+ nodeHash.Remove(key);
239
+ }
240
+ }
241
+ if (null == subHash)
242
+ {
243
+ subHash = new Hashtable();
244
+ nodeHash.Add(key, subHash);
245
+ }
246
+ nodeHash = subHash;
247
+ }
248
+ }
249
+ }
250
+
251
+ // Summary:
252
+ // queries a node value at the hash depth indicated by path.
253
+ //
254
+ // Parameters:
255
+ // nodeHash:
256
+ // node hash
257
+ //
258
+ // path:
259
+ // path into hash where each array element represents a level of hash depth.
260
+ //
261
+ // Returns:
262
+ // node value to insert.
263
+ private static object QueryNodeHash(IDictionary nodeHash, string[] path)
264
+ {
265
+ // special case for querying the root hash.
266
+ if (1 == path.Length && 0 == path[0].Length)
267
+ {
268
+ return nodeHash;
269
+ }
270
+ for (int pathIndex = 0, pathCount = path.Length; pathIndex < pathCount; ++pathIndex)
271
+ {
272
+ string key = path[pathIndex];
273
+
274
+ if (pathIndex + 1 == pathCount)
275
+ {
276
+ return nodeHash.Contains(key) ? nodeHash[key] : null;
277
+ }
278
+ if (nodeHash.Contains(key))
279
+ {
280
+ object child = nodeHash[key];
281
+
282
+ if (child is IDictionary)
283
+ {
284
+ nodeHash = (IDictionary)child;
285
+ }
286
+ else
287
+ {
288
+ break;
289
+ }
290
+ }
291
+ else
292
+ {
293
+ break;
294
+ }
295
+ }
296
+
297
+ return null;
298
+ }
299
+
300
+ // Summary:
301
+ // reads a text file and returns its content as a string.
302
+ //
303
+ // Parameters:
304
+ // filePath:
305
+ // path to text file
306
+ //
307
+ // Returns:
308
+ // text read from file or empty.
309
+ public static string ReadTextFile(string filePath)
310
+ {
311
+ FileStream fileStream = null;
312
+ StreamReader streamReader = null;
313
+
314
+ try
315
+ {
316
+ fileStream = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Read);
317
+ streamReader = new StreamReader(fileStream);
318
+
319
+ return streamReader.ReadToEnd();
320
+ }
321
+ catch (IOException)
322
+ {
323
+ return "";
324
+ }
325
+ finally
326
+ {
327
+ if (null != streamReader)
328
+ {
329
+ streamReader.Close();
330
+ streamReader = null;
331
+ }
332
+ if (null != fileStream)
333
+ {
334
+ fileStream.Close();
335
+ fileStream = null;
336
+ }
337
+ }
338
+ }
339
+
340
+ // Summary:
341
+ // writes the text given as a string to the given file.
342
+ public static void WriteTextFile(string filePath, string text)
343
+ {
344
+ StreamWriter streamWriter = null;
345
+
346
+ try
347
+ {
348
+ string parentDirPath = Path.GetDirectoryName(filePath);
349
+
350
+ if (parentDirPath.Length > 0 && false == Directory.Exists(parentDirPath))
351
+ {
352
+ Directory.CreateDirectory(parentDirPath);
353
+ }
354
+
355
+ streamWriter = File.CreateText(filePath);
356
+ streamWriter.Write(text);
357
+ streamWriter.Flush();
358
+ }
359
+ finally
360
+ {
361
+ if (null != streamWriter)
362
+ {
363
+ try
364
+ {
365
+ streamWriter.Close();
366
+ }
367
+ catch (Exception)
368
+ {
369
+ }
370
+ }
371
+ }
372
+ }
373
+ }
374
+ }
@@ -0,0 +1,16 @@
1
+ using System.Reflection;
2
+ using System.Runtime.CompilerServices;
3
+ using System.Runtime.InteropServices;
4
+
5
+ [assembly: AssemblyTitle("TestChefNodeCmdlet")]
6
+ [assembly: AssemblyDescription("")]
7
+ [assembly: AssemblyConfiguration("")]
8
+ [assembly: AssemblyCompany("RightScale")]
9
+ [assembly: AssemblyProduct("TestChefNodeCmdlet")]
10
+ [assembly: AssemblyCopyright("Copyright (c) 2010-2011 RightScale Inc")]
11
+ [assembly: AssemblyTrademark("")]
12
+ [assembly: AssemblyCulture("")]
13
+ [assembly: ComVisible(false)]
14
+ [assembly: Guid("779c8da1-7f5d-4d15-a84b-329070ac87f1")]
15
+ [assembly: AssemblyVersion("1.0.0.1")]
16
+ [assembly: AssemblyFileVersion("1.0.0.1")]
@@ -0,0 +1,65 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
+ <PropertyGroup>
4
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6
+ <ProductVersion>9.0.30729</ProductVersion>
7
+ <SchemaVersion>2.0</SchemaVersion>
8
+ <ProjectGuid>{3691CA56-6927-4789-9102-0841E99B3F16}</ProjectGuid>
9
+ <OutputType>Exe</OutputType>
10
+ <AppDesignerFolder>Properties</AppDesignerFolder>
11
+ <RootNamespace>TestChefNodeCmdlet</RootNamespace>
12
+ <AssemblyName>TestChefNodeCmdlet</AssemblyName>
13
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
14
+ <FileAlignment>512</FileAlignment>
15
+ </PropertyGroup>
16
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17
+ <DebugSymbols>true</DebugSymbols>
18
+ <DebugType>full</DebugType>
19
+ <Optimize>false</Optimize>
20
+ <OutputPath>$(SolutionDir)\$(Configuration)</OutputPath>
21
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
22
+ <ErrorReport>prompt</ErrorReport>
23
+ <WarningLevel>4</WarningLevel>
24
+ </PropertyGroup>
25
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26
+ <DebugType>pdbonly</DebugType>
27
+ <Optimize>true</Optimize>
28
+ <OutputPath>$(SolutionDir)\$(Configuration)</OutputPath>
29
+ <DefineConstants>TRACE</DefineConstants>
30
+ <ErrorReport>prompt</ErrorReport>
31
+ <WarningLevel>4</WarningLevel>
32
+ </PropertyGroup>
33
+ <ItemGroup>
34
+ <Reference Include="System" />
35
+ <Reference Include="System.Core">
36
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
37
+ </Reference>
38
+ <Reference Include="System.Xml.Linq">
39
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
40
+ </Reference>
41
+ <Reference Include="System.Data.DataSetExtensions">
42
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
43
+ </Reference>
44
+ <Reference Include="System.Data" />
45
+ <Reference Include="System.Xml" />
46
+ </ItemGroup>
47
+ <ItemGroup>
48
+ <Compile Include="Program.cs" />
49
+ <Compile Include="Properties\AssemblyInfo.cs" />
50
+ </ItemGroup>
51
+ <ItemGroup>
52
+ <ProjectReference Include="..\ChefNodeCmdlet\ChefNodeCmdlet.csproj">
53
+ <Project>{F421745A-3ADE-473A-83DE-C7A3DF1B9557}</Project>
54
+ <Name>ChefNodeCmdlet</Name>
55
+ </ProjectReference>
56
+ </ItemGroup>
57
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
58
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
59
+ Other similar extension points exist, see Microsoft.Common.targets.
60
+ <Target Name="BeforeBuild">
61
+ </Target>
62
+ <Target Name="AfterBuild">
63
+ </Target>
64
+ -->
65
+ </Project>
@@ -0,0 +1,136 @@
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
+ using System;
24
+ using System.Collections;
25
+ using System.IO;
26
+ using System.IO.Pipes;
27
+ using RightScale.Chef.Protocol;
28
+ using RightScale.Common.Protocol;
29
+
30
+ namespace TestNextActionCmdlet
31
+ {
32
+ class Program
33
+ {
34
+ static void Main(string[] args)
35
+ {
36
+ // resolve persistent node path.
37
+ string pipeName = null;
38
+ string nextActionPath = null;
39
+
40
+ if (4 == args.Length && args[0] == "-pn" && args[2] == "-na")
41
+ {
42
+ pipeName = args[1];
43
+ nextActionPath = args[3];
44
+ }
45
+ else
46
+ {
47
+ Console.WriteLine("Usage: -pn <pipe name> -na <next action file path>");
48
+ Console.WriteLine();
49
+ Console.WriteLine("The <pipe name> is any legal file name which uniquely distinguishes the pipe server.");
50
+ Console.WriteLine("The <next action file path> is a text file containing a list of actions to execute in PowerShell.");
51
+ return;
52
+ }
53
+
54
+ FileStream fileStream = null;
55
+ StreamReader streamReader = null;
56
+
57
+ try
58
+ {
59
+ // read next action file linewise.
60
+ fileStream = new FileStream(nextActionPath, FileMode.OpenOrCreate, FileAccess.Read);
61
+ streamReader = new StreamReader(fileStream);
62
+
63
+ // use JSON transport to unmarshal initial nodes.
64
+ ITransport transport = new JsonTransport();
65
+
66
+ // create pipe server using JSON as transport.
67
+ PipeServer pipeServer = new PipeServer(pipeName, transport);
68
+
69
+ Console.WriteLine("Hit Ctrl+C to stop the server.");
70
+
71
+ bool moreCommands = true;
72
+
73
+ while (moreCommands)
74
+ {
75
+ try
76
+ {
77
+ Console.WriteLine("Waiting for client to connect...");
78
+ pipeServer.WaitForConnection();
79
+
80
+ GetNextActionRequest request = pipeServer.Receive<GetNextActionRequest>();
81
+
82
+ if (null == request)
83
+ {
84
+ break;
85
+ }
86
+ Console.WriteLine(String.Format("Received: {0}", request.ToString()));
87
+
88
+ for (;;)
89
+ {
90
+ string nextLine = streamReader.ReadLine();
91
+
92
+ if (null == nextLine)
93
+ {
94
+ moreCommands = false;
95
+ nextLine = "exit";
96
+ }
97
+ if (nextLine.Trim().Length > 0)
98
+ {
99
+ GetNextActionResponse response = new GetNextActionResponse(nextLine);
100
+
101
+ Console.WriteLine(String.Format("Responding: {0}", response.ToString()));
102
+ pipeServer.Send(response);
103
+ break;
104
+ }
105
+ }
106
+ }
107
+ catch (Exception e)
108
+ {
109
+ Console.WriteLine(e.Message);
110
+ }
111
+ finally
112
+ {
113
+ pipeServer.Close();
114
+ }
115
+ }
116
+ }
117
+ catch (IOException e)
118
+ {
119
+ Console.WriteLine(e.Message);
120
+ }
121
+ finally
122
+ {
123
+ if (null != streamReader)
124
+ {
125
+ streamReader.Close();
126
+ streamReader = null;
127
+ }
128
+ if (null != fileStream)
129
+ {
130
+ fileStream.Close();
131
+ fileStream = null;
132
+ }
133
+ }
134
+ }
135
+ }
136
+ }
@@ -0,0 +1,36 @@
1
+ using System.Reflection;
2
+ using System.Runtime.CompilerServices;
3
+ using System.Runtime.InteropServices;
4
+
5
+ // General Information about an assembly is controlled through the following
6
+ // set of attributes. Change these attribute values to modify the information
7
+ // associated with an assembly.
8
+ [assembly: AssemblyTitle("TestNextActionCmdlet")]
9
+ [assembly: AssemblyDescription("")]
10
+ [assembly: AssemblyConfiguration("")]
11
+ [assembly: AssemblyCompany("Microsoft")]
12
+ [assembly: AssemblyProduct("TestNextActionCmdlet")]
13
+ [assembly: AssemblyCopyright("Copyright (c) 2010-2011 RightScale Inc")]
14
+ [assembly: AssemblyTrademark("")]
15
+ [assembly: AssemblyCulture("")]
16
+
17
+ // Setting ComVisible to false makes the types in this assembly not visible
18
+ // to COM components. If you need to access a type in this assembly from
19
+ // COM, set the ComVisible attribute to true on that type.
20
+ [assembly: ComVisible(false)]
21
+
22
+ // The following GUID is for the ID of the typelib if this project is exposed to COM
23
+ [assembly: Guid("721bf2bf-e02b-48fa-bac3-d0d189195f96")]
24
+
25
+ // Version information for an assembly consists of the following four values:
26
+ //
27
+ // Major Version
28
+ // Minor Version
29
+ // Build Number
30
+ // Revision
31
+ //
32
+ // You can specify all the values or you can default the Build and Revision Numbers
33
+ // by using the '*' as shown below:
34
+ // [assembly: AssemblyVersion("1.0.*")]
35
+ [assembly: AssemblyVersion("1.0.0.1")]
36
+ [assembly: AssemblyFileVersion("1.0.0.1")]