Module: VagrantPlugins::Packet::Action

Includes:
Vagrant::Action::Builtin
Defined in:
lib/vagrant-packet/action.rb,
lib/vagrant-packet/action/is_created.rb,
lib/vagrant-packet/action/is_stopped.rb,
lib/vagrant-packet/action/read_state.rb,
lib/vagrant-packet/action/run_instance.rb,
lib/vagrant-packet/action/read_ssh_info.rb,
lib/vagrant-packet/action/stop_instance.rb,
lib/vagrant-packet/action/warn_networks.rb,
lib/vagrant-packet/action/connect_packet.rb,
lib/vagrant-packet/action/start_instance.rb,
lib/vagrant-packet/action/wait_for_state.rb,
lib/vagrant-packet/action/timed_provision.rb,
lib/vagrant-packet/action/terminate_instance.rb,
lib/vagrant-packet/action/message_not_created.rb,
lib/vagrant-packet/action/message_already_created.rb,
lib/vagrant-packet/action/message_will_not_destroy.rb

Defined Under Namespace

Classes: ConnectPacket, IsCreated, IsStopped, MessageAlreadyCreated, MessageNotCreated, MessageWillNotDestroy, ReadSSHInfo, ReadState, RunInstance, StartInstance, StopInstance, TerminateInstance, TimedProvision, WaitForState, WarnNetworks

Class Method Summary collapse

Class Method Details

.action_destroyObject

This action is called to terminate the remote machine.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/vagrant-packet/action.rb', line 29

def self.action_destroy
  Vagrant::Action::Builder.new.tap do |b|
    b.use Call, DestroyConfirm do |env, b2|
      if env[:result]
        b2.use ConfigValidate
        b2.use Call, IsCreated do |env2, b3|
          unless env2[:result]
            b3.use MessageNotCreated
            next
          end

          b3.use ConnectPacket
          b3.use ProvisionerCleanup, :before if defined?(ProvisionerCleanup)
          b3.use TerminateInstance
        end
      else
        b2.use MessageWillNotDestroy
      end
    end
  end
end

.action_haltObject

This action is called to halt the remote machine.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/vagrant-packet/action.rb', line 13

def self.action_halt
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use Call, IsCreated do |env, b2|
      unless env[:result]
        b2.use MessageNotCreated
        next
      end

      b2.use ConnectPacket
      b2.use StopInstance
    end
  end
end

.action_prepare_bootObject



117
118
119
120
121
122
123
# File 'lib/vagrant-packet/action.rb', line 117

def self.action_prepare_boot
  Vagrant::Action::Builder.new.tap do |b|
    b.use Provision
    b.use SyncedFolders
    b.use WarnNetworks
  end
end

.action_provisionObject

This action is called when ‘vagrant provision` is called.



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/vagrant-packet/action.rb', line 52

def self.action_provision
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use Call, IsCreated do |env, b2|
      unless env[:result]
        b2.use MessageNotCreated
        next
      end

      b2.use Provision
    end
  end
end

.action_read_ssh_infoObject

This action is called to read the SSH info of the machine. The resulting state is expected to be put into the ‘:machine_ssh_info` key.



69
70
71
72
73
74
75
# File 'lib/vagrant-packet/action.rb', line 69

def self.action_read_ssh_info
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use ConnectPacket
    b.use ReadSSHInfo
  end
end

.action_read_stateObject

This action is called to read the state of the machine. The resulting state is expected to be put into the ‘:machine_state_id` key.



80
81
82
83
84
85
86
# File 'lib/vagrant-packet/action.rb', line 80

def self.action_read_state
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use ConnectPacket
    b.use ReadState
  end
end

.action_reloadObject



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/vagrant-packet/action.rb', line 151

def self.action_reload
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use ConnectPacket
    b.use Call, IsCreated do |env, b2|
      unless env[:result]
        b2.use MessageNotCreated
        next
      end

      b2.use action_halt
      b2.use Call, WaitForState, :inactive, 120 do |env2, b3|
        b3.use action_up if env2[:result]
        # TODO: we couldn't reach :stopped, what now?
      end
    end
  end
end

.action_sshObject

This action is called to SSH into the machine.



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/vagrant-packet/action.rb', line 89

def self.action_ssh
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use Call, IsCreated do |env, b2|
      unless env[:result]
        b2.use MessageNotCreated
        next
      end

      b2.use SSHExec
    end
  end
end

.action_ssh_runObject



103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/vagrant-packet/action.rb', line 103

def self.action_ssh_run
  Vagrant::Action::Builder.new.tap do |b|
    b.use ConfigValidate
    b.use Call, IsCreated do |env, b2|
      unless env[:result]
        b2.use MessageNotCreated
        next
      end

      b2.use SSHRun
    end
  end
end

.action_upObject

This action is called to bring the box up from nothing.



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/vagrant-packet/action.rb', line 126

def self.action_up
  Vagrant::Action::Builder.new.tap do |b|
    b.use HandleBox
    b.use ConfigValidate
    b.use BoxCheckOutdated
    b.use ConnectPacket
    b.use Call, IsCreated do |env1, b1|
      if env1[:result]
        b1.use Call, IsStopped do |env2, b2|
          if env2[:result]
            b2.use action_prepare_boot
            b2.use StartInstance # restart this instance
          else
            b2.use MessageAlreadyCreated
            # TODO: write a better message
          end
        end
      else
        b1.use action_prepare_boot
        b1.use RunInstance # launch a new instance
      end
    end
  end
end