Module: Vagrant::LXC::Action

Defined in:
lib/vagrant-lxc/action.rb,
lib/vagrant-lxc/action/boot.rb,
lib/vagrant-lxc/action/create.rb,
lib/vagrant-lxc/action/created.rb,
lib/vagrant-lxc/action/destroy.rb,
lib/vagrant-lxc/action/network.rb,
lib/vagrant-lxc/action/disconnect.rb,
lib/vagrant-lxc/action/is_running.rb,
lib/vagrant-lxc/action/base_action.rb,
lib/vagrant-lxc/action/forced_halt.rb,
lib/vagrant-lxc/action/check_created.rb,
lib/vagrant-lxc/action/check_running.rb,
lib/vagrant-lxc/action/forward_ports.rb,
lib/vagrant-lxc/action/share_folders.rb,
lib/vagrant-lxc/action/compress_rootfs.rb,
lib/vagrant-lxc/action/handle_box_metadata.rb,
lib/vagrant-lxc/action/setup_package_files.rb,
lib/vagrant-lxc/action/clear_forwarded_ports.rb

Defined Under Namespace

Classes: BaseAction, Boot, CheckCreated, CheckRunning, ClearForwardedPorts, CompressRootFS, Create, Created, Destroy, Disconnect, ForcedHalt, ForwardPorts, HandleBoxMetadata, IsRunning, Network, SetupPackageFiles, ShareFolders

Class Method Summary collapse

Class Method Details

.action_bootObject

This action boots the VM, assuming the VM is in a state that requires a bootup (i.e. not saved).



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

def self.action_boot
  Vagrant::Action::Builder.new.tap do |b|
    # b.use ClearForwardedPorts
    b.use Vagrant::Action::Builtin::Provision
    b.use Vagrant::Action::Builtin::EnvSet, :port_collision_repair => true
    # b.use PrepareForwardedPortCollisionParams
    # b.use ClearSharedFolders
    b.use ShareFolders
    b.use Network
    b.use Vagrant::Action::Builtin::SetHostname
    # b.use Customize
    b.use ForwardPorts
    b.use Boot
  end
end

.action_destroyObject

This is the action that is primarily responsible for completely freeing the resources of the underlying virtual machine.



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/vagrant-lxc/action.rb', line 152

def self.action_destroy
  Vagrant::Action::Builder.new.tap do |b|
    # b.use CheckDependencies
    b.use Vagrant::Action::Builtin::Call, Created do |env1, b2|
      if !env1[:result]
        # TODO: Implement our own MessageNotCreated
        b2.use VagrantPlugins::ProviderVirtualBox::Action::MessageNotCreated
        next
      end

      # TODO: Implement our own DestroyConfirm
      b2.use Vagrant::Action::Builtin::Call, VagrantPlugins::ProviderVirtualBox::Action::DestroyConfirm do |env2, b3|
        if env2[:result]
          b3.use Vagrant::Action::Builtin::ConfigValidate
          b3.use Vagrant::Action::Builtin::EnvSet, :force_halt => true
          b3.use action_halt
          b3.use Destroy
        else
          # TODO: Implement our own MessageWillNotDestroy
          b3.use VagrantPlugins::ProviderVirtualBox::Action::MessageWillNotDestroy
        end
      end
    end
  end
end

.action_haltObject

This is the action that is primarily responsible for halting the virtual machine, gracefully or by force.



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

def self.action_halt
  Vagrant::Action::Builder.new.tap do |b|
    # b.use CheckDependencies
    b.use Vagrant::Action::Builtin::Call, Created do |env, b2|
      if env[:result]
        # TODO: If vagrant >=...
        b2.use Disconnect
        b2.use ClearForwardedPorts
        b2.use Vagrant::Action::Builtin::Call, Vagrant::Action::Builtin::GracefulHalt, :stopped, :running do |env2, b3|
          if !env2[:result] && env2[:machine].provider.state.running?
            b3.use ForcedHalt
          end
        end
      else
        # TODO: Implement our own MessageNotCreated
        b2.use VagrantPlugins::ProviderVirtualBox::Action::MessageNotCreated
      end
    end
  end
end

.action_packageObject

This action packages the virtual machine into a single box file.



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/vagrant-lxc/action.rb', line 179

def self.action_package
  Vagrant::Action::Builder.new.tap do |b|
    # b.use CheckDependencies
    b.use Vagrant::Action::Builtin::Call, Created do |env1, b2|
      if !env1[:result]
        # TODO: Implement our own MessageNotCreated
        b2.use VagrantPlugins::ProviderVirtualBox::Action::MessageNotCreated
        next
      end

      b2.use action_halt
      b2.use CompressRootFS
      b2.use SetupPackageFiles
      b2.use Vagrant::Action::General::Package
    end
  end
end

.action_provisionObject

This action just runs the provisioners on the machine.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/vagrant-lxc/action.rb', line 70

def self.action_provision
  Vagrant::Action::Builder.new.tap do |b|
    # b.use CheckDependencies
    b.use Vagrant::Action::Builtin::ConfigValidate
    b.use Vagrant::Action::Builtin::Call, Created do |env1, b2|
      if !env1[:result]
        # TODO: Implement our own MessageNotCreated
        b2.use VagrantPlugins::ProviderVirtualBox::Action::MessageNotCreated
        next
      end

      b2.use Vagrant::Action::Builtin::Call, IsRunning do |env2, b3|
        if !env2[:result]
          # TODO: Implement our own MessageNotRunning
          b3.use VagrantPlugins::ProviderVirtualBox::Action::MessageNotRunning
          next
        end

        b3.use Vagrant::Action::Builtin::Provision
      end
    end
  end
end

.action_reloadObject

This action is responsible for reloading the machine, which brings it down, sucks in new configuration, and brings the machine back up with the new configuration.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/vagrant-lxc/action.rb', line 28

def self.action_reload
  Vagrant::Action::Builder.new.tap do |b|
    # b.use CheckDependencies
    b.use Vagrant::Action::Builtin::Call, Created do |env1, b2|
      if !env1[:result]
        # TODO: Implement our own MessageNotCreated
        b2.use VagrantPlugins::ProviderVirtualBox::Action::MessageNotCreated
        next
      end

      b2.use Vagrant::Action::Builtin::ConfigValidate
      b2.use action_halt
      b2.use action_start
    end
  end
end

.action_sshObject

This is the action that will exec into an SSH shell.



198
199
200
201
202
203
204
205
# File 'lib/vagrant-lxc/action.rb', line 198

def self.action_ssh
  Vagrant::Action::Builder.new.tap do |b|
    # b.use CheckDependencies
    b.use CheckCreated
    b.use CheckRunning
    b.use Vagrant::Action::Builtin::SSHExec
  end
end

.action_ssh_runObject

This is the action that will run a single SSH command.



208
209
210
211
212
213
214
215
# File 'lib/vagrant-lxc/action.rb', line 208

def self.action_ssh_run
  Vagrant::Action::Builder.new.tap do |b|
    # b.use CheckDependencies
    b.use CheckCreated
    b.use CheckRunning
    b.use Vagrant::Action::Builtin::SSHRun
  end
end

.action_startObject

This action starts a container, assuming it is already created and exists. A precondition of this action is that the container exists.



96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/vagrant-lxc/action.rb', line 96

def self.action_start
  Vagrant::Action::Builder.new.tap do |b|
    # b.use CheckDependencies
    b.use Vagrant::Action::Builtin::ConfigValidate
    b.use Vagrant::Action::Builtin::Call, IsRunning do |env, b2|
      # If the VM is running, then our work here is done, exit
      next if env[:result]
      # TODO: Check if has been saved / frozen and resume
      b2.use action_boot
    end
  end
end

.action_upObject

This action brings the machine up from nothing, including creating the container, configuring metadata, and booting.



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/vagrant-lxc/action.rb', line 111

def self.action_up
  Vagrant::Action::Builder.new.tap do |b|
    # b.use CheckDependencies
    b.use Vagrant::Action::Builtin::ConfigValidate
    b.use Vagrant::Action::Builtin::Call, Created do |env, b2|
      # If the VM is NOT created yet, then do the setup steps
      if !env[:result]
        b2.use Vagrant::Action::Builtin::HandleBoxUrl
        b2.use HandleBoxMetadata
        b2.use Create
      end
    end
    b.use action_start
  end
end