vagrant-oneandone 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +33 -0
- data/.rspec +2 -0
- data/.rubocop.yml +29 -0
- data/.travis.yml +16 -0
- data/Gemfile +12 -0
- data/LICENSE +201 -0
- data/README.md +275 -0
- data/Rakefile +33 -0
- data/box/README.md +13 -0
- data/box/Vagrantfile +7 -0
- data/box/dummy.box +0 -0
- data/box/metadata.json +3 -0
- data/examples/01_coreos_simple/Vagrantfile +12 -0
- data/examples/02_django_centos7_app/Vagrantfile +14 -0
- data/examples/03_ubuntu12.04_shell_provision/Vagrantfile +19 -0
- data/examples/04_parallel_servers/Vagrantfile +26 -0
- data/examples/05_debian8_docker_provision/Vagrantfile +17 -0
- data/lib/vagrant-oneandone.rb +26 -0
- data/lib/vagrant-oneandone/action.rb +163 -0
- data/lib/vagrant-oneandone/action/connect_1and1.rb +28 -0
- data/lib/vagrant-oneandone/action/create.rb +76 -0
- data/lib/vagrant-oneandone/action/destroy.rb +69 -0
- data/lib/vagrant-oneandone/action/get_state.rb +17 -0
- data/lib/vagrant-oneandone/action/power_off.rb +49 -0
- data/lib/vagrant-oneandone/action/power_on.rb +39 -0
- data/lib/vagrant-oneandone/action/read_ssh_info.rb +54 -0
- data/lib/vagrant-oneandone/action/read_state.rb +44 -0
- data/lib/vagrant-oneandone/action/reload.rb +48 -0
- data/lib/vagrant-oneandone/command/list_appliances.rb +38 -0
- data/lib/vagrant-oneandone/command/list_datacenters.rb +36 -0
- data/lib/vagrant-oneandone/command/list_firewalls.rb +32 -0
- data/lib/vagrant-oneandone/command/list_ips.rb +45 -0
- data/lib/vagrant-oneandone/command/list_load_balancers.rb +43 -0
- data/lib/vagrant-oneandone/command/list_monitor_policies.rb +32 -0
- data/lib/vagrant-oneandone/command/list_servers.rb +32 -0
- data/lib/vagrant-oneandone/command/list_sizes.rb +43 -0
- data/lib/vagrant-oneandone/command/main.rb +85 -0
- data/lib/vagrant-oneandone/command/utils.rb +31 -0
- data/lib/vagrant-oneandone/config.rb +65 -0
- data/lib/vagrant-oneandone/config_resolver.rb +97 -0
- data/lib/vagrant-oneandone/errors.rb +45 -0
- data/lib/vagrant-oneandone/plugin.rb +36 -0
- data/lib/vagrant-oneandone/provider.rb +41 -0
- data/lib/vagrant-oneandone/version.rb +5 -0
- data/locales/en.yml +124 -0
- data/vagrant-oneandone.gemspec +29 -0
- data/vagrant-spec.config.rb +9 -0
- metadata +189 -0
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module OneAndOne
|
5
|
+
module Action
|
6
|
+
class Destroy
|
7
|
+
def initialize(app, _env)
|
8
|
+
@app = app
|
9
|
+
@logger = Log4r::Logger.new('vagrant_1and1::action::destroy')
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
compute = env[:oneandone_compute]
|
14
|
+
server_id = env[:machine].id
|
15
|
+
server = begin
|
16
|
+
compute.servers.get(server_id)
|
17
|
+
rescue
|
18
|
+
nil
|
19
|
+
end
|
20
|
+
|
21
|
+
if server.nil?
|
22
|
+
@logger.warn "Unable to find server #{server_id}..."
|
23
|
+
env[:ui].warn(I18n.t('vagrant_1and1.errors.instance_not_found'))
|
24
|
+
env[:machine].id = nil
|
25
|
+
else
|
26
|
+
@logger.info "Deleting server #{server_id}..."
|
27
|
+
env[:ui].info(I18n.t('vagrant_1and1.wait_deleting_server'))
|
28
|
+
|
29
|
+
# wait until the server is ready to be deleted
|
30
|
+
result = begin
|
31
|
+
server.wait_for { ready? }
|
32
|
+
rescue
|
33
|
+
false
|
34
|
+
end
|
35
|
+
|
36
|
+
if result
|
37
|
+
result = begin
|
38
|
+
server.destroy
|
39
|
+
rescue
|
40
|
+
false
|
41
|
+
end
|
42
|
+
|
43
|
+
if result
|
44
|
+
loop do
|
45
|
+
begin
|
46
|
+
compute.get_server(server_id)
|
47
|
+
rescue
|
48
|
+
break
|
49
|
+
end
|
50
|
+
sleep 5
|
51
|
+
end
|
52
|
+
env[:machine].id = nil
|
53
|
+
env[:ui].info(I18n.t('vagrant_1and1.server_deleted'))
|
54
|
+
else
|
55
|
+
@logger.warn "Unable to delete server #{server_id}..."
|
56
|
+
env[:ui].warn(I18n.t('vagrant_1and1.errors.could_not_delete'))
|
57
|
+
end
|
58
|
+
else
|
59
|
+
@logger.warn "Unable to delete server #{server_id}..."
|
60
|
+
env[:ui].warn(I18n.t('vagrant_1and1.errors.could_not_delete'))
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
@app.call(env)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module OneAndOne
|
3
|
+
module Action
|
4
|
+
class GetState
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
@machine = env[:machine]
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
env[:machine_state] = @machine.state.id
|
12
|
+
@app.call(env)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module OneAndOne
|
5
|
+
module Action
|
6
|
+
class PowerOff
|
7
|
+
def initialize(app, env)
|
8
|
+
@app = app
|
9
|
+
@logger = Log4r::Logger.new('vagrant_1and1::action::power_off')
|
10
|
+
@machine = env[:machine]
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
compute = env[:oneandone_compute]
|
15
|
+
server = begin
|
16
|
+
compute.servers.get(@machine.id)
|
17
|
+
rescue
|
18
|
+
nil
|
19
|
+
end
|
20
|
+
|
21
|
+
if server.nil?
|
22
|
+
@logger.warn "Unable to find server #{env[:machine].id}..."
|
23
|
+
env[:ui].warn(I18n.t('vagrant_1and1.errors.instance_not_found'))
|
24
|
+
env[:machine].id = nil
|
25
|
+
else
|
26
|
+
@logger.info "Stopping server #{env[:machine].id}..."
|
27
|
+
env[:ui].info(I18n.t('vagrant_1and1.stopping_server'))
|
28
|
+
|
29
|
+
# if needed, wait until the is ready
|
30
|
+
server.wait_for { ready? }
|
31
|
+
|
32
|
+
if env[:force_halt]
|
33
|
+
compute.change_status(server_id: server.id,
|
34
|
+
action: 'POWER_OFF', method: 'HARDWARE')
|
35
|
+
else
|
36
|
+
server.off
|
37
|
+
end
|
38
|
+
|
39
|
+
server.wait_for { ready? }
|
40
|
+
|
41
|
+
env[:ui].info(I18n.t('vagrant_1and1.powered_off'))
|
42
|
+
end
|
43
|
+
|
44
|
+
@app.call(env)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module OneAndOne
|
3
|
+
module Action
|
4
|
+
class PowerOn
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
@logger = Log4r::Logger.new('vagrant_1and1::action::power_on')
|
8
|
+
@machine = env[:machine]
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
compute = env[:oneandone_compute]
|
13
|
+
server = begin
|
14
|
+
compute.servers.get(@machine.id)
|
15
|
+
rescue
|
16
|
+
nil
|
17
|
+
end
|
18
|
+
|
19
|
+
if server.nil?
|
20
|
+
@logger.warn "Unable to find server #{env[:machine].id}..."
|
21
|
+
env[:ui].warn(I18n.t('vagrant_1and1.errors.instance_not_found'))
|
22
|
+
env[:machine].id = nil
|
23
|
+
else
|
24
|
+
@logger.info "Starting server #{env[:machine].id}..."
|
25
|
+
env[:ui].info(I18n.t('vagrant_1and1.starting_server'))
|
26
|
+
|
27
|
+
server.on
|
28
|
+
|
29
|
+
server.wait_for { ready? }
|
30
|
+
|
31
|
+
env[:ui].info(I18n.t('vagrant_1and1.powered_on'))
|
32
|
+
end
|
33
|
+
|
34
|
+
@app.call(env)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module OneAndOne
|
5
|
+
module Action
|
6
|
+
class ReadSSHInfo
|
7
|
+
def initialize(app, _env)
|
8
|
+
@app = app
|
9
|
+
@logger = Log4r::Logger.new('vagrant_1and1::action::read_ssh_info')
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
env[:machine_ssh_info] = read_ssh_info(env[:oneandone_compute], env[:machine])
|
14
|
+
|
15
|
+
@app.call(env)
|
16
|
+
end
|
17
|
+
|
18
|
+
def read_ssh_info(oneandone, machine)
|
19
|
+
return nil if machine.id.nil?
|
20
|
+
|
21
|
+
# Find the server
|
22
|
+
server = begin
|
23
|
+
oneandone.servers.get(machine.id)
|
24
|
+
rescue
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
if server.nil?
|
28
|
+
# The server can't be found
|
29
|
+
@logger.info("The server #{machine.id} couldn't be found.")
|
30
|
+
machine.id = nil
|
31
|
+
return nil
|
32
|
+
end
|
33
|
+
|
34
|
+
ip = begin
|
35
|
+
server.ips[0]['ip']
|
36
|
+
rescue
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
|
40
|
+
if ip.nil?
|
41
|
+
@logger.warn('SSH is unavailable.')
|
42
|
+
return nil
|
43
|
+
end
|
44
|
+
|
45
|
+
{
|
46
|
+
host: ip,
|
47
|
+
port: 22,
|
48
|
+
username: 'root'
|
49
|
+
}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module OneAndOne
|
5
|
+
module Action
|
6
|
+
class ReadState
|
7
|
+
def initialize(app, _env)
|
8
|
+
@app = app
|
9
|
+
@logger = Log4r::Logger.new('vagrant_1and1::action::read_state')
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
env[:machine_state_id] = read_state(env[:oneandone_compute], env[:machine])
|
14
|
+
@app.call(env)
|
15
|
+
end
|
16
|
+
|
17
|
+
def read_state(oneandone, machine)
|
18
|
+
return :not_created if machine.id.nil?
|
19
|
+
|
20
|
+
state = begin
|
21
|
+
oneandone.status(machine.id).body['state'].downcase.to_sym
|
22
|
+
rescue
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
|
26
|
+
if state.nil? || state == :removing
|
27
|
+
@logger.info(I18n.t('vagrant_1and1.not_created'))
|
28
|
+
return :not_created
|
29
|
+
end
|
30
|
+
|
31
|
+
case state
|
32
|
+
when :configuring, :powered_on, :powering_on, :deploying
|
33
|
+
return :active
|
34
|
+
when :powered_off, :powering_off
|
35
|
+
return :off
|
36
|
+
end
|
37
|
+
|
38
|
+
# unknown state?
|
39
|
+
state
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
|
2
|
+
module VagrantPlugins
|
3
|
+
module OneAndOne
|
4
|
+
module Action
|
5
|
+
class Reload
|
6
|
+
def initialize(app, env)
|
7
|
+
@app = app
|
8
|
+
@logger = Log4r::Logger.new('vagrant_1and1::action::reload')
|
9
|
+
@machine = env[:machine]
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
compute = env[:oneandone_compute]
|
14
|
+
server = begin
|
15
|
+
compute.servers.get(@machine.id)
|
16
|
+
rescue
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
|
20
|
+
if server.nil?
|
21
|
+
@logger.warn "Unable to find server #{env[:machine].id}..."
|
22
|
+
env[:ui].warn(I18n.t('vagrant_1and1.errors.instance_not_found'))
|
23
|
+
env[:machine].id = nil
|
24
|
+
else
|
25
|
+
@logger.info "Restarting server #{env[:machine].id}..."
|
26
|
+
env[:ui].info(I18n.t('vagrant_1and1.reloading_server'))
|
27
|
+
|
28
|
+
# if needed, wait until the server is ready
|
29
|
+
server.wait_for { ready? }
|
30
|
+
|
31
|
+
if env[:force_halt]
|
32
|
+
compute.change_status(server_id: server.id,
|
33
|
+
action: 'REBOOT', method: 'HARDWARE')
|
34
|
+
else
|
35
|
+
server.reboot
|
36
|
+
end
|
37
|
+
|
38
|
+
server.wait_for { ready? }
|
39
|
+
|
40
|
+
env[:ui].info(I18n.t('vagrant_1and1.rebooted'))
|
41
|
+
end
|
42
|
+
|
43
|
+
@app.call(env)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'vagrant-oneandone/command/utils'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module OneAndOne
|
5
|
+
module Command
|
6
|
+
class ListAppliances < Vagrant.plugin('2', :command)
|
7
|
+
include VagrantPlugins::OneAndOne::Command::Utils
|
8
|
+
|
9
|
+
def execute
|
10
|
+
options = OptionParser.new do |o|
|
11
|
+
o.banner = I18n.t('vagrant_1and1.command.list_appliances')
|
12
|
+
o.separator ''
|
13
|
+
o.separator 'Usage: vagrant oneandone appliances [<api_key>]'
|
14
|
+
o.separator ''
|
15
|
+
end
|
16
|
+
|
17
|
+
argv = parse_options(options)
|
18
|
+
return unless argv
|
19
|
+
|
20
|
+
compute = fog_oneandone(argv[0])
|
21
|
+
|
22
|
+
rows = []
|
23
|
+
compute.list_server_appliances.body.each do |app|
|
24
|
+
rows << [
|
25
|
+
app['id'],
|
26
|
+
app['name'],
|
27
|
+
app['type'],
|
28
|
+
app['os'],
|
29
|
+
app['os_architecture']
|
30
|
+
]
|
31
|
+
end
|
32
|
+
|
33
|
+
display_table(@env, %w(ID Name Type OS Architecture), rows)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'vagrant-oneandone/command/utils'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module OneAndOne
|
5
|
+
module Command
|
6
|
+
class ListDatacenters < Vagrant.plugin('2', :command)
|
7
|
+
include VagrantPlugins::OneAndOne::Command::Utils
|
8
|
+
|
9
|
+
def execute
|
10
|
+
options = OptionParser.new do |o|
|
11
|
+
o.banner = I18n.t('vagrant_1and1.command.list_datacenters')
|
12
|
+
o.separator ''
|
13
|
+
o.separator 'Usage: vagrant oneandone datacenters [<api_key>]'
|
14
|
+
o.separator ''
|
15
|
+
end
|
16
|
+
|
17
|
+
argv = parse_options(options)
|
18
|
+
return unless argv
|
19
|
+
|
20
|
+
compute = fog_oneandone(argv[0])
|
21
|
+
|
22
|
+
rows = []
|
23
|
+
compute.list_datacenters.body.each do |dc|
|
24
|
+
rows << [
|
25
|
+
dc['id'],
|
26
|
+
dc['location'],
|
27
|
+
dc['country_code']
|
28
|
+
]
|
29
|
+
end
|
30
|
+
|
31
|
+
display_table(@env, ['ID', 'Location', 'Country Code'], rows)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'vagrant-oneandone/command/utils'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module OneAndOne
|
5
|
+
module Command
|
6
|
+
class ListFirewalls < Vagrant.plugin('2', :command)
|
7
|
+
include VagrantPlugins::OneAndOne::Command::Utils
|
8
|
+
|
9
|
+
def execute
|
10
|
+
options = OptionParser.new do |o|
|
11
|
+
o.banner = I18n.t('vagrant_1and1.command.list_firewalls')
|
12
|
+
o.separator ''
|
13
|
+
o.separator 'Usage: vagrant oneandone firewalls [<api_key>]'
|
14
|
+
o.separator ''
|
15
|
+
end
|
16
|
+
|
17
|
+
argv = parse_options(options)
|
18
|
+
return unless argv
|
19
|
+
|
20
|
+
compute = fog_oneandone(argv[0])
|
21
|
+
|
22
|
+
rows = []
|
23
|
+
compute.firewalls.all.each do |fw|
|
24
|
+
rows << [fw.id, fw.name]
|
25
|
+
end
|
26
|
+
|
27
|
+
display_table(@env, %w(ID Name), rows)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'vagrant-oneandone/command/utils'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module OneAndOne
|
5
|
+
module Command
|
6
|
+
class ListIPs < Vagrant.plugin('2', :command)
|
7
|
+
include VagrantPlugins::OneAndOne::Command::Utils
|
8
|
+
|
9
|
+
def execute
|
10
|
+
options = OptionParser.new do |o|
|
11
|
+
o.banner = I18n.t('vagrant_1and1.command.list_public_ips')
|
12
|
+
o.separator ''
|
13
|
+
o.separator 'Usage: vagrant oneandone ips [<api_key>]'
|
14
|
+
o.separator ''
|
15
|
+
end
|
16
|
+
|
17
|
+
argv = parse_options(options)
|
18
|
+
return unless argv
|
19
|
+
|
20
|
+
compute = fog_oneandone(argv[0])
|
21
|
+
|
22
|
+
rows = []
|
23
|
+
compute.list_public_ips.body.each do |ip|
|
24
|
+
dhcp = ip['is_dhcp'] ? 'yes' : 'no'
|
25
|
+
assigned = ip['assigned_to'] ? ip['assigned_to']['name'] : '-'
|
26
|
+
rows << [
|
27
|
+
ip['id'],
|
28
|
+
ip['ip'],
|
29
|
+
dhcp,
|
30
|
+
ip['state'],
|
31
|
+
ip['datacenter']['country_code'],
|
32
|
+
assigned
|
33
|
+
]
|
34
|
+
end
|
35
|
+
|
36
|
+
display_table(
|
37
|
+
@env,
|
38
|
+
['ID', 'IP Address', 'DHCP', 'State', 'Data Center', 'Owner'],
|
39
|
+
rows
|
40
|
+
)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|