vagrant-linode 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/.gitignore +19 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +23 -0
- data/README.md +201 -0
- data/Rakefile +22 -0
- data/box/README.md +13 -0
- data/box/linode.box +0 -0
- data/box/metadata.json +3 -0
- data/lib/vagrant-linode/actions/check_state.rb +19 -0
- data/lib/vagrant-linode/actions/create.rb +191 -0
- data/lib/vagrant-linode/actions/destroy.rb +30 -0
- data/lib/vagrant-linode/actions/modify_provision_path.rb +38 -0
- data/lib/vagrant-linode/actions/power_off.rb +32 -0
- data/lib/vagrant-linode/actions/power_on.rb +32 -0
- data/lib/vagrant-linode/actions/rebuild.rb +53 -0
- data/lib/vagrant-linode/actions/reload.rb +28 -0
- data/lib/vagrant-linode/actions/setup_key.rb +52 -0
- data/lib/vagrant-linode/actions/setup_sudo.rb +41 -0
- data/lib/vagrant-linode/actions/setup_user.rb +62 -0
- data/lib/vagrant-linode/actions/sync_folders.rb +80 -0
- data/lib/vagrant-linode/actions.rb +160 -0
- data/lib/vagrant-linode/commands/rebuild.rb +23 -0
- data/lib/vagrant-linode/config.rb +65 -0
- data/lib/vagrant-linode/errors.rb +49 -0
- data/lib/vagrant-linode/helpers/client.rb +114 -0
- data/lib/vagrant-linode/helpers/result.rb +38 -0
- data/lib/vagrant-linode/plugin.rb +26 -0
- data/lib/vagrant-linode/provider.rb +117 -0
- data/lib/vagrant-linode/version.rb +5 -0
- data/lib/vagrant-linode.rb +20 -0
- data/locales/en.yml +96 -0
- data/test/Vagrantfile +60 -0
- data/test/cookbooks/test/recipes/default.rb +1 -0
- data/test/scripts/provision.sh +3 -0
- data/test/test.sh +14 -0
- data/test/test_id_rsa +27 -0
- data/test/test_id_rsa.pub +1 -0
- data/vagrant-linode.gemspec +21 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZjE5MThiZTU0ODg3ZGVmZjA2OTI4MWEzZWIxYTc2YWRkNTYxZDllZA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NTRmMjI5MzdkNDg5YjBkNzI5NjhjZTA0ODdlN2RkMGNmMDBlNTQ3OA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YzBlMjc0ZGEyMDJmZTMwMDYzY2FlYTc4N2E0ZTBjMGVhOGFhNWJhMjhkZmYw
|
10
|
+
YzQ4NWYwZWNlY2FhYjBiMGU2YzUxNjQxYWI1OTM1ODk5NjEyMmVkMjgyNTQw
|
11
|
+
ZTU4OTIxODcwYzZjNzA1YjFhMTE3ODE4ODQxNjZmOGFiODBhNWE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NjQwNmRjOTc3N2ZhZGI3MTcxM2RjM2YxYjExMmRhNGU3YzM4OWRjOTA2MTFm
|
14
|
+
NjM4Mzk3N2E0YmIyMjdhOWNjZTJiNTczZDU1MDI2ZDc2OWVjZjdmZDU1MzBi
|
15
|
+
NTQ5MGQ0ZjdhYWQ4YzNmMTdkM2E2ZGE4NTA5ODMwNDc2MDgxNTA=
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright (c) 2013 John Bender
|
2
|
+
Copyright (c) 2013 Shawn Dahlen
|
3
|
+
|
4
|
+
MIT License
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
a copy of this software and associated documentation files (the
|
8
|
+
"Software"), to deal in the Software without restriction, including
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
the following conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be
|
15
|
+
included in all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Linode Vagrant Provider
|
2
|
+
==============================
|
3
|
+
`vagrant-linode` is a provider plugin for Vagrant that supports the
|
4
|
+
management of [Linode](https://www.linode.com/) linodes
|
5
|
+
(instances).
|
6
|
+
|
7
|
+
**NOTE:** The Chef provisioner is no longer supported by default (as of 0.2.0).
|
8
|
+
Please use the `vagrant-omnibus` plugin to install Chef on Vagrant-managed
|
9
|
+
machines. This plugin provides control over the specific version of Chef
|
10
|
+
to install.
|
11
|
+
|
12
|
+
Current features include:
|
13
|
+
- create and destroy linodes
|
14
|
+
- power on and off linodes
|
15
|
+
- rebuild a linode
|
16
|
+
- provision a linode with the shell or Chef provisioners
|
17
|
+
- setup a SSH public key for authentication
|
18
|
+
- create a new user account during linode creation
|
19
|
+
|
20
|
+
The provider has been tested with Vagrant 1.1.5+ using Ubuntu 14.04 LTS and
|
21
|
+
Debian 7.5 guest operating systems.
|
22
|
+
|
23
|
+
Install
|
24
|
+
-------
|
25
|
+
Installation of the provider requires two steps:
|
26
|
+
|
27
|
+
1. Install the provider plugin using the Vagrant command-line interface:
|
28
|
+
|
29
|
+
$ vagrant plugin install vagrant-linode
|
30
|
+
|
31
|
+
|
32
|
+
**NOTE:** If you are using a Mac, and this plugin would not work caused by SSL certificate problem,
|
33
|
+
You may need to specify certificate path explicitly.
|
34
|
+
You can verify actual certificate path by running:
|
35
|
+
|
36
|
+
```bash
|
37
|
+
ruby -ropenssl -e "p OpenSSL::X509::DEFAULT_CERT_FILE"
|
38
|
+
```
|
39
|
+
|
40
|
+
Then, add the following environment variable to your
|
41
|
+
`.bash_profile` script and `source` it:
|
42
|
+
|
43
|
+
```bash
|
44
|
+
export SSL_CERT_FILE=/usr/local/etc/openssl/cert.pem
|
45
|
+
```
|
46
|
+
|
47
|
+
Configure
|
48
|
+
---------
|
49
|
+
Once the provider has been installed, you will need to configure your project
|
50
|
+
to use it. The most basic `Vagrantfile` to create a linode on Linode
|
51
|
+
is shown below:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
Vagrant.configure('2') do |config|
|
55
|
+
|
56
|
+
config.vm.provider :linode do |provider, override|
|
57
|
+
override.ssh.private_key_path = '~/.ssh/id_rsa'
|
58
|
+
override.vm.box = 'linode'
|
59
|
+
override.vm.box_url = "https://github.com/displague/vagrant-linode/raw/master/box/linode.box"
|
60
|
+
|
61
|
+
provider.token = 'API_KEY'
|
62
|
+
provider.distribution = 'Ubuntu 14.04 LTS'
|
63
|
+
provider.datacenter = 'newark'
|
64
|
+
provider.plan = 'Linode 1024'
|
65
|
+
# provider.planid = <int>
|
66
|
+
# provider.paymentterm = <*1*,12,24>
|
67
|
+
# provider.datacenterid = <int>
|
68
|
+
# provider.image = <string>
|
69
|
+
# provider.imageid = <int>
|
70
|
+
# provider.private_networking = <boolean>
|
71
|
+
# provider.stackscript = <string>
|
72
|
+
# provider.stackscriptid = <int>
|
73
|
+
# provider.distributionid = <int>
|
74
|
+
end
|
75
|
+
end
|
76
|
+
```
|
77
|
+
|
78
|
+
Please note the following:
|
79
|
+
- You *must* specify the `override.ssh.private_key_path` to enable authentication
|
80
|
+
with the linode. The provider will create a new Linode SSH key using
|
81
|
+
your public key which is assumed to be the `private_key_path` with a *.pub*
|
82
|
+
extension.
|
83
|
+
- You *must* specify your Linode Personal Access Token. This may be
|
84
|
+
found on the control panel within the *Apps & API* section.
|
85
|
+
|
86
|
+
**Supported Configuration Attributes**
|
87
|
+
|
88
|
+
The following attributes are available to further configure the provider:
|
89
|
+
- `provider.image` - A string representing the image to use when creating a
|
90
|
+
new linode (e.g. `Debian 7.5`). The available options may
|
91
|
+
be found on Linode's new linode [form](https://www.linode.com/distributions).
|
92
|
+
It defaults to `Ubuntu 14.04 LTS`.
|
93
|
+
- `provider.datacenter` - A string representing the region to create the new
|
94
|
+
linode in. It defaults to `newark`.
|
95
|
+
- `provider.plan` - A string representing the size to use when creating a
|
96
|
+
new linode (e.g. `Linode 2048`). It defaults to `Linode 1024`.
|
97
|
+
- `provider.private_networking` - A boolean flag indicating whether to enable
|
98
|
+
a private network interface (if the region supports private networking). It
|
99
|
+
defaults to `false`.
|
100
|
+
- `provider.ssh_key_name` - A string representing the name to use when creating
|
101
|
+
a Linode SSH key for linode authentication. It defaults to `Vagrant`.
|
102
|
+
- `provider.setup` - A boolean flag indicating whether to setup a new user
|
103
|
+
account and modify sudo to disable tty requirement. It defaults to `true`.
|
104
|
+
If you are using a tool like [packer](https://packer.io) to create
|
105
|
+
reusable snapshots with user accounts already provisioned, set to `false`.
|
106
|
+
|
107
|
+
The provider will create a new user account with the specified SSH key for
|
108
|
+
authorization if `config.ssh.username` is set and the `provider.setup`
|
109
|
+
attribute is `true`.
|
110
|
+
|
111
|
+
### provider.plan
|
112
|
+
|
113
|
+
Each Linode Tier has been assigned a Plan Identifcation Number.
|
114
|
+
Current Plan-ID table follows:
|
115
|
+
|
116
|
+
| PlanID | Plan |
|
117
|
+
|:------- |:------------------------- |
|
118
|
+
| 1 | 1GB Plan (Linode 1024) |
|
119
|
+
| 2 | 2GB Plan (Linode 2048) |
|
120
|
+
| 4 | 4GB Plan (Linode 4096) |
|
121
|
+
| 6 | 8GB Plan (Linode 8192) |
|
122
|
+
| 7 | 16GB Plan (Linode 16384) |
|
123
|
+
| 8 | 32GB Plan (Linode 32768) |
|
124
|
+
| 9 | 48GB Plan (Linode 49152) |
|
125
|
+
| 10 | 64GB Plan (Linode 65536) |
|
126
|
+
| 12 | 96GB Plan (Linode 98304) |
|
127
|
+
|
128
|
+
```
|
129
|
+
curl -X POST "https://api.linode.com/?api_action=avail.plans" \
|
130
|
+
--data-ascii api_key="$LINODE_API_KEY" \
|
131
|
+
2>/dev/null | jq '.DATA [] | .PLANID,.LABEL'
|
132
|
+
```
|
133
|
+
|
134
|
+
More detail: [Linode API - Plans](https://www.linode.com/api/utility/avail.plans)
|
135
|
+
|
136
|
+
### provider.datacenter
|
137
|
+
|
138
|
+
Each region has been specified with a Data Center ID.
|
139
|
+
Current Region-ID table is:
|
140
|
+
|
141
|
+
| DatacenterID | Datacenter | Location |
|
142
|
+
|:------- |:------ |:--------------------|
|
143
|
+
| 4 | atlanta | Atlanta, GA, USA |
|
144
|
+
| 2 | dallas | Dallas, TX, USA |
|
145
|
+
| 3 | fremont | Fremont, CA, USA |
|
146
|
+
| 7 | london | London, England, UK |
|
147
|
+
| 6 | newark | Newark, NJ, USA |
|
148
|
+
| 8 | tokyo | Tokyo, JP |
|
149
|
+
|
150
|
+
You can find latest datacenter ID number using Linode API call.
|
151
|
+
|
152
|
+
- example call.
|
153
|
+
|
154
|
+
```
|
155
|
+
curl -X POST "https://api.linode.com/?api_action=avail.datacenters" \
|
156
|
+
--data-ascii api_key="$LINODE_API_KEY" \
|
157
|
+
2>/dev/null | jq '.DATA [] | .DATACENTERID,.ABBR,.LOCATION'
|
158
|
+
```
|
159
|
+
|
160
|
+
More detail: [Linode API - Datacenters](https://www.linode.com/api/utility/avail.datacenters)
|
161
|
+
|
162
|
+
Run
|
163
|
+
---
|
164
|
+
After creating your project's `Vagrantfile` with the required configuration
|
165
|
+
attributes described above, you may create a new linode with the following
|
166
|
+
command:
|
167
|
+
|
168
|
+
$ vagrant up --provider=linode
|
169
|
+
|
170
|
+
This command will create a new linode, setup your SSH key for authentication,
|
171
|
+
create a new user account, and run the provisioners you have configured.
|
172
|
+
|
173
|
+
**Supported Commands**
|
174
|
+
|
175
|
+
The provider supports the following Vagrant sub-commands:
|
176
|
+
- `vagrant destroy` - Destroys the linode instance.
|
177
|
+
- `vagrant ssh` - Logs into the linode instance using the configured user
|
178
|
+
account.
|
179
|
+
- `vagrant halt` - Powers off the linode instance.
|
180
|
+
- `vagrant provision` - Runs the configured provisioners and rsyncs any
|
181
|
+
specified `config.vm.synced_folder`.
|
182
|
+
- `vagrant reload` - Reboots the linode instance.
|
183
|
+
- `vagrant rebuild` - Destroys the linode instance and recreates it with the
|
184
|
+
same IP address which was previously assigned.
|
185
|
+
- `vagrant status` - Outputs the status (active, off, not created) for the
|
186
|
+
linode instance.
|
187
|
+
|
188
|
+
Contribute
|
189
|
+
----------
|
190
|
+
To contribute, clone the repository, and use [Bundler](http://gembundler.com)
|
191
|
+
to install dependencies:
|
192
|
+
|
193
|
+
$ bundle
|
194
|
+
|
195
|
+
To run the provider's tests:
|
196
|
+
|
197
|
+
$ bundle exec rake test
|
198
|
+
|
199
|
+
You can now make modifications. Running `vagrant` within the Bundler
|
200
|
+
environment will ensure that plugins installed in your Vagrant
|
201
|
+
environment are not loaded.
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'bundler/gem_helper'
|
2
|
+
|
3
|
+
namespace :gem do
|
4
|
+
Bundler::GemHelper.install_tasks
|
5
|
+
end
|
6
|
+
|
7
|
+
task :test do
|
8
|
+
result = sh 'bash test/test.sh'
|
9
|
+
|
10
|
+
if result
|
11
|
+
puts 'Success!'
|
12
|
+
else
|
13
|
+
puts 'Failure!'
|
14
|
+
exit 1
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def env
|
19
|
+
%w(LINODE_CLIENT_ID LINODE_API_KEY VAGRANT_LOG).reduce('') do |acc, key|
|
20
|
+
acc += "#{key}=#{ENV[key] || 'error'} "
|
21
|
+
end
|
22
|
+
end
|
data/box/README.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Vagrant Linode Cloud Example Box
|
2
|
+
|
3
|
+
Vagrant providers each require a custom provider-specific box format.
|
4
|
+
This folder shows the example contents of a box for the `linode` provider.
|
5
|
+
To turn this into a box:
|
6
|
+
|
7
|
+
```
|
8
|
+
$ tar cvzf linode.box ./metadata.json ./Vagrantfile
|
9
|
+
```
|
10
|
+
|
11
|
+
This box works by using Vagrant's built-in Vagrantfile merging to setup
|
12
|
+
defaults for Linode. These defaults can easily be overwritten by higher-level
|
13
|
+
Vagrantfiles (such as project root Vagrantfiles).
|
data/box/linode.box
ADDED
Binary file
|
data/box/metadata.json
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Linode
|
3
|
+
module Actions
|
4
|
+
class CheckState
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
@machine = env[:machine]
|
8
|
+
@logger = Log4r::Logger.new('vagrant::linode::check_state')
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
env[:machine_state] = @machine.state.id
|
13
|
+
@logger.info "Machine state is '#{@machine.state.id}'"
|
14
|
+
@app.call(env)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,191 @@
|
|
1
|
+
require 'vagrant-linode/helpers/client'
|
2
|
+
require 'vagrant-linode/errors'
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module Linode
|
6
|
+
module Actions
|
7
|
+
class Create
|
8
|
+
include Helpers::Client
|
9
|
+
include Vagrant::Util::Retryable
|
10
|
+
|
11
|
+
def initialize(app, env)
|
12
|
+
@app = app
|
13
|
+
@machine = env[:machine]
|
14
|
+
@client = client
|
15
|
+
@logger = Log4r::Logger.new('vagrant::linode::create')
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(env)
|
19
|
+
ssh_key_id = env[:machine].config.ssh.private_key_path
|
20
|
+
ssh_key_id = ssh_key_id[0] if ssh_key_id.is_a?(Array)
|
21
|
+
|
22
|
+
if ssh_key_id
|
23
|
+
pubkey = File.read(File.expand_path("#{ssh_key_id}.pub"))
|
24
|
+
end
|
25
|
+
|
26
|
+
if @machine.provider_config.root_pass
|
27
|
+
root_pass = @machine.provider_config.root_pass
|
28
|
+
else
|
29
|
+
root_pass = Digest::SHA2.new.update(@machine.provider_config.api_key).to_s
|
30
|
+
end
|
31
|
+
|
32
|
+
if @machine.provider_config.distribution
|
33
|
+
distributions = @client.avail.distributions
|
34
|
+
distribution = distributions.find { |d| d.label.downcase.include? @machine.provider_config.distribution.downcase }
|
35
|
+
raise( Errors::DistroMatch, distro: @machine.provider_config.distribution.to_s ) if distribution == nil
|
36
|
+
distribution_id = distribution.distributionid || nil
|
37
|
+
else
|
38
|
+
distribution_id = @machine.provider_config.distributionid
|
39
|
+
end
|
40
|
+
|
41
|
+
if @machine.provider_config.datacenter
|
42
|
+
datacenters = @client.avail.datacenters
|
43
|
+
datacenter = datacenters.find { |d| d.abbr == @machine.provider_config.datacenter }
|
44
|
+
datacenter_id = datacenter.datacenterid || nil # @todo throw if not found
|
45
|
+
else
|
46
|
+
datacenter_id = @machine.provider_config.datacenterid
|
47
|
+
end
|
48
|
+
|
49
|
+
if @machine.provider_config.plan
|
50
|
+
plans = @client.avail.linodeplans
|
51
|
+
plan = plans.find { |p| p.label.include? @machine.provider_config.plan }
|
52
|
+
raise Errors::PlanID, plan: @machine.provider_config.plan if plan == nil
|
53
|
+
plan_id = plan.planid || nil
|
54
|
+
else
|
55
|
+
plan_id = @machine.provider_config.planid
|
56
|
+
end
|
57
|
+
|
58
|
+
### Disk Images
|
59
|
+
xvda_size, swap_size, disk_sanity = @machine.provider_config.xvda_size, @machine.provider_config.swap_size, true
|
60
|
+
|
61
|
+
# Sanity checks for disk size
|
62
|
+
if xvda_size != true
|
63
|
+
disk_sanity = false if ( xvda_size.to_i + swap_size.to_i ) > ( plan['disk'].to_i * 1024 )
|
64
|
+
end
|
65
|
+
|
66
|
+
# throw if disk sizes are too large
|
67
|
+
if xvda_size == true
|
68
|
+
xvda_size = ( ( plan['disk'].to_i * 1024 ) - swap_size.to_i )
|
69
|
+
elsif disk_sanity == false
|
70
|
+
raise Errors::DiskSize, current: (xvda_size.to_i + swap_size.to_i), max: ( plan['disk'].to_i * 1024 )
|
71
|
+
end
|
72
|
+
|
73
|
+
env[:ui].info I18n.t('vagrant_linode.info.creating')
|
74
|
+
|
75
|
+
# submit new linode request
|
76
|
+
result = @client.linode.create(
|
77
|
+
planid: plan_id,
|
78
|
+
datacenterid: datacenter_id,
|
79
|
+
paymentterm: @machine.provider_config.paymentterm || 1
|
80
|
+
)
|
81
|
+
env[:ui].info I18n.t('vagrant_linode.info.created', linodeid: result['linodeid'])
|
82
|
+
|
83
|
+
# @client.linode.job.list(:linodeid => result['linodeid'], :pendingonly => 1)
|
84
|
+
# assign the machine id for reference in other commands
|
85
|
+
@machine.id = result['linodeid'].to_s
|
86
|
+
|
87
|
+
if distribution_id
|
88
|
+
swap = @client.linode.disk.create(
|
89
|
+
linodeid: result['linodeid'],
|
90
|
+
label: 'Vagrant swap',
|
91
|
+
type: 'swap',
|
92
|
+
size: swap_size
|
93
|
+
)
|
94
|
+
|
95
|
+
disk = @client.linode.disk.createfromdistribution(
|
96
|
+
linodeid: result['linodeid'],
|
97
|
+
distributionid: distribution_id,
|
98
|
+
label: 'Vagrant Disk Distribution ' + distribution_id.to_s + ' Linode ' + result['linodeid'].to_s,
|
99
|
+
type: 'ext4',
|
100
|
+
size: xvda_size,
|
101
|
+
rootSSHKey: pubkey,
|
102
|
+
rootPass: root_pass
|
103
|
+
)
|
104
|
+
elsif image_id
|
105
|
+
disk = @client.linode.disk.createfromimage(
|
106
|
+
linodeid: result['linodeid'],
|
107
|
+
imageid: image_id,
|
108
|
+
size: xvda_size,
|
109
|
+
rootSSHKey: pubkey,
|
110
|
+
rootPass: root_pass
|
111
|
+
)
|
112
|
+
|
113
|
+
swap = @client.linode.disk.create(
|
114
|
+
linodeid: result['linodeid'],
|
115
|
+
label: 'Vagrant swap',
|
116
|
+
type: 'swap',
|
117
|
+
size: swap_size
|
118
|
+
)
|
119
|
+
end
|
120
|
+
|
121
|
+
config = @client.linode.config.create(
|
122
|
+
linodeid: result['linodeid'],
|
123
|
+
label: 'Vagrant Config',
|
124
|
+
disklist: "#{disk['diskid']},#{swap['diskid']}",
|
125
|
+
kernelid: 138 # default - newest @todo make this part of config..
|
126
|
+
)
|
127
|
+
|
128
|
+
# @todo: allow provisioning to set static configuration for networking
|
129
|
+
if @machine.provider_config.private_networking
|
130
|
+
private_network = @client.linode.ip.addprivate linodeid: result['linodeid']
|
131
|
+
end
|
132
|
+
|
133
|
+
result = @client.linode.update(
|
134
|
+
linodeid: result['linodeid'],
|
135
|
+
label: @machine.config.vm.hostname || @machine.name
|
136
|
+
)
|
137
|
+
|
138
|
+
env[:ui].info I18n.t('vagrant_linode.info.booting', linodeid: result['linodeid'])
|
139
|
+
|
140
|
+
bootjob = @client.linode.boot linodeid: result['linodeid']
|
141
|
+
# sleep 1 until ! @client.linode.job.list(:linodeid => result['linodeid'], :jobid => bootjob['jobid'], :pendingonly => 1).length
|
142
|
+
wait_for_event(env, bootjob['jobid'])
|
143
|
+
|
144
|
+
# refresh linode state with provider and output ip address
|
145
|
+
linode = Provider.linode(@machine, refresh: true)
|
146
|
+
public_network = linode.network.find { |network| network['ispublic'] == 1 }
|
147
|
+
env[:ui].info I18n.t('vagrant_linode.info.linode_ip', ip: public_network['ipaddress'])
|
148
|
+
|
149
|
+
if private_network
|
150
|
+
env[:ui].info I18n.t('vagrant_linode.info.linode_private_ip', ip: private_network['ipaddress'])
|
151
|
+
end
|
152
|
+
|
153
|
+
# wait for ssh to be ready
|
154
|
+
switch_user = @machine.provider_config.setup?
|
155
|
+
user = @machine.config.ssh.username
|
156
|
+
if switch_user
|
157
|
+
@machine.config.ssh.username = 'root'
|
158
|
+
@machine.config.ssh.password = root_pass
|
159
|
+
end
|
160
|
+
|
161
|
+
retryable(tries: 25, sleep: 10) do # @todo bump tries when this is solid
|
162
|
+
next if env[:interrupted]
|
163
|
+
fail 'not ready' unless @machine.communicate.ready?
|
164
|
+
end
|
165
|
+
|
166
|
+
@machine.config.ssh.username = user
|
167
|
+
|
168
|
+
@app.call(env)
|
169
|
+
end
|
170
|
+
|
171
|
+
# Both the recover and terminate are stolen almost verbatim from
|
172
|
+
# the Vagrant AWS provider up action
|
173
|
+
# def recover(env)
|
174
|
+
# print YAML::dump env['vagrant_error']
|
175
|
+
# return if env['vagrant.error'].is_a?(Vagrant::Errors::VagrantError)
|
176
|
+
# if @machine.state.id != -1
|
177
|
+
# terminate(env)
|
178
|
+
# end
|
179
|
+
# end
|
180
|
+
|
181
|
+
def terminate(env)
|
182
|
+
destroy_env = env.dup
|
183
|
+
destroy_env.delete(:interrupted)
|
184
|
+
destroy_env[:config_validate] = false
|
185
|
+
destroy_env[:force_confirm_destroy] = true
|
186
|
+
env[:action_runner].run(Actions.destroy, destroy_env)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'vagrant-linode/helpers/client'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Linode
|
5
|
+
module Actions
|
6
|
+
class Destroy
|
7
|
+
include Helpers::Client
|
8
|
+
|
9
|
+
def initialize(app, env)
|
10
|
+
@app = app
|
11
|
+
@machine = env[:machine]
|
12
|
+
@client = client
|
13
|
+
@logger = Log4r::Logger.new('vagrant::linode::destroy')
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
# submit destroy linode request
|
18
|
+
@client.linode.delete(linodeid: @machine.id, skipchecks: true)
|
19
|
+
|
20
|
+
env[:ui].info I18n.t('vagrant_linode.info.destroying')
|
21
|
+
|
22
|
+
# set the machine id to nil to cleanup local vagrant state
|
23
|
+
@machine.id = nil
|
24
|
+
|
25
|
+
@app.call(env)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Linode
|
3
|
+
module Actions
|
4
|
+
class ModifyProvisionPath
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
@machine = env[:machine]
|
8
|
+
@logger =
|
9
|
+
Log4r::Logger.new('vagrant::linode::modify_provision_path')
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
# check if provisioning is enabled
|
14
|
+
enabled = true
|
15
|
+
enabled = env[:provision_enabled] if env.key?(:provision_enabled)
|
16
|
+
return @app.call(env) unless enabled
|
17
|
+
|
18
|
+
username = @machine.ssh_info[:username]
|
19
|
+
|
20
|
+
# change ownership of the provisioning path recursively to the
|
21
|
+
# ssh user
|
22
|
+
#
|
23
|
+
# TODO submit patch to vagrant to set appropriate permissions
|
24
|
+
# based on ssh username
|
25
|
+
@machine.config.vm.provisioners.each do |provisioner|
|
26
|
+
cfg = provisioner.config
|
27
|
+
path = cfg.upload_path if cfg.respond_to? :upload_path
|
28
|
+
path = cfg.provisioning_path if cfg.respond_to? :provisioning_path
|
29
|
+
@machine.communicate.sudo("chown -R #{username} #{path}",
|
30
|
+
error_check: false)
|
31
|
+
end
|
32
|
+
|
33
|
+
@app.call(env)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'vagrant-linode/helpers/client'
|
2
|
+
# TODO: --force
|
3
|
+
module VagrantPlugins
|
4
|
+
module Linode
|
5
|
+
module Actions
|
6
|
+
class PowerOff
|
7
|
+
include Helpers::Client
|
8
|
+
|
9
|
+
def initialize(app, env)
|
10
|
+
@app = app
|
11
|
+
@machine = env[:machine]
|
12
|
+
@client = client
|
13
|
+
@logger = Log4r::Logger.new('vagrant::linode::power_off')
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
# submit power off linode request
|
18
|
+
result = @client.linode.shutdown(linodeid: @machine.id)
|
19
|
+
|
20
|
+
# wait for request to complete
|
21
|
+
env[:ui].info I18n.t('vagrant_linode.info.powering_off')
|
22
|
+
wait_for_event(env, result['jobid'])
|
23
|
+
|
24
|
+
# refresh linode state with provider
|
25
|
+
Provider.linode(@machine, refresh: true)
|
26
|
+
|
27
|
+
@app.call(env)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'vagrant-linode/helpers/client'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Linode
|
5
|
+
module Actions
|
6
|
+
class PowerOn
|
7
|
+
include Helpers::Client
|
8
|
+
|
9
|
+
def initialize(app, env)
|
10
|
+
@app = app
|
11
|
+
@machine = env[:machine]
|
12
|
+
@client = client
|
13
|
+
@logger = Log4r::Logger.new('vagrant::linode::power_on')
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
# submit power on linode request
|
18
|
+
result = @client.linode.boot(linodeid: @machine.id)
|
19
|
+
|
20
|
+
# wait for request to complete
|
21
|
+
env[:ui].info I18n.t('vagrant_linode.info.powering_on')
|
22
|
+
wait_for_event(env, result['jobid'])
|
23
|
+
|
24
|
+
# refresh linode state with provider
|
25
|
+
Provider.linode(@machine, refresh: true)
|
26
|
+
|
27
|
+
@app.call(env)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|