Module: Dopi

Defined in:
lib/dopi/error.rb,
lib/dopi.rb,
lib/dopi/cli.rb,
lib/dopi/log.rb,
lib/dopi/node.rb,
lib/dopi/plan.rb,
lib/dopi/step.rb,
lib/dopi/state.rb,
lib/dopi/cli/log.rb,
lib/dopi/command.rb,
lib/dopi/version.rb,
lib/dopi/step_set.rb,
lib/dopi/command_set.rb,
lib/dopi/state_store.rb,
lib/dopi/command/dummy.rb,
lib/dopi/connector/ssh.rb,
lib/dopi/pluginmanager.rb,
lib/dopi/command/custom.rb,
lib/dopi/cli/command_add.rb,
lib/dopi/cli/command_run.rb,
lib/dopi/command/mco/rpc.rb,
lib/dopi/connector/local.rb,
lib/dopi/connector/winrm.rb,
lib/dopi/cli/command_list.rb,
lib/dopi/cli/command_show.rb,
lib/dopi/cli/command_reset.rb,
lib/dopi/command/winrm/cmd.rb,
lib/dopi/cli/command_remove.rb,
lib/dopi/cli/command_update.rb,
lib/dopi/cli/global_options.rb,
lib/dopi/command/ssh/custom.rb,
lib/dopi/command/ssh/reboot.rb,
lib/dopi/command_parser/env.rb,
lib/dopi/command_parser/exec.rb,
lib/dopi/cli/command_validate.rb,
lib/dopi/command/winrm/reboot.rb,
lib/dopi/command_parser/output.rb,
lib/dopi/command/ssh/file_deploy.rb,
lib/dopi/command/ssh/file_exists.rb,
lib/dopi/command/ssh/file_replace.rb,
lib/dopi/command/winrm/powershell.rb,
lib/dopi/command_parser/arguments.rb,
lib/dopi/command_parser/exit_code.rb,
lib/dopi/command/ssh/file_contains.rb,
lib/dopi/command/winrm/file_exists.rb,
lib/dopi/command_parser/puppet_run.rb,
lib/dopi/command/ssh/wait_for_login.rb,
lib/dopi/command_parser/credentials.rb,
lib/dopi/command/winrm/file_contains.rb,
lib/dopi/command/ssh/puppet_agent_run.rb,
lib/dopi/command/winrm/wait_for_login.rb,
lib/dopi/command/winrm/puppet_agent_run.rb

Overview

SSH custom command

Defined Under Namespace

Modules: Cli, CommandParser, Connector, PluginManager, State Classes: Command, CommandConnectionError, CommandExecutionError, CommandParsingError, CommandSet, ConnectionError, GracefulExit, NoRoleFoundError, Node, NodeConnectionError, Plan, PluginLoaderError, StateStore, StateStoreObserver, StateTransitionError, Step, StepSet

Constant Summary collapse

VERSION =
'0.18.2'

Class Method Summary collapse

Class Method Details

.add(raw_plan) ⇒ Object

Raises:

  • (StandardError)


34
35
36
37
# File 'lib/dopi.rb', line 34

def self.add(raw_plan)
  raise StandardError, 'Plan not valid; did not add' unless valid?(raw_plan)
  plan_store.add(raw_plan)
end

.listObject



57
58
59
# File 'lib/dopi.rb', line 57

def self.list
  plan_store.list
end

.logObject



9
10
11
# File 'lib/dopi/log.rb', line 9

def self.log
  @log ||= DopCommon.log
end

.logger=(logger) ⇒ Object



13
14
15
16
# File 'lib/dopi/log.rb', line 13

def self.logger=(logger)
  @log = logger
  DopCommon.logger = logger
end

.on_state_change(plan_name) ⇒ Object



112
113
114
115
116
117
118
# File 'lib/dopi.rb', line 112

def self.on_state_change(plan_name)
  ensure_plan_exists(plan_name)
  state_store = Dopi::StateStore.new(plan_name, plan_store)
  state_store.on_change do
    yield
  end
end

.remove(plan_name, remove_dopi_state = true, remove_dopv_state = false) ⇒ Object



53
54
55
# File 'lib/dopi.rb', line 53

def self.remove(plan_name, remove_dopi_state = true, remove_dopv_state = false)
  plan_store.remove(plan_name, remove_dopi_state, remove_dopv_state)
end

.reset(plan_name, force = false) ⇒ Object



101
102
103
104
105
106
107
108
109
110
# File 'lib/dopi.rb', line 101

def self.reset(plan_name, force = false)
  ensure_plan_exists(plan_name)
  plan_store.run_lock(plan_name) do
    state_store = Dopi::StateStore.new(plan_name, plan_store)
    plan = get_plan(plan_name)
    plan.load_state(state_store.state_hash)
    plan.state_reset_with_children(force)
    state_store.persist_state(plan)
  end
end

.run(plan_name, options = {}) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/dopi.rb', line 71

def self.run(plan_name, options = {})
  ensure_plan_exists(plan_name)
  update_state(plan_name)
  plan_store.run_lock(plan_name) do
    state_store = Dopi::StateStore.new(plan_name, plan_store)
    dopv_state_store = plan_store.state_store(plan_name, 'dopv')
    dopv_state_store.transaction(true) do
      dopv_node_info = dopv_state_store[:nodes] || {}
      api_node_info  = options[:node_info] || {}
      options[:node_info] = dopv_node_info.merge(api_node_info)
    end
    plan = get_plan(plan_name)
    plan.load_state(state_store.state_hash)
    manager = nil
    if block_given?
      manager = Thread.new { yield(plan) }
    else
      run_signal_handler(plan)
    end
    begin
      state_store_observer = Dopi::StateStoreObserver.new(plan, state_store)
      plan.add_observer(state_store_observer)
      plan.run(options)
      manager.join if manager
    ensure
      state_store_observer.update
    end
  end
end

.show(plan_name) ⇒ Object

TODO: this returns a plan with loaded state at the moment. THIS MAY BE CHANGED IN THE FUTURE!!



63
64
65
66
67
68
69
# File 'lib/dopi.rb', line 63

def self.show(plan_name)
  ensure_plan_exists(plan_name)
  state_store = Dopi::StateStore.new(plan_name, plan_store)
  plan = get_plan(plan_name)
  plan.load_state(state_store.state_hash)
  plan
end

.update_plan(raw_plan, options = {}) ⇒ Object

Raises:

  • (StandardError)


39
40
41
42
43
44
# File 'lib/dopi.rb', line 39

def self.update_plan(raw_plan, options = {})
  raise StandardError, 'Plan not valid; did not add' unless valid?(raw_plan)
  plan_name = plan_store.update(raw_plan)
  update_state(plan_name, options)
  plan_name
end

.update_state(plan_name, options = {}) ⇒ Object



46
47
48
49
50
51
# File 'lib/dopi.rb', line 46

def self.update_state(plan_name, options = {})
  plan_store.run_lock(plan_name) do
    state_store = Dopi::StateStore.new(plan_name, plan_store)
    state_store.update(options)
  end
end

.valid?(raw_plan) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
# File 'lib/dopi.rb', line 27

def self.valid?(raw_plan)
  hash, _ = plan_store.read_plan_file(raw_plan)
  plan_parser = DopCommon::Plan.new(hash)
  plan = Dopi::Plan.new(plan_parser)
  plan.valid?
end