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,59 @@
|
|
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 the Set-NewResource cmdlet.
|
38
|
+
[Cmdlet(VerbsCommon.Set, "NewResource")]
|
39
|
+
[CmdletBinding(DefaultParameterSetName = "ByPositionStringParameterSetName")]
|
40
|
+
public class SetNewResourceCommand : SetNodeValueCommandBase
|
41
|
+
{
|
42
|
+
protected override SetNodeValueRequestBase CreateRequest()
|
43
|
+
{
|
44
|
+
return new SetNewResourceRequest(Path, GetNormalizedValue());
|
45
|
+
}
|
46
|
+
|
47
|
+
protected override ChefNodeCmdletExceptionBase CreateException(string message)
|
48
|
+
{
|
49
|
+
return new SetNewResourceException(message);
|
50
|
+
}
|
51
|
+
|
52
|
+
protected override ChefNodeCmdletExceptionBase CreateException(IDictionary responseHash)
|
53
|
+
{
|
54
|
+
return new SetNewResourceException(responseHash);
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}
|
59
|
+
}
|
@@ -0,0 +1,46 @@
|
|
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
|
+
// data for a Set-NewResource request
|
33
|
+
public class SetNewResourceRequest : SetNodeValueRequestBase
|
34
|
+
{
|
35
|
+
public SetNewResourceRequest()
|
36
|
+
{
|
37
|
+
}
|
38
|
+
|
39
|
+
public SetNewResourceRequest(ICollection path, object nodeValue)
|
40
|
+
: base(path, nodeValue)
|
41
|
+
{
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
@@ -0,0 +1,40 @@
|
|
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
|
+
// data for a Set-NewResource response
|
32
|
+
public class SetNewResourceResponse : SetNodeValueResponseBase
|
33
|
+
{
|
34
|
+
public SetNewResourceResponse()
|
35
|
+
{
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
}
|
@@ -0,0 +1,293 @@
|
|
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
|
+
public abstract class SetNodeValueCommandBase : Cmdlet
|
38
|
+
{
|
39
|
+
[Parameter(ValueFromPipeline = true, Position = 0, Mandatory = true)]
|
40
|
+
public string[] Path
|
41
|
+
{
|
42
|
+
get { return path; }
|
43
|
+
set { path = value; }
|
44
|
+
}
|
45
|
+
|
46
|
+
[Parameter(ValueFromPipeline = true, Position = 1, ParameterSetName = "StringParameterSetName")]
|
47
|
+
public String StringValue
|
48
|
+
{
|
49
|
+
get { return (nodeValue is String) ? (String)nodeValue : default(String); }
|
50
|
+
set { nodeValue = value; }
|
51
|
+
}
|
52
|
+
|
53
|
+
[Parameter(ValueFromPipeline = true, Position = 1, ParameterSetName = "Int32ParameterSetName")]
|
54
|
+
public Int32 Int32Value
|
55
|
+
{
|
56
|
+
get { return (nodeValue is Int32) ? (Int32)nodeValue : default(Int32); }
|
57
|
+
set { nodeValue = value; }
|
58
|
+
}
|
59
|
+
|
60
|
+
[Parameter(ValueFromPipeline = true, Position = 1, ParameterSetName = "HashValueSetName")]
|
61
|
+
public IDictionary HashValue
|
62
|
+
{
|
63
|
+
get { return (nodeValue is IDictionary) ? (IDictionary)nodeValue : default(IDictionary); }
|
64
|
+
set { nodeValue = value; }
|
65
|
+
}
|
66
|
+
|
67
|
+
[Parameter(ValueFromPipeline = true, Position = 1, ParameterSetName = "BooleanParameterSetName")]
|
68
|
+
public Boolean BooleanValue
|
69
|
+
{
|
70
|
+
get { return (nodeValue is Boolean) ? (Boolean)nodeValue : default(Boolean); }
|
71
|
+
set { nodeValue = value; }
|
72
|
+
}
|
73
|
+
|
74
|
+
[Parameter(ParameterSetName = "Int64ParameterSetName")]
|
75
|
+
public Int64 Int64Value
|
76
|
+
{
|
77
|
+
get { return (nodeValue is Int64) ? (Int64)nodeValue : default(Int64); }
|
78
|
+
set { nodeValue = value; }
|
79
|
+
}
|
80
|
+
|
81
|
+
[Parameter(ParameterSetName = "DoubleParameterSetName")]
|
82
|
+
public Double DoubleValue
|
83
|
+
{
|
84
|
+
get { return (nodeValue is Double) ? (Double)nodeValue : default(Double); }
|
85
|
+
set { nodeValue = value; }
|
86
|
+
}
|
87
|
+
|
88
|
+
[Parameter(ParameterSetName = "ArrayParameterSetName")]
|
89
|
+
public Array ArrayValue
|
90
|
+
{
|
91
|
+
get { return (nodeValue is Array) ? (Array)nodeValue : default(Array); }
|
92
|
+
set { nodeValue = value; }
|
93
|
+
}
|
94
|
+
|
95
|
+
[Parameter(ParameterSetName = "NullParameterSetName")]
|
96
|
+
public SwitchParameter NullValue
|
97
|
+
{
|
98
|
+
get { return null == nodeValue; }
|
99
|
+
set { nodeValue = null; }
|
100
|
+
}
|
101
|
+
|
102
|
+
// Summary:
|
103
|
+
// Factory method for request from cmdlet parameters.
|
104
|
+
//
|
105
|
+
// Returns:
|
106
|
+
// request object
|
107
|
+
protected abstract SetNodeValueRequestBase CreateRequest();
|
108
|
+
|
109
|
+
// Summary:
|
110
|
+
// Factory method for exception from message.
|
111
|
+
//
|
112
|
+
// Returns:
|
113
|
+
// exception
|
114
|
+
protected abstract ChefNodeCmdletExceptionBase CreateException(string message);
|
115
|
+
|
116
|
+
// Summary:
|
117
|
+
// Factory method for exception from response hash.
|
118
|
+
//
|
119
|
+
// Returns:
|
120
|
+
// exception
|
121
|
+
protected abstract ChefNodeCmdletExceptionBase CreateException(IDictionary responseHash);
|
122
|
+
|
123
|
+
protected override void ProcessRecord()
|
124
|
+
{
|
125
|
+
// iterate attempting to connect, send and receive to Chef node server.
|
126
|
+
for (int tryIndex = 0; tryIndex < Constants.MAX_CLIENT_RETRIES; ++tryIndex)
|
127
|
+
{
|
128
|
+
ITransport transport = new JsonTransport();
|
129
|
+
PipeClient pipeClient = new PipeClient(Constants.CHEF_NODE_PIPE_NAME, transport);
|
130
|
+
|
131
|
+
try
|
132
|
+
{
|
133
|
+
pipeClient.Connect(Constants.CHEF_NODE_CONNECT_TIMEOUT_MSECS);
|
134
|
+
|
135
|
+
SetNodeValueRequestBase request = CreateRequest();
|
136
|
+
|
137
|
+
IDictionary responseHash = (IDictionary)transport.NormalizeDeserializedObject(pipeClient.SendReceive<object>(request));
|
138
|
+
|
139
|
+
if (null == responseHash)
|
140
|
+
{
|
141
|
+
if (tryIndex + 1 < Constants.MAX_CLIENT_RETRIES)
|
142
|
+
{
|
143
|
+
// delay retry a few ticks to yield time in case server is busy.
|
144
|
+
Thread.Sleep(Constants.SLEEP_BETWEEN_CLIENT_RETRIES_MSECS);
|
145
|
+
continue;
|
146
|
+
}
|
147
|
+
else
|
148
|
+
{
|
149
|
+
string message = String.Format("Failed to get expected response after {0} retries.", Constants.MAX_CLIENT_RETRIES);
|
150
|
+
|
151
|
+
throw CreateException(message);
|
152
|
+
}
|
153
|
+
}
|
154
|
+
if (ChefNodeCmdletExceptionBase.HasError(responseHash))
|
155
|
+
{
|
156
|
+
throw CreateException(responseHash);
|
157
|
+
}
|
158
|
+
|
159
|
+
// done.
|
160
|
+
break;
|
161
|
+
}
|
162
|
+
catch (TimeoutException e)
|
163
|
+
{
|
164
|
+
ThrowTerminatingError(new ErrorRecord(e, "Connection timed out", ErrorCategory.OperationTimeout, pipeClient));
|
165
|
+
}
|
166
|
+
catch (ChefNodeCmdletExceptionBase e)
|
167
|
+
{
|
168
|
+
ThrowTerminatingError(new ErrorRecord(e, "ChefNodeCmdlet exception", ErrorCategory.InvalidResult, pipeClient));
|
169
|
+
}
|
170
|
+
catch (Exception e)
|
171
|
+
{
|
172
|
+
ThrowTerminatingError(new ErrorRecord(e, "Unexpected exception", ErrorCategory.NotSpecified, pipeClient));
|
173
|
+
}
|
174
|
+
finally
|
175
|
+
{
|
176
|
+
pipeClient.Close();
|
177
|
+
pipeClient = null;
|
178
|
+
}
|
179
|
+
}
|
180
|
+
}
|
181
|
+
|
182
|
+
// Summary:
|
183
|
+
// normalizes the node value from powershell for serialization.
|
184
|
+
//
|
185
|
+
// Returns:
|
186
|
+
// normalized value
|
187
|
+
protected object GetNormalizedValue()
|
188
|
+
{
|
189
|
+
return NormalizeValue(nodeValue);
|
190
|
+
}
|
191
|
+
|
192
|
+
// Summary:
|
193
|
+
// converts a node value from powershell-specific types to a marshalable type.
|
194
|
+
//
|
195
|
+
// Parameters:
|
196
|
+
// value:
|
197
|
+
// raw powershell value which may or may not be a marshalable type.
|
198
|
+
//
|
199
|
+
// Returns:
|
200
|
+
// value as a marshalable type
|
201
|
+
private static object NormalizeValue(object rawValue)
|
202
|
+
{
|
203
|
+
if (null == rawValue)
|
204
|
+
{
|
205
|
+
return null;
|
206
|
+
}
|
207
|
+
if (rawValue is PSObject)
|
208
|
+
{
|
209
|
+
PSObject pso = (PSObject)rawValue;
|
210
|
+
|
211
|
+
return NormalizeValue(pso.BaseObject);
|
212
|
+
}
|
213
|
+
if (rawValue is Array)
|
214
|
+
{
|
215
|
+
// FIX: detect circular references.
|
216
|
+
return NormalizeArrayValue((Array)rawValue);
|
217
|
+
}
|
218
|
+
if (rawValue is IDictionary)
|
219
|
+
{
|
220
|
+
// FIX: detect circular references.
|
221
|
+
return NormalizeHashValue((IDictionary)rawValue);
|
222
|
+
}
|
223
|
+
if (Array.IndexOf(SUPPORTED_PRIMITIVES, rawValue.GetType()) > 0)
|
224
|
+
{
|
225
|
+
return rawValue;
|
226
|
+
}
|
227
|
+
|
228
|
+
// note that some types are infinitely serializable, which leads to stack overflow.
|
229
|
+
// the transport layer may or may not fail for circular references (depending on
|
230
|
+
// implementation) but there are many types of infinitely serializable objects.
|
231
|
+
// an example is FileInfo, which contains a DirectoryInfo for it's parent directory
|
232
|
+
// which, when serialized, produces the same listing containing the FileInfo which
|
233
|
+
// contains the same DirectoryInfo, ad infinitum.
|
234
|
+
//
|
235
|
+
// FIX: attempt to convert the object to a hash of primitive types and otherwise
|
236
|
+
// call .ToString() on any non-primitive members. the type of the original object
|
237
|
+
// is lost but duck typing is assumed (per JSON standard).
|
238
|
+
return rawValue.ToString();
|
239
|
+
}
|
240
|
+
|
241
|
+
// Summary:
|
242
|
+
// converts an array containing one or more powershell-specific objects to marshalable array.
|
243
|
+
//
|
244
|
+
// Parameters:
|
245
|
+
// arrayValue:
|
246
|
+
// array to convert.
|
247
|
+
//
|
248
|
+
// Returns:
|
249
|
+
// array containing marshalable values.
|
250
|
+
private static object NormalizeArrayValue(Array arrayValue)
|
251
|
+
{
|
252
|
+
ArrayList copyArray = new ArrayList(arrayValue.Length);
|
253
|
+
|
254
|
+
foreach (object value in arrayValue)
|
255
|
+
{
|
256
|
+
copyArray.Add(NormalizeValue(value));
|
257
|
+
}
|
258
|
+
|
259
|
+
return copyArray;
|
260
|
+
}
|
261
|
+
|
262
|
+
// Summary:
|
263
|
+
// converts a hash containing one or more powershell-specific objects to marshalable array.
|
264
|
+
//
|
265
|
+
// Parameters:
|
266
|
+
// hashValue:
|
267
|
+
// hash to convert.
|
268
|
+
//
|
269
|
+
// Returns:
|
270
|
+
// hash containing marshalable values.
|
271
|
+
private static object NormalizeHashValue(IDictionary hashValue)
|
272
|
+
{
|
273
|
+
IDictionary copyHash = new Hashtable();
|
274
|
+
|
275
|
+
foreach (object key in hashValue.Keys)
|
276
|
+
{
|
277
|
+
object copyKey = NormalizeValue(key);
|
278
|
+
object copyValue = NormalizeValue(hashValue[key]);
|
279
|
+
|
280
|
+
copyHash.Add(copyKey, copyValue);
|
281
|
+
}
|
282
|
+
|
283
|
+
return copyHash;
|
284
|
+
}
|
285
|
+
|
286
|
+
static private Type[] SUPPORTED_PRIMITIVES = new Type[] { typeof(String), typeof(Int32), typeof(Int64), typeof(Double), typeof(Boolean) };
|
287
|
+
|
288
|
+
private string[] path;
|
289
|
+
private object nodeValue;
|
290
|
+
}
|
291
|
+
}
|
292
|
+
}
|
293
|
+
}
|
@@ -0,0 +1,75 @@
|
|
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 an abstract base class for a set node request
|
33
|
+
public abstract class SetNodeValueRequestBase
|
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 object NodeValue
|
47
|
+
{
|
48
|
+
get { return nodeValue; }
|
49
|
+
set { nodeValue = value; }
|
50
|
+
}
|
51
|
+
|
52
|
+
public SetNodeValueRequestBase()
|
53
|
+
{
|
54
|
+
}
|
55
|
+
|
56
|
+
public SetNodeValueRequestBase(ICollection path, object nodeValue)
|
57
|
+
{
|
58
|
+
this.path = Utilities.CollectionToStringArray(path);
|
59
|
+
this.nodeValue = nodeValue;
|
60
|
+
}
|
61
|
+
|
62
|
+
public override string ToString()
|
63
|
+
{
|
64
|
+
return String.Format("{0}: {{ Path = node[{1}], NodeValue = {2} }}",
|
65
|
+
Command,
|
66
|
+
String.Join("][", path),
|
67
|
+
Utilities.GetPrettyNodeValue(NodeValue));
|
68
|
+
}
|
69
|
+
|
70
|
+
private string[] path;
|
71
|
+
private object nodeValue;
|
72
|
+
}
|
73
|
+
}
|
74
|
+
}
|
75
|
+
}
|
@@ -0,0 +1,45 @@
|
|
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
|
+
// data for a set-ChefNode response
|
32
|
+
public abstract class SetNodeValueResponseBase
|
33
|
+
{
|
34
|
+
public SetNodeValueResponseBase()
|
35
|
+
{
|
36
|
+
}
|
37
|
+
|
38
|
+
public override string ToString()
|
39
|
+
{
|
40
|
+
return String.Format("{0}:", GetType().Name);
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
@@ -0,0 +1,91 @@
|
|
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
|
+
namespace RightScale
|
24
|
+
{
|
25
|
+
namespace Common
|
26
|
+
{
|
27
|
+
namespace Protocol
|
28
|
+
{
|
29
|
+
public interface ITransport
|
30
|
+
{
|
31
|
+
// Summary:
|
32
|
+
// converts some data to text which can be sent via protocol.
|
33
|
+
//
|
34
|
+
// Parameters:
|
35
|
+
// data:
|
36
|
+
// object to convert to text
|
37
|
+
//
|
38
|
+
// Returns:
|
39
|
+
// converted data
|
40
|
+
string ConvertObjectToString(object data);
|
41
|
+
|
42
|
+
// Summary:
|
43
|
+
// converts some data to text which can be sent via protocol with optional pretty printing.
|
44
|
+
//
|
45
|
+
// Parameters:
|
46
|
+
// data:
|
47
|
+
// object to convert to text
|
48
|
+
//
|
49
|
+
// pretty:
|
50
|
+
// true to insert pretty indentation for human readability.
|
51
|
+
//
|
52
|
+
// Returns:
|
53
|
+
// converted data
|
54
|
+
string ConvertObjectToString(object data, bool pretty);
|
55
|
+
|
56
|
+
// Summary:
|
57
|
+
// converts some data to an object of an expected type.
|
58
|
+
//
|
59
|
+
// Parameters:
|
60
|
+
// T:
|
61
|
+
// expected type of object
|
62
|
+
//
|
63
|
+
// data:
|
64
|
+
// text to convert to object
|
65
|
+
//
|
66
|
+
// Returns:
|
67
|
+
// converted data
|
68
|
+
T ConvertStringToObject<T>(string data);
|
69
|
+
|
70
|
+
// Summary:
|
71
|
+
// normalizes the given object to strip away any implementation-dependent
|
72
|
+
// type information resulting from deserializing objects of unknown type.
|
73
|
+
// serialization libraries tend to default to their own internal types
|
74
|
+
// for collections and hashes (and sometimes for primitives) instead of
|
75
|
+
// relying on generics (usually because they are more efficient to
|
76
|
+
// deserialize and/or implement the ToString() method in a developer-
|
77
|
+
// friendly way). the problem with these internal types is that other
|
78
|
+
// libraries may encounter errors using them. on the other hand, support
|
79
|
+
// for generic collections of object is nearly universal.
|
80
|
+
//
|
81
|
+
// Parameters:
|
82
|
+
// data:
|
83
|
+
// data to convert, if necessary.
|
84
|
+
//
|
85
|
+
// Returns:
|
86
|
+
// normalized object
|
87
|
+
object NormalizeDeserializedObject(object data);
|
88
|
+
}
|
89
|
+
}
|
90
|
+
}
|
91
|
+
}
|