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.
- data/actors/agent_manager.rb +88 -0
- data/actors/instance_scheduler.rb +321 -0
- data/actors/instance_services.rb +64 -0
- data/actors/instance_setup.rb +567 -0
- data/bin/cloud +25 -0
- data/bin/cook_runner +44 -0
- data/bin/deploy +120 -0
- data/bin/enroll +385 -0
- data/bin/rad +32 -0
- data/bin/rchk +29 -0
- data/bin/rnac +39 -0
- data/bin/rs_connect +33 -0
- data/bin/rs_log_level +31 -0
- data/bin/rs_ohai +28 -0
- data/bin/rs_reenroll +31 -0
- data/bin/rs_run_recipe +34 -0
- data/bin/rs_run_right_script +34 -0
- data/bin/rs_shutdown +33 -0
- data/bin/rs_tag +33 -0
- data/bin/rs_thunk +33 -0
- data/bin/rstat +31 -0
- data/bin/system +16 -0
- data/ext/Rakefile +18 -0
- data/init/config.yml +5 -0
- data/init/init.rb +79 -0
- data/lib/chef/ohai_setup.rb +51 -0
- data/lib/chef/plugins/cloud.rb +91 -0
- data/lib/chef/plugins/cloudstack.rb +23 -0
- data/lib/chef/plugins/ec2.rb +23 -0
- data/lib/chef/plugins/linux/block_device2.rb +24 -0
- data/lib/chef/plugins/rackspace.rb +23 -0
- data/lib/chef/plugins/rightscale.rb +125 -0
- data/lib/chef/plugins/windows/network.rb +114 -0
- data/lib/chef/plugins.rb +74 -0
- data/lib/chef/providers/dns_dnsmadeeasy_provider.rb +81 -0
- data/lib/chef/providers/dns_resource.rb +100 -0
- data/lib/chef/providers/executable_schedule_provider.rb +70 -0
- data/lib/chef/providers/executable_schedule_resource.rb +144 -0
- data/lib/chef/providers/remote_recipe_provider.rb +86 -0
- data/lib/chef/providers/remote_recipe_resource.rb +101 -0
- data/lib/chef/providers/right_link_tag_provider.rb +73 -0
- data/lib/chef/providers/right_link_tag_resource.rb +59 -0
- data/lib/chef/providers/right_script_provider.rb +190 -0
- data/lib/chef/providers/right_script_resource.rb +113 -0
- data/lib/chef/providers/rs_shutdown_provider.rb +75 -0
- data/lib/chef/providers/rs_shutdown_resource.rb +55 -0
- data/lib/chef/providers/server_collection_provider.rb +66 -0
- data/lib/chef/providers/server_collection_resource.rb +93 -0
- data/lib/chef/providers/windows/powershell_provider.rb +151 -0
- data/lib/chef/providers/windows/powershell_resource.rb +111 -0
- data/lib/chef/providers/windows/unsupported_provider.rb +51 -0
- data/lib/chef/right_providers.rb +55 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/ChefNodeCmdlet.csproj +104 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/ChefNodeCmdlet.dll-Help.xml +141 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/Exceptions.cs +182 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetChefNodeCommand.cs +58 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetChefNodeRequest.cs +46 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetChefNodeResponse.cs +45 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetCurrentResourceCommand.cs +58 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetCurrentResourceRequest.cs +46 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetCurrentResourceResponse.cs +45 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetNewResourceCommand.cs +58 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetNewResourceRequest.cs +46 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetNewResourceResponse.cs +45 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetNextActionCommand.cs +178 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetNextActionRequest.cs +67 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetNextActionResponse.cs +58 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetNodeValueCommandBase.cs +142 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetNodeValueRequestBase.cs +64 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/GetNodeValueResponseBase.cs +69 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/JsonTransport.cs +110 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/PipeClient.cs +158 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/PipeServer.cs +142 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/Properties/AssemblyInfo.cs +16 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/ProtocolConstants.cs +55 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/ProtocolUtilities.cs +77 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/ReadMe.txt +53 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetChefNodeCommand.cs +59 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetChefNodeRequest.cs +46 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetChefNodeResponse.cs +58 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetCurrentResourceCommand.cs +59 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetCurrentResourceRequest.cs +46 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetCurrentResourceResponse.cs +40 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetNewResourceCommand.cs +59 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetNewResourceRequest.cs +46 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetNewResourceResponse.cs +40 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetNodeValueCommandBase.cs +293 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetNodeValueRequestBase.cs +75 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/SetNodeValueResponseBase.cs +45 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet/Transport.cs +91 -0
- data/lib/chef/windows/ChefNodeCmdlet/ChefNodeCmdlet.sln +35 -0
- data/lib/chef/windows/ChefNodeCmdlet/TestChefNodeCmdlet/Program.cs +374 -0
- data/lib/chef/windows/ChefNodeCmdlet/TestChefNodeCmdlet/Properties/AssemblyInfo.cs +16 -0
- data/lib/chef/windows/ChefNodeCmdlet/TestChefNodeCmdlet/TestChefNodeCmdlet.csproj +65 -0
- data/lib/chef/windows/ChefNodeCmdlet/TestNextActionCmdlet/Program.cs +136 -0
- data/lib/chef/windows/ChefNodeCmdlet/TestNextActionCmdlet/Properties/AssemblyInfo.cs +36 -0
- data/lib/chef/windows/ChefNodeCmdlet/TestNextActionCmdlet/ReadMe.txt +46 -0
- data/lib/chef/windows/ChefNodeCmdlet/TestNextActionCmdlet/TestNextActionCmdlet.csproj +68 -0
- data/lib/chef/windows/bin/Newtonsoft.Json.dll +0 -0
- data/lib/chef/windows/chef_node_server.rb +463 -0
- data/lib/chef/windows/dynamic_powershell_provider.rb +296 -0
- data/lib/chef/windows/pipe_server.rb +283 -0
- data/lib/chef/windows/powershell_host.rb +285 -0
- data/lib/chef/windows/powershell_pipe_server.rb +136 -0
- data/lib/chef/windows/powershell_provider_base.rb +92 -0
- data/lib/chef/windows/scripts/run_loop.ps1 +105 -0
- data/lib/clouds/cloud.rb +557 -0
- data/lib/clouds/cloud_factory.rb +250 -0
- data/lib/clouds/cloud_utilities.rb +244 -0
- data/lib/clouds/clouds/azure.rb +106 -0
- data/lib/clouds/clouds/cloudstack.rb +114 -0
- data/lib/clouds/clouds/ec2.rb +113 -0
- data/lib/clouds/clouds/eucalyptus.rb +46 -0
- data/lib/clouds/clouds/google.rb +102 -0
- data/lib/clouds/clouds/none.rb +76 -0
- data/lib/clouds/clouds/openstack.rb +30 -0
- data/lib/clouds/clouds/rackspace-ng.rb +54 -0
- data/lib/clouds/clouds/rackspace.rb +78 -0
- data/lib/clouds/clouds/softlayer.rb +91 -0
- data/lib/clouds/metadata_formatter.rb +108 -0
- data/lib/clouds/metadata_provider.rb +128 -0
- data/lib/clouds/metadata_source.rb +87 -0
- data/lib/clouds/metadata_sources/certificate_metadata_source.rb +207 -0
- data/lib/clouds/metadata_sources/config_drive_metadata_source.rb +129 -0
- data/lib/clouds/metadata_sources/file_metadata_source.rb +74 -0
- data/lib/clouds/metadata_sources/http_metadata_source.rb +277 -0
- data/lib/clouds/metadata_sources/selective_metadata_source.rb +122 -0
- data/lib/clouds/metadata_tree_climber.rb +144 -0
- data/lib/clouds/metadata_writer.rb +155 -0
- data/lib/clouds/metadata_writers/dictionary_metadata_writer.rb +72 -0
- data/lib/clouds/metadata_writers/ruby_metadata_writer.rb +76 -0
- data/lib/clouds/metadata_writers/shell_metadata_writer.rb +121 -0
- data/lib/clouds/register_clouds.rb +34 -0
- data/lib/clouds.rb +32 -0
- data/lib/gem_dependencies.rb +83 -0
- data/lib/git_hooks/commit-msg.rb +7 -0
- data/lib/instance/agent_config.rb +168 -0
- data/lib/instance/agent_watcher.rb +233 -0
- data/lib/instance/audit_cook_stub.rb +104 -0
- data/lib/instance/audit_proxy.rb +247 -0
- data/lib/instance/bundle_queue.rb +104 -0
- data/lib/instance/cook/agent_connection.rb +109 -0
- data/lib/instance/cook/audit_logger.rb +165 -0
- data/lib/instance/cook/audit_stub.rb +142 -0
- data/lib/instance/cook/ca-bundle.crt +2794 -0
- data/lib/instance/cook/chef_state.rb +211 -0
- data/lib/instance/cook/cook.rb +306 -0
- data/lib/instance/cook/cook_state.rb +298 -0
- data/lib/instance/cook/cookbook_path_mapping.rb +66 -0
- data/lib/instance/cook/cookbook_repo_retriever.rb +190 -0
- data/lib/instance/cook/executable_sequence.rb +765 -0
- data/lib/instance/cook/external_parameter_gatherer.rb +190 -0
- data/lib/instance/cook/repose_downloader.rb +349 -0
- data/lib/instance/cook/shutdown_request_proxy.rb +121 -0
- data/lib/instance/cook.rb +41 -0
- data/lib/instance/downloader.rb +208 -0
- data/lib/instance/duplicable.rb +67 -0
- data/lib/instance/exceptions.rb +49 -0
- data/lib/instance/executable_sequence_proxy.rb +278 -0
- data/lib/instance/instance_commands.rb +577 -0
- data/lib/instance/instance_state.rb +633 -0
- data/lib/instance/json_utilities.rb +102 -0
- data/lib/instance/login_manager.rb +533 -0
- data/lib/instance/login_user_manager.rb +522 -0
- data/lib/instance/message_encoder.rb +118 -0
- data/lib/instance/multi_thread_bundle_queue.rb +232 -0
- data/lib/instance/operation_context.rb +60 -0
- data/lib/instance/options_bag.rb +65 -0
- data/lib/instance/payload_formatter.rb +46 -0
- data/lib/instance/policy.rb +53 -0
- data/lib/instance/policy_audit.rb +100 -0
- data/lib/instance/policy_manager.rb +146 -0
- data/lib/instance/reenroll_manager.rb +104 -0
- data/lib/instance/right_scripts_cookbook.rb +181 -0
- data/lib/instance/shutdown_request.rb +221 -0
- data/lib/instance/single_thread_bundle_queue.rb +189 -0
- data/lib/instance/volume_management.rb +450 -0
- data/lib/instance.rb +50 -0
- data/lib/repo_conf_generators/apt_conf_generators.rb +106 -0
- data/lib/repo_conf_generators/gem_conf_generators.rb +80 -0
- data/lib/repo_conf_generators/rightscale_conf_generators.rb +254 -0
- data/lib/repo_conf_generators/rightscale_key.pub +17 -0
- data/lib/repo_conf_generators/yum_conf_generators.rb +225 -0
- data/lib/repo_conf_generators.rb +30 -0
- data/lib/run_shell.rb +28 -0
- data/scripts/agent_checker.rb +571 -0
- data/scripts/agent_controller.rb +247 -0
- data/scripts/agent_deployer.rb +148 -0
- data/scripts/bundle_runner.rb +336 -0
- data/scripts/cloud_controller.rb +176 -0
- data/scripts/log_level_manager.rb +142 -0
- data/scripts/ohai_runner.rb +33 -0
- data/scripts/reenroller.rb +193 -0
- data/scripts/server_importer.rb +293 -0
- data/scripts/shutdown_client.rb +183 -0
- data/scripts/system_configurator.rb +367 -0
- data/scripts/tagger.rb +381 -0
- data/scripts/thunker.rb +356 -0
- metadata +418 -0
@@ -0,0 +1,142 @@
|
|
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.Management.Automation;
|
26
|
+
using System.Threading;
|
27
|
+
using RightScale.Common.Protocol;
|
28
|
+
using RightScale.Chef.Protocol;
|
29
|
+
using RightScale.Powershell.Exceptions;
|
30
|
+
|
31
|
+
namespace RightScale
|
32
|
+
{
|
33
|
+
namespace Powershell
|
34
|
+
{
|
35
|
+
namespace Commands
|
36
|
+
{
|
37
|
+
// Provides a base class for get node commands.
|
38
|
+
public abstract class GetNodeValueCommandBase : Cmdlet
|
39
|
+
{
|
40
|
+
// Path to distinguish child element being requested.
|
41
|
+
[Parameter(ValueFromPipeline = true, Position = 0)]
|
42
|
+
public string[] Path
|
43
|
+
{
|
44
|
+
get { return path; }
|
45
|
+
set { path = value; }
|
46
|
+
}
|
47
|
+
|
48
|
+
// Summary:
|
49
|
+
// Factory method for request from cmdlet parameters.
|
50
|
+
//
|
51
|
+
// Returns:
|
52
|
+
// request object
|
53
|
+
protected abstract GetNodeValueRequestBase CreateRequest();
|
54
|
+
|
55
|
+
// Summary:
|
56
|
+
// Factory method for exception from message.
|
57
|
+
//
|
58
|
+
// Returns:
|
59
|
+
// exception
|
60
|
+
protected abstract ChefNodeCmdletExceptionBase CreateException(string message);
|
61
|
+
|
62
|
+
// Summary:
|
63
|
+
// Factory method for exception from response hash.
|
64
|
+
//
|
65
|
+
// Returns:
|
66
|
+
// exception
|
67
|
+
protected abstract ChefNodeCmdletExceptionBase CreateException(IDictionary responseHash);
|
68
|
+
|
69
|
+
// Summary:
|
70
|
+
// implements required cmdlet processing method.
|
71
|
+
protected override void ProcessRecord()
|
72
|
+
{
|
73
|
+
// iterate attempting to connect, send and receive to Chef node server.
|
74
|
+
for (int tryIndex = 0; tryIndex < Constants.MAX_CLIENT_RETRIES; ++tryIndex)
|
75
|
+
{
|
76
|
+
ITransport transport = new JsonTransport();
|
77
|
+
PipeClient pipeClient = new PipeClient(Constants.CHEF_NODE_PIPE_NAME, transport);
|
78
|
+
|
79
|
+
try
|
80
|
+
{
|
81
|
+
GetNodeValueRequestBase request = CreateRequest();
|
82
|
+
|
83
|
+
pipeClient.Connect(Constants.CHEF_NODE_CONNECT_TIMEOUT_MSECS);
|
84
|
+
|
85
|
+
IDictionary responseHash = (IDictionary)transport.NormalizeDeserializedObject(pipeClient.SendReceive<object>(request));
|
86
|
+
|
87
|
+
if (null == responseHash)
|
88
|
+
{
|
89
|
+
if (tryIndex + 1 < Constants.MAX_CLIENT_RETRIES)
|
90
|
+
{
|
91
|
+
// delay retry a few ticks to yield time in case server is busy.
|
92
|
+
Thread.Sleep(Constants.SLEEP_BETWEEN_CLIENT_RETRIES_MSECS);
|
93
|
+
continue;
|
94
|
+
}
|
95
|
+
else
|
96
|
+
{
|
97
|
+
string message = String.Format("Failed to get expected response after {0} retries.", Constants.MAX_CLIENT_RETRIES);
|
98
|
+
|
99
|
+
throw CreateException(message);
|
100
|
+
}
|
101
|
+
}
|
102
|
+
if (ChefNodeCmdletExceptionBase.HasError(responseHash))
|
103
|
+
{
|
104
|
+
throw CreateException(responseHash);
|
105
|
+
}
|
106
|
+
|
107
|
+
// can't write a null object to pipeline, so write nothing in the null case.
|
108
|
+
object nodeValue = responseHash.Contains(Constants.JSON_NODE_VALUE_KEY) ? responseHash[Constants.JSON_NODE_VALUE_KEY] : null;
|
109
|
+
|
110
|
+
if (null != nodeValue)
|
111
|
+
{
|
112
|
+
WriteObject(nodeValue, nodeValue is ICollection);
|
113
|
+
}
|
114
|
+
|
115
|
+
// done.
|
116
|
+
break;
|
117
|
+
}
|
118
|
+
catch (TimeoutException e)
|
119
|
+
{
|
120
|
+
ThrowTerminatingError(new ErrorRecord(e, "Connection timed out", ErrorCategory.OperationTimeout, pipeClient));
|
121
|
+
}
|
122
|
+
catch (ChefNodeCmdletExceptionBase e)
|
123
|
+
{
|
124
|
+
ThrowTerminatingError(new ErrorRecord(e, "ChefNodeCmdlet exception", ErrorCategory.InvalidResult, pipeClient));
|
125
|
+
}
|
126
|
+
catch (Exception e)
|
127
|
+
{
|
128
|
+
ThrowTerminatingError(new ErrorRecord(e, "Unexpected exception", ErrorCategory.NotSpecified, pipeClient));
|
129
|
+
}
|
130
|
+
finally
|
131
|
+
{
|
132
|
+
pipeClient.Close();
|
133
|
+
pipeClient = null;
|
134
|
+
}
|
135
|
+
}
|
136
|
+
}
|
137
|
+
|
138
|
+
private string[] path;
|
139
|
+
}
|
140
|
+
}
|
141
|
+
}
|
142
|
+
}
|
@@ -0,0 +1,64 @@
|
|
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
|
+
|
26
|
+
namespace RightScale
|
27
|
+
{
|
28
|
+
namespace Chef
|
29
|
+
{
|
30
|
+
namespace Protocol
|
31
|
+
{
|
32
|
+
// Provides a base class for a get node request.
|
33
|
+
public abstract class GetNodeValueRequestBase
|
34
|
+
{
|
35
|
+
public string Command
|
36
|
+
{
|
37
|
+
get { return GetType().Name; }
|
38
|
+
}
|
39
|
+
|
40
|
+
public string[] Path
|
41
|
+
{
|
42
|
+
get { return path; }
|
43
|
+
set { path = value; }
|
44
|
+
}
|
45
|
+
|
46
|
+
public GetNodeValueRequestBase()
|
47
|
+
{
|
48
|
+
}
|
49
|
+
|
50
|
+
public GetNodeValueRequestBase(ICollection path)
|
51
|
+
{
|
52
|
+
this.path = Utilities.CollectionToStringArray(path);
|
53
|
+
}
|
54
|
+
|
55
|
+
public override string ToString()
|
56
|
+
{
|
57
|
+
return String.Format("{0}: {{ Path = node[{1}] }}", Command, String.Join("][", path));
|
58
|
+
}
|
59
|
+
|
60
|
+
private string[] path;
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}
|
@@ -0,0 +1,69 @@
|
|
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
|
+
|
25
|
+
namespace RightScale
|
26
|
+
{
|
27
|
+
namespace Chef
|
28
|
+
{
|
29
|
+
namespace Protocol
|
30
|
+
{
|
31
|
+
// Provides a base class for a get node response.
|
32
|
+
public abstract class GetNodeValueResponseBase
|
33
|
+
{
|
34
|
+
public string[] Path
|
35
|
+
{
|
36
|
+
get { return path; }
|
37
|
+
set { path = value; }
|
38
|
+
}
|
39
|
+
|
40
|
+
public object NodeValue
|
41
|
+
{
|
42
|
+
get { return nodeValue; }
|
43
|
+
set { nodeValue = value; }
|
44
|
+
}
|
45
|
+
|
46
|
+
public GetNodeValueResponseBase()
|
47
|
+
{
|
48
|
+
}
|
49
|
+
|
50
|
+
public GetNodeValueResponseBase(string[] path, object nodeValue)
|
51
|
+
{
|
52
|
+
this.path = path;
|
53
|
+
this.nodeValue = nodeValue;
|
54
|
+
}
|
55
|
+
|
56
|
+
public override string ToString()
|
57
|
+
{
|
58
|
+
return String.Format("{0}: {{ Path = node[{1}], NodeValue = {2} }}",
|
59
|
+
GetType().Name,
|
60
|
+
String.Join("][", path),
|
61
|
+
Utilities.GetPrettyNodeValue(NodeValue));
|
62
|
+
}
|
63
|
+
|
64
|
+
private string[] path;
|
65
|
+
private object nodeValue;
|
66
|
+
}
|
67
|
+
}
|
68
|
+
}
|
69
|
+
}
|
@@ -0,0 +1,110 @@
|
|
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.Collections.Generic;
|
26
|
+
using Newtonsoft.Json;
|
27
|
+
using Newtonsoft.Json.Linq;
|
28
|
+
|
29
|
+
namespace RightScale
|
30
|
+
{
|
31
|
+
namespace Common
|
32
|
+
{
|
33
|
+
namespace Protocol
|
34
|
+
{
|
35
|
+
// implements ITransport in terms of JSON serialization.
|
36
|
+
public class JsonTransport : ITransport
|
37
|
+
{
|
38
|
+
string ITransport.ConvertObjectToString(object data)
|
39
|
+
{
|
40
|
+
return JsonConvert.SerializeObject(data);
|
41
|
+
}
|
42
|
+
|
43
|
+
string ITransport.ConvertObjectToString(object data, bool pretty)
|
44
|
+
{
|
45
|
+
return JsonConvert.SerializeObject(data, pretty ? Formatting.Indented : Formatting.None);
|
46
|
+
}
|
47
|
+
|
48
|
+
T ITransport.ConvertStringToObject<T>(string data)
|
49
|
+
{
|
50
|
+
return JsonConvert.DeserializeObject<T>(data);
|
51
|
+
}
|
52
|
+
|
53
|
+
object ITransport.NormalizeDeserializedObject(object data)
|
54
|
+
{
|
55
|
+
return NormalizeValue(data);
|
56
|
+
}
|
57
|
+
|
58
|
+
// Summary:
|
59
|
+
// implements normalization in terms of the inner types used by this
|
60
|
+
// JSON library. only handles known JSON types and returns any other
|
61
|
+
// types unchanged.
|
62
|
+
//
|
63
|
+
// Parameters:
|
64
|
+
// data:
|
65
|
+
// data to normalize.
|
66
|
+
//
|
67
|
+
// Returns:
|
68
|
+
// normalized data
|
69
|
+
private static object NormalizeValue(object data)
|
70
|
+
{
|
71
|
+
if (data is JValue)
|
72
|
+
{
|
73
|
+
JValue customValue = (JValue)data;
|
74
|
+
|
75
|
+
return customValue.Value;
|
76
|
+
}
|
77
|
+
if (data is JObject)
|
78
|
+
{
|
79
|
+
JObject jobject = (JObject)data;
|
80
|
+
Hashtable normalHash = new Hashtable();
|
81
|
+
|
82
|
+
foreach (JProperty jproperty in jobject.Properties())
|
83
|
+
{
|
84
|
+
string key = jproperty.Name;
|
85
|
+
object value = jproperty.Value;
|
86
|
+
|
87
|
+
normalHash[key] = NormalizeValue(value);
|
88
|
+
}
|
89
|
+
|
90
|
+
return normalHash;
|
91
|
+
}
|
92
|
+
if (data is JArray)
|
93
|
+
{
|
94
|
+
ICollection customCollection = (ICollection)data;
|
95
|
+
ArrayList normalCollection = new ArrayList(customCollection.Count);
|
96
|
+
|
97
|
+
foreach (object customObject in customCollection)
|
98
|
+
{
|
99
|
+
normalCollection.Add(NormalizeValue(customObject));
|
100
|
+
}
|
101
|
+
|
102
|
+
return normalCollection;
|
103
|
+
}
|
104
|
+
|
105
|
+
return data;
|
106
|
+
}
|
107
|
+
}
|
108
|
+
}
|
109
|
+
}
|
110
|
+
}
|
@@ -0,0 +1,158 @@
|
|
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.IO;
|
25
|
+
using System.IO.Pipes;
|
26
|
+
|
27
|
+
namespace RightScale
|
28
|
+
{
|
29
|
+
namespace Common
|
30
|
+
{
|
31
|
+
namespace Protocol
|
32
|
+
{
|
33
|
+
// represents a generic text-based pipe client which communicates via a user-supplied transport.
|
34
|
+
// the transport must convert requests/responses to discrete text messages delimited by newline.
|
35
|
+
public class PipeClient
|
36
|
+
{
|
37
|
+
// Summary:
|
38
|
+
// constructor for a named pipe client.
|
39
|
+
//
|
40
|
+
// Parameters:
|
41
|
+
// pipeName:
|
42
|
+
// name of pipe to use when connecting to server.
|
43
|
+
public PipeClient(string pipeName, ITransport transport)
|
44
|
+
{
|
45
|
+
this.pipeName = pipeName;
|
46
|
+
this.transport = transport;
|
47
|
+
}
|
48
|
+
|
49
|
+
// Summary:
|
50
|
+
// creates a bidirectional pipe client.
|
51
|
+
//
|
52
|
+
// Parameters:
|
53
|
+
// timeoutMsecs:
|
54
|
+
// timeout on waiting for connection in milliseconds
|
55
|
+
//
|
56
|
+
// Throws:
|
57
|
+
// System.TimeoutException on failure to connect
|
58
|
+
public void Connect(int timeoutMsecs)
|
59
|
+
{
|
60
|
+
// create bidirectional pipe client.
|
61
|
+
pipeClient = new NamedPipeClientStream(pipeName);
|
62
|
+
pipeClient.Connect(timeoutMsecs);
|
63
|
+
|
64
|
+
// create writer.
|
65
|
+
streamWriter = new StreamWriter(pipeClient);
|
66
|
+
streamWriter.AutoFlush = true;
|
67
|
+
|
68
|
+
// create reader.
|
69
|
+
streamReader = new StreamReader(pipeClient);
|
70
|
+
}
|
71
|
+
|
72
|
+
// Summary:
|
73
|
+
// sends a request without waiting for a response.
|
74
|
+
//
|
75
|
+
// Parameters:
|
76
|
+
// request:
|
77
|
+
// request to send
|
78
|
+
public void Send(object request)
|
79
|
+
{
|
80
|
+
// send.
|
81
|
+
string text = transport.ConvertObjectToString(request);
|
82
|
+
|
83
|
+
streamWriter.WriteLine(text);
|
84
|
+
}
|
85
|
+
|
86
|
+
// Summary:
|
87
|
+
// sends/receives a request/response pair.
|
88
|
+
//
|
89
|
+
// Parameters:
|
90
|
+
// T:
|
91
|
+
// expected type for response
|
92
|
+
//
|
93
|
+
// request:
|
94
|
+
// request to send
|
95
|
+
//
|
96
|
+
// Returns:
|
97
|
+
// received response object
|
98
|
+
public T SendReceive<T>(object request)
|
99
|
+
{
|
100
|
+
// send.
|
101
|
+
Send(request);
|
102
|
+
|
103
|
+
// receive.
|
104
|
+
{
|
105
|
+
string text = streamReader.ReadLine();
|
106
|
+
|
107
|
+
return (null == text) ? default(T) : transport.ConvertStringToObject<T>(text);
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
// Summary:
|
112
|
+
// closes the client and releases all resources.
|
113
|
+
public void Close()
|
114
|
+
{
|
115
|
+
if (null != streamReader)
|
116
|
+
{
|
117
|
+
try
|
118
|
+
{
|
119
|
+
streamReader.Close();
|
120
|
+
}
|
121
|
+
catch (Exception)
|
122
|
+
{
|
123
|
+
}
|
124
|
+
streamReader = null;
|
125
|
+
}
|
126
|
+
if (null != streamWriter)
|
127
|
+
{
|
128
|
+
try
|
129
|
+
{
|
130
|
+
streamWriter.Close();
|
131
|
+
}
|
132
|
+
catch (Exception)
|
133
|
+
{
|
134
|
+
}
|
135
|
+
streamWriter = null;
|
136
|
+
}
|
137
|
+
if (null != pipeClient)
|
138
|
+
{
|
139
|
+
try
|
140
|
+
{
|
141
|
+
pipeClient.Close();
|
142
|
+
}
|
143
|
+
catch (Exception)
|
144
|
+
{
|
145
|
+
}
|
146
|
+
pipeClient = null;
|
147
|
+
}
|
148
|
+
}
|
149
|
+
|
150
|
+
private ITransport transport = null;
|
151
|
+
private NamedPipeClientStream pipeClient = null;
|
152
|
+
private StreamReader streamReader = null;
|
153
|
+
private StreamWriter streamWriter = null;
|
154
|
+
private string pipeName = null;
|
155
|
+
}
|
156
|
+
}
|
157
|
+
}
|
158
|
+
}
|