Module: VagrantPlugins::Lightsail::Action

Includes:
Vagrant::Action::Builtin
Defined in:
lib/vagrant-lightsail/action.rb,
lib/vagrant-lightsail/action/setup_key.rb,
lib/vagrant-lightsail/action/is_created.rb,
lib/vagrant-lightsail/action/is_stopped.rb,
lib/vagrant-lightsail/action/read_state.rb,
lib/vagrant-lightsail/action/run_instance.rb,
lib/vagrant-lightsail/action/read_ssh_info.rb,
lib/vagrant-lightsail/action/stop_instance.rb,
lib/vagrant-lightsail/action/start_instance.rb,
lib/vagrant-lightsail/action/wait_for_state.rb,
lib/vagrant-lightsail/action/configure_ports.rb,
lib/vagrant-lightsail/action/connect_lightsail.rb,
lib/vagrant-lightsail/action/terminate_instance.rb,
lib/vagrant-lightsail/action/message_not_created.rb,
lib/vagrant-lightsail/action/message_already_created.rb,
lib/vagrant-lightsail/action/message_will_not_destroy.rb

Defined Under Namespace

Classes: ConfigurePorts, ConnectLightsail, IsCreated, IsStopped, MessageAlreadyCreated, MessageNotCreated, MessageWillNotDestroy, ReadSSHInfo, ReadState, RunInstance, SetupKey, StartInstance, StopInstance, TerminateInstance, WaitForState

Class Method Summary collapse

Class Method Details

.destroyObject

This action is called to terminate the remote machine.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/vagrant-lightsail/action.rb', line 64

def self.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 ConnectLightsail
          b3.use ProvisionerCleanup, :before if defined? ProvisionerCleanup
          b3.use TerminateInstance
        end
      else
        b2.use MessageWillNotDestroy
      end
    end
  end
end

.haltObject

This action is called to halt the remote machine.



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/vagrant-lightsail/action.rb', line 118

def self.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 ConnectLightsail
      b2.use StopInstance
      b2.use WaitForState, :stopped, 120
    end
  end
end

.prepare_bootObject



56
57
58
59
60
61
# File 'lib/vagrant-lightsail/action.rb', line 56

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

.provisionObject

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



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/vagrant-lightsail/action.rb', line 87

def self.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

.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.



9
10
11
12
13
14
15
# File 'lib/vagrant-lightsail/action.rb', line 9

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

.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.



20
21
22
23
24
25
26
# File 'lib/vagrant-lightsail/action.rb', line 20

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

.reloadObject



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

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

      b2.use halt
      b2.use up
    end
  end
end

.sshObject

This action is called to SSH into the machine.



135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/vagrant-lightsail/action.rb', line 135

def self.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

.upObject

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



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

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