dopi 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.rspec +2 -0
  4. data/.ruby-version +1 -0
  5. data/CHANGELOG.md +322 -0
  6. data/Gemfile +7 -0
  7. data/Gemfile.lock +102 -0
  8. data/LICENSE.txt +177 -0
  9. data/README.md +309 -0
  10. data/Rakefile +44 -0
  11. data/Vagrantfile +64 -0
  12. data/bin/dopi +4 -0
  13. data/doc/getting_started.md +247 -0
  14. data/doc/getting_started_examples/001_hello_world.yaml +17 -0
  15. data/doc/getting_started_examples/002_connecting_over_ssh.yaml +35 -0
  16. data/doc/plugins/custom.md +88 -0
  17. data/doc/plugins/mco/rpc.md +82 -0
  18. data/doc/plugins/ssh/custom.md +141 -0
  19. data/doc/plugins/ssh/file_contains.md +37 -0
  20. data/doc/plugins/ssh/file_deploy.md +52 -0
  21. data/doc/plugins/ssh/file_exists.md +31 -0
  22. data/doc/plugins/ssh/file_replace.md +37 -0
  23. data/doc/plugins/ssh/puppet_agent_run.md +50 -0
  24. data/doc/plugins/ssh/reboot.md +22 -0
  25. data/doc/plugins/ssh/wait_for_login.md +53 -0
  26. data/doc/plugins/winrm/cmd.md +161 -0
  27. data/doc/plugins/winrm/file_contains.md +39 -0
  28. data/doc/plugins/winrm/file_exists.md +31 -0
  29. data/doc/plugins/winrm/powershell.md +27 -0
  30. data/doc/plugins/winrm/puppet_agent_run.md +49 -0
  31. data/doc/plugins/winrm/reboot.md +17 -0
  32. data/doc/plugins/winrm/wait_for_login.md +55 -0
  33. data/dopi.gemspec +42 -0
  34. data/lib/dopi/cli/command_add.rb +35 -0
  35. data/lib/dopi/cli/command_list.rb +19 -0
  36. data/lib/dopi/cli/command_remove.rb +31 -0
  37. data/lib/dopi/cli/command_reset.rb +27 -0
  38. data/lib/dopi/cli/command_run.rb +68 -0
  39. data/lib/dopi/cli/command_show.rb +109 -0
  40. data/lib/dopi/cli/command_update.rb +37 -0
  41. data/lib/dopi/cli/command_validate.rb +27 -0
  42. data/lib/dopi/cli/global_options.rb +55 -0
  43. data/lib/dopi/cli/log.rb +33 -0
  44. data/lib/dopi/cli.rb +57 -0
  45. data/lib/dopi/command/custom.rb +52 -0
  46. data/lib/dopi/command/dummy.rb +27 -0
  47. data/lib/dopi/command/mco/rpc.rb +158 -0
  48. data/lib/dopi/command/ssh/custom.rb +48 -0
  49. data/lib/dopi/command/ssh/file_contains.rb +70 -0
  50. data/lib/dopi/command/ssh/file_deploy.rb +71 -0
  51. data/lib/dopi/command/ssh/file_exists.rb +54 -0
  52. data/lib/dopi/command/ssh/file_replace.rb +96 -0
  53. data/lib/dopi/command/ssh/puppet_agent_run.rb +63 -0
  54. data/lib/dopi/command/ssh/reboot.rb +50 -0
  55. data/lib/dopi/command/ssh/wait_for_login.rb +68 -0
  56. data/lib/dopi/command/winrm/cmd.rb +44 -0
  57. data/lib/dopi/command/winrm/file_contains.rb +66 -0
  58. data/lib/dopi/command/winrm/file_exists.rb +51 -0
  59. data/lib/dopi/command/winrm/powershell.rb +16 -0
  60. data/lib/dopi/command/winrm/puppet_agent_run.rb +61 -0
  61. data/lib/dopi/command/winrm/reboot.rb +33 -0
  62. data/lib/dopi/command/winrm/wait_for_login.rb +49 -0
  63. data/lib/dopi/command.rb +239 -0
  64. data/lib/dopi/command_parser/arguments.rb +38 -0
  65. data/lib/dopi/command_parser/credentials.rb +59 -0
  66. data/lib/dopi/command_parser/env.rb +37 -0
  67. data/lib/dopi/command_parser/exec.rb +27 -0
  68. data/lib/dopi/command_parser/exit_code.rb +73 -0
  69. data/lib/dopi/command_parser/output.rb +126 -0
  70. data/lib/dopi/command_set.rb +66 -0
  71. data/lib/dopi/connector/local.rb +77 -0
  72. data/lib/dopi/connector/ssh.rb +170 -0
  73. data/lib/dopi/connector/winrm.rb +167 -0
  74. data/lib/dopi/error.rb +43 -0
  75. data/lib/dopi/log.rb +18 -0
  76. data/lib/dopi/node.rb +70 -0
  77. data/lib/dopi/plan.rb +99 -0
  78. data/lib/dopi/pluginmanager.rb +62 -0
  79. data/lib/dopi/state.rb +226 -0
  80. data/lib/dopi/state_store.rb +155 -0
  81. data/lib/dopi/step.rb +227 -0
  82. data/lib/dopi/step_set.rb +70 -0
  83. data/lib/dopi/version.rb +3 -0
  84. data/lib/dopi.rb +165 -0
  85. data/spec/command_helper.rb +11 -0
  86. data/spec/fixtures/mco_client.cfg +26 -0
  87. data/spec/fixtures/plans/fail_on_timeout.yaml +20 -0
  88. data/spec/fixtures/plans/hello_world.yaml +34 -0
  89. data/spec/fixtures/plans/non_existing_node.yaml +26 -0
  90. data/spec/fixtures/plans/test_role_variable.yaml +29 -0
  91. data/spec/fixtures/puppet/Puppetfile +8 -0
  92. data/spec/fixtures/puppet/Puppetfile.lock +57 -0
  93. data/spec/fixtures/puppet/hiera.yaml +6 -0
  94. data/spec/fixtures/puppet/manifests/site.pp +52 -0
  95. data/spec/fixtures/test_configuration.yaml +54 -0
  96. data/spec/fixtures/test_credentials.yaml +11 -0
  97. data/spec/fixtures/test_deloyed_file.txt +5 -0
  98. data/spec/fixtures/test_infrastructure.yaml +12 -0
  99. data/spec/fixtures/test_nodes.yaml +45 -0
  100. data/spec/fixtures/testenv_plan.yaml +159 -0
  101. data/spec/integration/dopi/addrun_spec.rb +31 -0
  102. data/spec/integration/dopi/cli/command_run_spec.rb +38 -0
  103. data/spec/integration/dopi/cli/global_options_spec.rb +128 -0
  104. data/spec/integration/dopi/command_spec.rb +66 -0
  105. data/spec/integration/dopi/fail_check_plans/file_exists_fails.yaml +38 -0
  106. data/spec/integration/dopi/fail_check_plans/output_parser.yaml +39 -0
  107. data/spec/integration/dopi/fail_check_plans/powershell_fail.yaml +25 -0
  108. data/spec/integration/dopi/fail_check_plans/timeout.yaml +29 -0
  109. data/spec/integration/dopi/fail_check_plans/verify_commands.yaml +33 -0
  110. data/spec/integration/dopi/failplan.rb +27 -0
  111. data/spec/integration/dopi/plan.rb +27 -0
  112. data/spec/integration/dopi/plans/dummy.yaml +29 -0
  113. data/spec/integration/dopi/plans/max_per_role.yaml +55 -0
  114. data/spec/integration/dopi/plans/no_timeout.yaml +29 -0
  115. data/spec/integration/dopi/plans/node_and_role_patterns.yaml +58 -0
  116. data/spec/integration/dopi/plans/node_by_config.yaml +116 -0
  117. data/spec/integration/dopi/plans/plugin_defaults.yaml +86 -0
  118. data/spec/integration/dopi/plans/plugins/mco/rpc.yaml +33 -0
  119. data/spec/integration/dopi/plans/plugins/ssh/custom.yaml +97 -0
  120. data/spec/integration/dopi/plans/plugins/ssh/file_contains.yaml +51 -0
  121. data/spec/integration/dopi/plans/plugins/ssh/file_deploy.yaml +82 -0
  122. data/spec/integration/dopi/plans/plugins/ssh/file_exists.yaml +69 -0
  123. data/spec/integration/dopi/plans/plugins/ssh/file_replace.yaml +55 -0
  124. data/spec/integration/dopi/plans/plugins/ssh/puppet_agent_run.yaml +45 -0
  125. data/spec/integration/dopi/plans/plugins/ssh/reboot.yaml +43 -0
  126. data/spec/integration/dopi/plans/plugins/ssh/wait_for_login.yaml +45 -0
  127. data/spec/integration/dopi/plans/plugins/winrm/cmd.yaml +39 -0
  128. data/spec/integration/dopi/plans/plugins/winrm/file_contains.yaml +51 -0
  129. data/spec/integration/dopi/plans/plugins/winrm/file_exists.yaml +69 -0
  130. data/spec/integration/dopi/plans/plugins/winrm/reboot.yaml +31 -0
  131. data/spec/integration/dopi/plans/resolve_roles_on_validate.yaml +23 -0
  132. data/spec/integration/dopi/plans/ssh_parallel.yaml +37 -0
  133. data/spec/integration/dopi/plans/verify_commands.yaml +49 -0
  134. data/spec/spec_helper.rb +104 -0
  135. data/spec/unit/dopi/command/custom_spec.rb +58 -0
  136. data/spec/unit/dopi/command/mco/rpc_spec.rb +157 -0
  137. data/spec/unit/dopi/command/ssh/custom_spec.rb +30 -0
  138. data/spec/unit/dopi/command/ssh/file_deploy_spec.rb +42 -0
  139. data/spec/unit/dopi/command/ssh/file_replace_spec.rb +35 -0
  140. data/spec/unit/dopi/command_parser/credentials_spec.rb +53 -0
  141. data/spec/unit/dopi/command_parser/exit_code_spec.rb +63 -0
  142. data/spec/unit/dopi/command_parser/output_spec.rb +129 -0
  143. data/spec/unit/dopi/command_spec.rb +14 -0
  144. data/spec/unit/dopi/connector/winrm_spec.rb +111 -0
  145. data/spec/unit/dopi/node_spec.rb +24 -0
  146. data/spec/unit/dopi/plan_spec.rb +31 -0
  147. data/spec/unit/dopi/state_spec.rb +109 -0
  148. data/spec/unit/dopi/step_spec.rb +13 -0
  149. metadata +448 -0
@@ -0,0 +1,161 @@
1
+ # DOPi Command Plugin: WinRM Command executor
2
+
3
+ This DOPi Plugin will execute a command on Windows with WinRM.
4
+
5
+ ## Plugin Settings:
6
+
7
+ ### credentials (optional)
8
+
9
+ `default: []`
10
+
11
+ The winrm plugin and all the plugins that inherit from it can use
12
+ credentials from the credentials hash in the plan to login.
13
+
14
+ credentials:
15
+ 'windows_staging_login':
16
+ type: :username_password
17
+ username: 'administrator'
18
+ password: 'foo'
19
+
20
+ steps:
21
+ - name: 'set winrm login credentials'
22
+ command:
23
+ plugin: 'winrm/cmd'
24
+ credentials: 'windows_staging_login'
25
+ exec: 'somecommand'
26
+
27
+ You can also specify multiple credentials and the winrm plugin will try each one
28
+ of them in turn to login to the node.
29
+
30
+ credentials:
31
+ 'windows_staging_login':
32
+ type: :username_password
33
+ username: 'administrator'
34
+ password: 'foo'
35
+ 'windows_prod_login':
36
+ type: :kerberos
37
+ realm: 'FOOO'
38
+
39
+ steps:
40
+ - name: 'set winrm login credentials'
41
+ command:
42
+ plugin: 'winrm/cmd'
43
+ credentials:
44
+ - 'windows_staging_login'
45
+ - 'windows_prod_login'
46
+ exec: 'somecommand'
47
+
48
+ This can be set in each plugin (don't forget the validator plugins) or via
49
+ the set_plugin_defaults hash. The plugin defaults will be preserved for
50
+ subsequent steps until it is altered or deleted.
51
+
52
+ credentials:
53
+ 'windows_staging_login':
54
+ type: :username_password
55
+ username: 'administrator'
56
+ password: 'foo'
57
+ 'windows_prod_login':
58
+ type: :kerberos
59
+ realm: 'FOOO'
60
+
61
+ steps:
62
+ - name: 'set winrm login credentials'
63
+ set_plugin_defaults:
64
+ - plugins: '/^ssh/'
65
+ :credentials:
66
+ - 'windows_staging_login'
67
+ - 'windows_prod_login'
68
+ command:
69
+ plugin: 'winrm/cmd'
70
+ exec: 'somecommand'
71
+
72
+
73
+ (See dop_common plan format for more options)
74
+
75
+ ### exec (required)
76
+
77
+ The command the plugin should execute for every node.
78
+
79
+ ### arguments (optional)
80
+
81
+ `default: ""`
82
+
83
+ The arguments for the command. This can be set by a string as an array or
84
+ as a hash. All the elements of the hash and the array will be flattened
85
+ and joined with a space.
86
+
87
+ ### port (optional)
88
+
89
+ `default: 5985`
90
+
91
+ The port where the service is listening on the remote machines.
92
+
93
+ ### ssl (optional)
94
+
95
+ `default: true`
96
+
97
+ Communicate with the node over ssl
98
+
99
+ ### ca_trust_path (optional)
100
+
101
+ `default: nil`
102
+
103
+ Point to another CA trust ca trust path
104
+
105
+ ### disable_sspi (optional)
106
+
107
+ `default: false`
108
+
109
+ Disable the security support provider interface.
110
+
111
+ ### basic_auth_only (optional)
112
+
113
+ `default: false`
114
+
115
+ Use basic auth only
116
+
117
+ ### operation_timeout (optional)
118
+
119
+ `default: plugin_timeout - 5s`
120
+
121
+ Timeout for the winrm command to respond. This will default to the plugin_timeout - 5s
122
+
123
+ ### expect_exit_codes (optional)
124
+
125
+ `default: 0`
126
+
127
+ The exit codes DOPi should expect if the program terminates. It the program
128
+ exits with an exit code not listed here, DOPi will mark the run as failed.
129
+ The values can be a number, an array of numbers or :all for all possible exit
130
+ codes. Will replace the current default.
131
+
132
+ ### parse_output (optional)
133
+
134
+ `default: {}`
135
+
136
+ Here you can define patterns that match against the output of the command plugin
137
+ and flag certain lines as errors or warnings. The parse_output key should contain
138
+ a hash with two keys, 'error' and 'warning' which each can contain an array of
139
+ patterns.
140
+
141
+ ## Example:
142
+
143
+ credentials:
144
+ 'windows_kerberos':
145
+ type: 'kerberos'
146
+ realm: 'EXAMPLE.COM'
147
+ 'windows_login':
148
+ type: 'username_password'
149
+ username: 'Administrator'
150
+ password: 'vagrant'
151
+
152
+ steps:
153
+ - name: 'execute a simple cmd command'
154
+ nodes: 'all'
155
+ command:
156
+ plugin: 'winrm/cmd'
157
+ credentials:
158
+ - 'windows_kerberos'
159
+ - 'windows_login'
160
+ exec: 'ipconfig'
161
+ arguments: '/all'
@@ -0,0 +1,39 @@
1
+ # DOPi Command Plugin: File Contains WinRM Command
2
+
3
+ This DOPi Plugin will check if the specified file on the node contains a
4
+ specific pattern. This plugin is usually used as a verify command to check
5
+ if a command has to be executed on a node.
6
+
7
+ ## Plugin Settings:
8
+
9
+ The winrm/file_contains command plugin is based on the
10
+ [winrm powershell command plugin](doc/plugins/winrm/powershell.md) and the
11
+ [winrm cmd command plugin](doc/plugins/winrm/cdm.md) and inherits all their
12
+ parameters.
13
+
14
+ It will however overwrite the **exec** parameter, so it is not possible to
15
+ set a custom command in this plugin.
16
+
17
+ ### file (required)
18
+
19
+ The file to check
20
+
21
+ ### pattern (required)
22
+
23
+ The regular expression to check against
24
+
25
+ ## Example:
26
+
27
+ - name "Run puppet on a node"
28
+ nodes:
29
+ - 'web01.example.com'
30
+ command:
31
+ plugin: 'winrm/cmd'
32
+ verify_commands:
33
+ - plugin: 'winrm/file_contains'
34
+ file: 'C:\puppet\puppet.conf'
35
+ pattern: 'puppetmaster.example.com'
36
+ exec: 'puppet'
37
+ arguments:
38
+ 'agent': '--test'
39
+ '--server': 'puppetmaster.example.com'
@@ -0,0 +1,31 @@
1
+ # DOPi Command Plugin: File Contains WinRM Command
2
+
3
+ This DOPi Plugin will check if the specified file on the node exists.
4
+ This plugin is usually used as a verify command to check if a command
5
+ has to be executed on a node.
6
+
7
+ ## Plugin Settings:
8
+
9
+ The winrm/file_exists command plugin is based on the
10
+ [winrm powershell command plugin](doc/plugins/winrm/powershell.md) and the
11
+ [winrm cmd plugin](doc/plugins/winrm/cmd.md) and inherits all their
12
+ parameters.
13
+
14
+ It will however overwrite the **exec** parameter, so it is not possible to
15
+ set a custom command in this plugin.
16
+
17
+ ### file (required)
18
+
19
+ The file to check
20
+
21
+ ## Example:
22
+
23
+ - name: 'Say hello'
24
+ nodes: all
25
+ command:
26
+ verify_commands:
27
+ - plugin: 'winrm/file_exists'
28
+ file: 'C:\some\file.txt'
29
+ plugin: 'winrm/cmd'
30
+ exec: 'echo'
31
+ arguments: '"Hello"'
@@ -0,0 +1,27 @@
1
+ # DOPi Command Plugin: WinRM Command executor
2
+
3
+ This DOPi Plugin will execute a powershell command on Windows with WinRM.
4
+
5
+ This Plugin is identical to the 'winrm/cmd' plugin and shares the same options.
6
+ The only difference is that it will execute powershell commands.
7
+
8
+ ## Example:
9
+
10
+ credentials:
11
+ 'windows_kerberos':
12
+ type: 'kerberos'
13
+ realm: 'EXAMPLE.COM'
14
+ 'windows_login':
15
+ type: 'username_password'
16
+ username: 'Administrator'
17
+ password: 'vagrant'
18
+
19
+ steps:
20
+ - name: 'execute a simple powershell command'
21
+ nodes: 'all'
22
+ command:
23
+ plugin: 'winrm/powershell'
24
+ credentials:
25
+ - 'windows_kerberos'
26
+ - 'windows_login'
27
+ exec: 'Get-NetAdapter'
@@ -0,0 +1,49 @@
1
+ # DOPi Command Plugin: WinRM Puppet Agent run Command
2
+
3
+ This DOPi Plugin will run puppet on the nodes in the step.
4
+
5
+ ## Plugin Settings:
6
+
7
+ The winrm/puppet_agent_run command plugin is based on the
8
+ [winrm custom command plugin](doc/plugins/winrm/powershell.md) and
9
+ inherits all it's parameters.
10
+
11
+ It will however overwrite the **exec** parameter, so it is not possible to
12
+ set a custom command in this plugin.
13
+
14
+ You may want to set a high **plugin_timeout** here to make sure it waits
15
+ long enough for all the nodes to come up if you provision the nodes while
16
+ waiting.
17
+
18
+ This plugin overwrites the defaults for the **expect_exit_codes** parameter.
19
+ Puppet will return an exit code of 2 if there where changes. Since this will
20
+ be what we are looking we have to expect this and mark it as success
21
+
22
+ `default overwrite for expect_exit_codes : [ 0, 2 ]`
23
+
24
+ If you are sure that there will be changes you should overwrite this with 2
25
+ to make sure there where changes. This may help you catching problems where
26
+ nodes don't actually get a configuration or are in the wrong environment.
27
+
28
+ The winrm/puppet_agent_run plugin has no additional parameters.
29
+
30
+ ## Examples:
31
+
32
+ ### Simple Example
33
+
34
+ - name "Run puppet on a node"
35
+ nodes:
36
+ - 'web01.example.com'
37
+ command: 'winrm/puppet_agent_run'
38
+
39
+ ### Complete Example
40
+
41
+ - name "Run puppet with parameters on a node"
42
+ nodes:
43
+ - 'web01.example.com'
44
+ command:
45
+ plugin: 'winrm/puppet_agent_run'
46
+ plugin_timeout: 300
47
+ arguments:
48
+ '--server': 'puppetmaster.example.com'
49
+ '--environment': 'development'
@@ -0,0 +1,17 @@
1
+ # DOPi Command Plugin: Reboot
2
+
3
+ This plugin will send the reboot command to a node. Then it will check if the
4
+ node actually rebooted by checking until it is unavailable and then available
5
+ again. The command will finish if DOPi is again able to login after the reboot.
6
+
7
+ ## Plugin Settings:
8
+
9
+ There are currently no settings for this plugin
10
+
11
+ ## Example
12
+
13
+ - name "Wait until we can successfully login to the node"
14
+ nodes:
15
+ - 'web01.example.com'
16
+ command: 'winrm/reboot'
17
+
@@ -0,0 +1,55 @@
1
+ # DOPi Command Plugin: Wait for SSH login Command
2
+
3
+ This DOPi Plugin will try to connect to the node until a successful login
4
+ is possible or until a timeout is reached.
5
+
6
+ ## Plugin Settings:
7
+
8
+ The winrm/wait_for_login command plugin is based on the
9
+ [winrm cmd plugin](doc/plugins/winrm/cmd.md) and the
10
+ [custom command plugin](doc/plugins/custom.md) and inherits all their
11
+ parameters.
12
+
13
+ It will however overwrite the **exec** parameter, so it is not possible to
14
+ set a custom command in this plugin.
15
+
16
+ You may want to set a high **plugin_timeout** here to make sure it waits
17
+ long enough for all the nodes to come up if you provision the nodes while
18
+ waiting.
19
+
20
+ ### connect_timeout (optional)
21
+
22
+ `default: 0`
23
+
24
+ __*NOTE:*__ This is not implemented for the winrm version of this plugin right now
25
+
26
+ Amount of seconds to wait while connecting until giving up.
27
+
28
+ ### interval (optional)
29
+
30
+ `default: 10`
31
+
32
+ Amount of seconds to wait between login attempts.
33
+
34
+ ## Examples:
35
+
36
+ ### Simple Example
37
+
38
+ - name "Wait until we can successfully login to the node"
39
+ nodes:
40
+ - 'windows01.example.com'
41
+ command:
42
+ plugin: 'winrm/wait_for_login'
43
+ plugin_timeout: 300
44
+
45
+
46
+ ### Complete Example
47
+
48
+ - name "Wait until we can successfully login to the node"
49
+ nodes:
50
+ - 'windows01.example.com'
51
+ command:
52
+ plugin: 'winrm/wait_for_login'
53
+ plugin_timeout: 300
54
+ connect_timeout: 5
55
+ interval: 30
data/dopi.gemspec ADDED
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dopi/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'dopi'
8
+ spec.version = Dopi::VERSION
9
+ spec.authors = ['Andreas Zuber', 'Andreas Maierhofer']
10
+ spec.email = ['zuber@puzzle.ch', 'andreas.maierhofer@swisscom.com']
11
+ spec.description = %q{DOPi orchestrates puppet runs, mco calls and custom commands over different nodes}
12
+ spec.summary = %q{DOPi orchestrates puppet runs, mco calls and custom commands over different nodes}
13
+ spec.homepage = ''
14
+ spec.license = 'Apache-2.0'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+ spec.required_ruby_version = '>= 1.9.3'
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.3'
23
+ spec.add_development_dependency 'rake'
24
+ spec.add_development_dependency 'rspec'
25
+ spec.add_development_dependency 'rspec-mocks'
26
+ spec.add_development_dependency 'rspec-command'
27
+
28
+ # Code quality
29
+ spec.add_development_dependency 'simplecov'
30
+
31
+ spec.add_runtime_dependency 'dop_common', '~> 0.13', '>= 0.13.0'
32
+ spec.add_runtime_dependency 'gli', '~> 2'
33
+ spec.add_runtime_dependency 'logger-colors', '~> 1'
34
+ spec.add_runtime_dependency 'mcollective-client', '~> 2'
35
+ spec.add_runtime_dependency 'winrm', '~> 1'
36
+ spec.add_runtime_dependency 'parallel', '~> 1'
37
+
38
+ # curses was removed in ruby 2.1
39
+ if RUBY_VERSION >= '2.1'
40
+ spec.add_runtime_dependency 'curses', '~> 1'
41
+ end
42
+ end
@@ -0,0 +1,35 @@
1
+ module Dopi
2
+ module Cli
3
+
4
+ def self.command_add(base)
5
+ base.class_eval do
6
+
7
+ desc 'Add a new plan file to the plan cache'
8
+ arg_name 'plan_file'
9
+ command :add do |c|
10
+ c.desc 'update the plan if it already exists'
11
+ c.default_value false
12
+ c.switch [:update, :u]
13
+
14
+ c.action do |global_options,options,args|
15
+ help_now!('Specify a plan file to add') if args.empty?
16
+ help_now!('You can only add one plan') if args.length > 1
17
+ plan_file = args[0]
18
+ begin
19
+ puts Dopi.add(plan_file)
20
+ rescue DopCommon::PlanExistsError => e
21
+ if options[:update]
22
+ puts Dopi.update_plan(plan_file, {})
23
+ else
24
+ raise e
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ end
31
+ end
32
+
33
+ end
34
+ end
35
+
@@ -0,0 +1,19 @@
1
+ module Dopi
2
+ module Cli
3
+
4
+ def self.command_list(base)
5
+ base.class_eval do
6
+
7
+ desc 'Show the list of plans in the dopi plan cache'
8
+ command :list do |c|
9
+ c.action do |global_options,options,args|
10
+ puts Dopi.list
11
+ end
12
+ end
13
+
14
+ end
15
+ end
16
+
17
+ end
18
+ end
19
+
@@ -0,0 +1,31 @@
1
+ module Dopi
2
+ module Cli
3
+
4
+ def self.command_remove(base)
5
+ base.class_eval do
6
+
7
+ desc 'Remove an existing plan from the plan cache'
8
+ arg_name 'name'
9
+ command :remove do |c|
10
+ c.desc 'Keep the DOPi state file'
11
+ c.default_value false
12
+ c.switch [:keep_dopi_state]
13
+
14
+ c.desc 'Remove the DOPv state file (THIS WILL REMOVE THE DISK INFO)'
15
+ c.default_value false
16
+ c.switch [:remove_dopv_state]
17
+
18
+ c.action do |global_options,options,args|
19
+ help_now!('Specify a plan name to remove') if args.empty?
20
+ help_now!('You can only remove one plan') if args.length > 1
21
+ plan_name = args[0]
22
+ Dopi.remove(plan_name, !options[:keep_dopi_state], options[:remove_dopv_state])
23
+ end
24
+ end
25
+
26
+ end
27
+ end
28
+
29
+ end
30
+ end
31
+
@@ -0,0 +1,27 @@
1
+ module Dopi
2
+ module Cli
3
+
4
+ def self.command_reset(base)
5
+ base.class_eval do
6
+
7
+ desc 'Reset a failed plan'
8
+ arg_name 'name'
9
+ command :reset do |c|
10
+ c.desc 'Force reset the states back to ready from every state'
11
+ c.default_value false
12
+ c.switch [:force, :f]
13
+
14
+ c.action do |global_options,options,args|
15
+ help_now!('Specify a plan name to run') if args.empty?
16
+ help_now!('You can only run one plan') if args.length > 1
17
+ plan_name = args[0]
18
+ Dopi.reset(plan_name, options[:force])
19
+ end
20
+ end
21
+
22
+ end
23
+ end
24
+
25
+ end
26
+ end
27
+
@@ -0,0 +1,68 @@
1
+ module Dopi
2
+ module Cli
3
+
4
+ def self.run_options(command)
5
+ DopCommon::Cli.node_select_options(command)
6
+
7
+ command.desc 'Show only stuff the run would do but don\'t execute commands (verify commands will still be executed)'
8
+ command.default_value false
9
+ command.switch [:noop, :n]
10
+
11
+ command.desc 'Select the step set to run (if nothing is specified it will try to run the step set "default")'
12
+ command.default_value 'default'
13
+ command.arg_name 'STEPSET'
14
+ command.flag [:step_set, :s]
15
+ end
16
+
17
+ def self.command_run(base)
18
+ base.class_eval do
19
+
20
+ desc 'Run the plan'
21
+ arg_name 'id'
22
+ command :run do |c|
23
+ run_options(c)
24
+ c.action do |global_options,options,args|
25
+ help_now!('Specify a plan name to run') if args.empty?
26
+ help_now!('You can only run one plan') if args.length > 1
27
+ options[:run_for_nodes] = DopCommon::Cli.parse_node_select_options(options)
28
+ plan_name = args[0]
29
+ begin
30
+ Dopi.run(plan_name, options)
31
+ rescue Dopi::StateTransitionError => e
32
+ Dopi.log.error(e.message)
33
+ exit_now!("Some steps are in a state where they can't be started again. Try to reset the plan.")
34
+ ensure
35
+ print_state(plan_name)
36
+ exit_now!('Errors during plan run detected!') if Dopi.show(plan_name).state_failed?
37
+ end
38
+ end
39
+ end
40
+
41
+ desc 'Add a plan, run it and then remove it again (This is mainly for testing)'
42
+ arg_name 'plan_file'
43
+ command :oneshot do |c|
44
+ run_options(c)
45
+ c.action do |global_options,options,args|
46
+ help_now!('Specify a plan file to add') if args.empty?
47
+ help_now!('You can only add one plan') if args.length > 1
48
+ options[:run_for_nodes] = DopCommon::Cli.parse_node_select_options(options)
49
+ plan_file = args[0]
50
+ plan_name = Dopi.add(plan_file)
51
+ begin
52
+ Dopi.run(plan_name, options)
53
+ ensure
54
+ print_state(plan_name)
55
+ failed = Dopi.show(plan_name).state_failed?
56
+ Dopi.remove(plan_name, true)
57
+ exit_now!('Errors during plan run detected!') if failed
58
+ end
59
+ end
60
+ end
61
+
62
+ end
63
+ end
64
+
65
+ end
66
+ end
67
+
68
+