vagrant-oneandone 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +33 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +29 -0
  5. data/.travis.yml +16 -0
  6. data/Gemfile +12 -0
  7. data/LICENSE +201 -0
  8. data/README.md +275 -0
  9. data/Rakefile +33 -0
  10. data/box/README.md +13 -0
  11. data/box/Vagrantfile +7 -0
  12. data/box/dummy.box +0 -0
  13. data/box/metadata.json +3 -0
  14. data/examples/01_coreos_simple/Vagrantfile +12 -0
  15. data/examples/02_django_centos7_app/Vagrantfile +14 -0
  16. data/examples/03_ubuntu12.04_shell_provision/Vagrantfile +19 -0
  17. data/examples/04_parallel_servers/Vagrantfile +26 -0
  18. data/examples/05_debian8_docker_provision/Vagrantfile +17 -0
  19. data/lib/vagrant-oneandone.rb +26 -0
  20. data/lib/vagrant-oneandone/action.rb +163 -0
  21. data/lib/vagrant-oneandone/action/connect_1and1.rb +28 -0
  22. data/lib/vagrant-oneandone/action/create.rb +76 -0
  23. data/lib/vagrant-oneandone/action/destroy.rb +69 -0
  24. data/lib/vagrant-oneandone/action/get_state.rb +17 -0
  25. data/lib/vagrant-oneandone/action/power_off.rb +49 -0
  26. data/lib/vagrant-oneandone/action/power_on.rb +39 -0
  27. data/lib/vagrant-oneandone/action/read_ssh_info.rb +54 -0
  28. data/lib/vagrant-oneandone/action/read_state.rb +44 -0
  29. data/lib/vagrant-oneandone/action/reload.rb +48 -0
  30. data/lib/vagrant-oneandone/command/list_appliances.rb +38 -0
  31. data/lib/vagrant-oneandone/command/list_datacenters.rb +36 -0
  32. data/lib/vagrant-oneandone/command/list_firewalls.rb +32 -0
  33. data/lib/vagrant-oneandone/command/list_ips.rb +45 -0
  34. data/lib/vagrant-oneandone/command/list_load_balancers.rb +43 -0
  35. data/lib/vagrant-oneandone/command/list_monitor_policies.rb +32 -0
  36. data/lib/vagrant-oneandone/command/list_servers.rb +32 -0
  37. data/lib/vagrant-oneandone/command/list_sizes.rb +43 -0
  38. data/lib/vagrant-oneandone/command/main.rb +85 -0
  39. data/lib/vagrant-oneandone/command/utils.rb +31 -0
  40. data/lib/vagrant-oneandone/config.rb +65 -0
  41. data/lib/vagrant-oneandone/config_resolver.rb +97 -0
  42. data/lib/vagrant-oneandone/errors.rb +45 -0
  43. data/lib/vagrant-oneandone/plugin.rb +36 -0
  44. data/lib/vagrant-oneandone/provider.rb +41 -0
  45. data/lib/vagrant-oneandone/version.rb +5 -0
  46. data/locales/en.yml +124 -0
  47. data/vagrant-oneandone.gemspec +29 -0
  48. data/vagrant-spec.config.rb +9 -0
  49. metadata +189 -0
@@ -0,0 +1,33 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ # Do not buffer output
7
+ $stdout.sync = true
8
+ $stderr.sync = true
9
+
10
+ # Change to the directory of this file.
11
+ Dir.chdir(File.expand_path('../', __FILE__))
12
+
13
+ namespace :spec do
14
+ desc 'Run acceptance specs'
15
+ task :acceptance do
16
+ components = %w(
17
+ general
18
+ commands
19
+ ).map { |s| "provider/oneandone/#{s}" }
20
+
21
+ exec "bundle exec vagrant-spec test --components=#{components.join(' ')}"
22
+ end
23
+
24
+ desc 'Run unit specs using RSpec'
25
+ RSpec::Core::RakeTask.new('unit') do |t|
26
+ t.pattern = './unit/**/*_spec.rb'
27
+ end
28
+ end
29
+
30
+ desc 'Run all tests'
31
+ task spec: ['spec:unit', 'spec:acceptance']
32
+
33
+ task default: 'spec:unit'
@@ -0,0 +1,13 @@
1
+ # Vagrant OneAndOne 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 `oneandone` provider.
5
+ To turn this into a box:
6
+
7
+ ```
8
+ $ tar cvzf oneandone.box ./metadata.json ./Vagrantfile
9
+ ```
10
+
11
+ This box works by using Vagrant's built-in Vagrantfile merging to setup
12
+ defaults for Oneandone. These defaults can easily be overwritten by higher-level
13
+ Vagrantfiles (such as project root Vagrantfiles).
@@ -0,0 +1,7 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant.configure('2') do |config|
5
+ config.vm.provider :oneandone do |oneandone|
6
+ end
7
+ end
Binary file
@@ -0,0 +1,3 @@
1
+ {
2
+ "provider": "oneandone"
3
+ }
@@ -0,0 +1,12 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant.configure('2') do |config|
5
+ config.vm.box = 'dummy'
6
+ config.ssh.private_key_path = '~/.ssh/id_rsa'
7
+
8
+ config.vm.provider :oneandone do |server|
9
+ server.name = 'vagrant-coreos'
10
+ server.appliance = 'CoreOS_Stable_64std'
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant.configure('2') do |config|
5
+ config.vm.box = 'dummy'
6
+ config.ssh.private_key_path = '~/.ssh/id_rsa'
7
+
8
+ config.vm.provider :oneandone do |server|
9
+ server.name = 'django-db-server'
10
+ server.appliance = 'django'
11
+ server.datacenter = 'DE' # Germany
12
+ server.fixed_size = 'L'
13
+ end
14
+ end
@@ -0,0 +1,19 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant.configure('2') do |config|
5
+ config.vm.hostname = 'ubuntu1204-server-example'
6
+ config.vm.box = 'dummy'
7
+ config.ssh.private_key_path = '~/.ssh/id_rsa'
8
+ config.ssh.pty = true
9
+
10
+ config.vm.provider :oneandone do |oneandone|
11
+ oneandone.appliance = 'ubuntu1204-64std'
12
+ oneandone.datacenter = 'ES' # Spain
13
+ oneandone.fixed_size = 'S'
14
+ end
15
+
16
+ config.vm.provision 'shell' do |s|
17
+ s.inline = 'apt-get update && apt-get install -y'
18
+ end
19
+ end
@@ -0,0 +1,26 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant.configure('2') do |config|
5
+ config.vm.box = 'dummy'
6
+ config.ssh.private_key_path = '~/.ssh/id_rsa'
7
+
8
+ config.vm.define :centos do |centos|
9
+ centos.ssh.pty = true
10
+ centos.vm.provider :oneandone do |vm|
11
+ vm.name = 'worker1'
12
+ vm.description = 'worker node 1'
13
+ vm.appliance = 'centos7-64std'
14
+ vm.datacenter = 'US'
15
+ end
16
+ end
17
+
18
+ config.vm.define :ubuntu do |ubuntu|
19
+ ubuntu.vm.provider :oneandone do |vm|
20
+ vm.name = 'worker2'
21
+ vm.description = 'worker node 2'
22
+ vm.appliance = 'ubuntu1604-64std'
23
+ vm.datacenter = 'US'
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,17 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant.configure('2') do |config|
5
+ config.vm.box = 'dummy'
6
+ config.ssh.private_key_path = '~/.ssh/id_rsa'
7
+
8
+ config.vm.provider :oneandone do |oneandone|
9
+ oneandone.name = 'debian8-docker'
10
+ oneandone.appliance = 'debian8-64std'
11
+ oneandone.datacenter = 'GB' # United Kingdom
12
+ oneandone.fixed_size = 'XL'
13
+ end
14
+
15
+ config.vm.provision 'docker' do |d|
16
+ end
17
+ end
@@ -0,0 +1,26 @@
1
+ require 'pathname'
2
+ require 'vagrant-oneandone/plugin'
3
+ require 'vagrant-oneandone/version'
4
+
5
+ module VagrantPlugins
6
+ module OneAndOne
7
+ lib_path = Pathname.new(File.expand_path('../vagrant-oneandone', __FILE__))
8
+ autoload :Action, lib_path.join('action')
9
+ autoload :Errors, lib_path.join('errors')
10
+
11
+ def self.source_root
12
+ @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
13
+ end
14
+
15
+ def self.public_key(private_key_path)
16
+ File.read("#{private_key_path}.pub")
17
+ rescue
18
+ raise Errors::PublicKeyError, key: "#{private_key_path}.pub"
19
+ end
20
+
21
+ def self.init_i18n
22
+ I18n.load_path << File.expand_path('locales/en.yml', source_root)
23
+ I18n.reload!
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,163 @@
1
+ require 'pathname'
2
+
3
+ require 'vagrant/action/builder'
4
+
5
+ module VagrantPlugins
6
+ module OneAndOne
7
+ module Action
8
+ include Vagrant::Action::Builtin
9
+
10
+ action_root = Pathname.new(File.expand_path('../action', __FILE__))
11
+ autoload :Create, action_root.join('create')
12
+ autoload :Destroy, action_root.join('destroy')
13
+ autoload :Connect1And1, action_root.join('connect_1and1')
14
+ autoload :GetState, action_root.join('get_state')
15
+ autoload :PowerOff, action_root.join('power_off')
16
+ autoload :PowerOn, action_root.join('power_on')
17
+ autoload :ReadSSHInfo, action_root.join('read_ssh_info')
18
+ autoload :ReadState, action_root.join('read_state')
19
+ autoload :Reload, action_root.join('reload')
20
+
21
+ def self.action_destroy
22
+ Vagrant::Action::Builder.new.tap do |b|
23
+ b.use ConfigValidate
24
+ b.use Call, GetState do |env, b1|
25
+ if env[:machine_state] != :not_created
26
+ b1.use Call, DestroyConfirm do |env2, b2|
27
+ if env2[:result]
28
+ b2.use Connect1And1
29
+ b2.use Destroy
30
+ b2.use ProvisionerCleanup if defined?(ProvisionerCleanup)
31
+ end
32
+ end
33
+ else
34
+ env[:ui].info I18n.t('vagrant_1and1.not_created')
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ def self.action_halt
41
+ Vagrant::Action::Builder.new.tap do |b|
42
+ b.use ConfigValidate
43
+ b.use Connect1And1
44
+ b.use Call, GetState do |env, b1|
45
+ case env[:machine_state]
46
+ when :active
47
+ b1.use PowerOff
48
+ when :off
49
+ env[:ui].info I18n.t('vagrant_1and1.already_stopped')
50
+ when :not_created
51
+ env[:ui].info I18n.t('vagrant_1and1.not_created')
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ def self.action_read_ssh_info
58
+ Vagrant::Action::Builder.new.tap do |b|
59
+ b.use ConfigValidate
60
+ b.use Connect1And1
61
+ b.use ReadSSHInfo
62
+ end
63
+ end
64
+
65
+ # This action is called to read the state of the machine. The
66
+ # resulting state is put into the `env[:machine_state_id]`.
67
+ def self.action_read_state
68
+ Vagrant::Action::Builder.new.tap do |b|
69
+ b.use ConfigValidate
70
+ b.use Connect1And1
71
+ b.use ReadState
72
+ end
73
+ end
74
+
75
+ def self.action_reload
76
+ Vagrant::Action::Builder.new.tap do |b|
77
+ b.use ConfigValidate
78
+ b.use Connect1And1
79
+ b.use Call, GetState do |env, b1|
80
+ case env[:machine_state]
81
+ when :active
82
+ b1.use Reload
83
+ b1.use Provision
84
+ when :off
85
+ env[:ui].info I18n.t('vagrant_1and1.states.long_off')
86
+ when :not_created
87
+ env[:ui].info I18n.t('vagrant_1and1.not_created')
88
+ end
89
+ end
90
+ end
91
+ end
92
+
93
+ def self.action_provision
94
+ Vagrant::Action::Builder.new.tap do |b|
95
+ b.use ConfigValidate
96
+ b.use Call, GetState do |env, b1|
97
+ case env[:machine_state]
98
+ when :active
99
+ b1.use Provision
100
+ when :off
101
+ env[:ui].info I18n.t('vagrant_1and1.states.long_off')
102
+ when :not_created
103
+ env[:ui].info I18n.t('vagrant_1and1.not_created')
104
+ end
105
+ end
106
+ end
107
+ end
108
+
109
+ def self.action_ssh
110
+ Vagrant::Action::Builder.new.tap do |b|
111
+ b.use ConfigValidate
112
+ b.use Connect1And1
113
+ b.use Call, GetState do |env, b1|
114
+ case env[:machine_state]
115
+ when :active
116
+ b1.use SSHExec
117
+ when :off
118
+ env[:ui].info I18n.t('vagrant_1and1.states.long_off')
119
+ when :not_created
120
+ env[:ui].info I18n.t('vagrant_1and1.not_created')
121
+ end
122
+ end
123
+ end
124
+ end
125
+
126
+ def self.action_ssh_run
127
+ Vagrant::Action::Builder.new.tap do |b|
128
+ b.use ConfigValidate
129
+ b.use Connect1And1
130
+ b.use Call, GetState do |env, b1|
131
+ case env[:machine_state]
132
+ when :active
133
+ b1.use SSHRun
134
+ when :off
135
+ env[:ui].info I18n.t('vagrant_1and1.states.long_off')
136
+ when :not_created
137
+ env[:ui].info I18n.t('vagrant_1and1.not_created')
138
+ end
139
+ end
140
+ end
141
+ end
142
+
143
+ def self.action_up
144
+ Vagrant::Action::Builder.new.tap do |b|
145
+ b.use ConfigValidate
146
+ b.use Connect1And1
147
+ b.use Call, GetState do |env, b1|
148
+ case env[:machine_state]
149
+ when :not_created
150
+ b1.use Create
151
+ b1.use Provision
152
+ when :off
153
+ b1.use PowerOn
154
+ b1.use Provision
155
+ else
156
+ env[:ui].info I18n.t('vagrant_1and1.already_created')
157
+ end
158
+ end
159
+ end
160
+ end
161
+ end
162
+ end
163
+ end
@@ -0,0 +1,28 @@
1
+ require 'fog-oneandone'
2
+ require 'log4r'
3
+
4
+ module VagrantPlugins
5
+ module OneAndOne
6
+ module Action
7
+ class Connect1And1
8
+ def initialize(app, _env)
9
+ @app = app
10
+ @logger = Log4r::Logger.new('vagrant_1and1::action::connect_1and1')
11
+ end
12
+
13
+ def call(env)
14
+ config = env[:machine].provider_config
15
+ api_key = config.api_key
16
+
17
+ params = {
18
+ oneandone_api_key: api_key
19
+ }
20
+
21
+ env[:oneandone_compute] = Fog::Compute::OneAndOne.new params
22
+
23
+ @app.call(env)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,76 @@
1
+ require 'log4r'
2
+
3
+ require 'vagrant-oneandone/config_resolver'
4
+
5
+ module VagrantPlugins
6
+ module OneAndOne
7
+ module Action
8
+ class Create
9
+ def initialize(app, env)
10
+ @app = app
11
+ @machine = env[:machine]
12
+ @compute = env[:oneandone_compute]
13
+ @logger = Log4r::Logger.new('vagrant_1and1::action::create')
14
+ @resolver = ConfigResolver.new(env)
15
+ end
16
+
17
+ def call(env)
18
+ # send new server request
19
+ server = @compute.servers.create(
20
+ name: @machine.provider_config.name || @machine.config.vm.hostname,
21
+ description: @machine.provider_config.description,
22
+ fixed_instance_id: @resolver.resolve_fixed_instance_size(env),
23
+ appliance_id: @resolver.resolve_appliance(env),
24
+ datacenter_id: @resolver.resolve_datacenter(env),
25
+ rsa_key: @resolver.resolve_ssh_key(env),
26
+ ip_id: @resolver.resolve_public_ip(env),
27
+ firewall_id: @machine.provider_config.firewall_id,
28
+ load_balancer_id: @machine.provider_config.load_balancer_id,
29
+ monitoring_policy_id: @machine.provider_config.monitoring_policy_id
30
+ )
31
+
32
+ env[:ui].info I18n.t('vagrant_1and1.creating_server')
33
+
34
+ # set timeout
35
+ Fog.timeout = if @machine.provider_config.timeout.nil?
36
+ 1800
37
+ else
38
+ @machine.provider_config.timeout
39
+ end
40
+ # wait for the request to complete
41
+ server.wait_for { ready? }
42
+
43
+ @machine.id = server.id
44
+ env[:ui].info(" -- Server Name: #{server.name}")
45
+ env[:ui].info(" -- Server Size: #{@machine.provider_config.fixed_size}")
46
+ env[:ui].info(" -- Server Appliance: #{@machine.provider_config.appliance}")
47
+ env[:ui].info(" -- Data Center: #{@machine.provider_config.datacenter}")
48
+ ip = begin
49
+ server.ips[0]['ip']
50
+ rescue
51
+ ''
52
+ end
53
+ env[:ui].info(" -- Public IP: #{ip}")
54
+
55
+ env[:ui].info(I18n.t('vagrant_1and1.ready'))
56
+
57
+ @app.call(env)
58
+ end
59
+
60
+ def recover(env)
61
+ return if env['vagrant.error'].is_a?(Vagrant::Errors::VagrantError)
62
+
63
+ terminate(env) if @machine.state.id != :not_created
64
+ end
65
+
66
+ def terminate(env)
67
+ destroy_env = env.dup
68
+ destroy_env.delete(:interrupted)
69
+ destroy_env[:config_validate] = false
70
+ destroy_env[:force_confirm_destroy] = true
71
+ env[:action_runner].run(Actions.destroy, destroy_env)
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end