vagrant-1cloud 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. metadata +3 -46
  3. data/Gemfile +0 -8
  4. data/LICENSE +0 -373
  5. data/README.md +0 -117
  6. data/Rakefile +0 -21
  7. data/build.sh +0 -32
  8. data/lib/vagrant-1cloud.rb +0 -20
  9. data/lib/vagrant-1cloud/actions.rb +0 -183
  10. data/lib/vagrant-1cloud/actions/check_state.rb +0 -19
  11. data/lib/vagrant-1cloud/actions/create.rb +0 -93
  12. data/lib/vagrant-1cloud/actions/destroy.rb +0 -31
  13. data/lib/vagrant-1cloud/actions/modify_provision_path.rb +0 -38
  14. data/lib/vagrant-1cloud/actions/power_off.rb +0 -35
  15. data/lib/vagrant-1cloud/actions/power_on.rb +0 -45
  16. data/lib/vagrant-1cloud/actions/private_network.rb +0 -108
  17. data/lib/vagrant-1cloud/actions/rebuild.rb +0 -78
  18. data/lib/vagrant-1cloud/actions/reload.rb +0 -42
  19. data/lib/vagrant-1cloud/actions/setup_key.rb +0 -60
  20. data/lib/vagrant-1cloud/actions/setup_sudo.rb +0 -43
  21. data/lib/vagrant-1cloud/actions/setup_user.rb +0 -58
  22. data/lib/vagrant-1cloud/actions/shut_down.rb +0 -35
  23. data/lib/vagrant-1cloud/commands/add_network.rb +0 -59
  24. data/lib/vagrant-1cloud/commands/create_network.rb +0 -135
  25. data/lib/vagrant-1cloud/commands/rebuild.rb +0 -29
  26. data/lib/vagrant-1cloud/config.rb +0 -62
  27. data/lib/vagrant-1cloud/errors.rb +0 -33
  28. data/lib/vagrant-1cloud/helpers/client.rb +0 -181
  29. data/lib/vagrant-1cloud/helpers/result.rb +0 -40
  30. data/lib/vagrant-1cloud/plugin.rb +0 -36
  31. data/lib/vagrant-1cloud/provider.rb +0 -106
  32. data/lib/vagrant-1cloud/version.rb +0 -5
  33. data/locales/en.yml +0 -90
  34. data/pom.xml +0 -59
  35. data/test/Vagrantfile +0 -14
  36. data/test/scripts/provision.sh +0 -3
  37. data/test/test.sh +0 -11
  38. data/test/test_id_rsa +0 -27
  39. data/test/test_id_rsa.pub +0 -1
  40. data/vagrant-1cloud.gemspec +0 -21
@@ -1,31 +0,0 @@
1
- require 'vagrant-1cloud/helpers/client'
2
-
3
- module VagrantPlugins
4
- module OneCloud
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::onecloud::destroy')
14
- end
15
-
16
- def call(env)
17
- # submit destroy droplet request
18
- @client.delete("/server/#{@machine.id}")
19
-
20
- env[:ui].info I18n.t('vagrant_1cloud.info.destroying')
21
- @client.wait_for_destroy(env, @machine.id)
22
-
23
- # set the machine id to nil to cleanup local vagrant state
24
- @machine.id = nil
25
-
26
- @app.call(env)
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,38 +0,0 @@
1
- module VagrantPlugins
2
- module OneCloud
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::onecloud::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.has_key?(:provision_enabled)
16
- return @app.call(env) if !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
@@ -1,35 +0,0 @@
1
- require 'vagrant-1cloud/helpers/client'
2
-
3
- module VagrantPlugins
4
- module OneCloud
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::onecloud::power_off')
14
- end
15
-
16
- def call(env)
17
- # submit power off droplet request
18
- result = @client.post("/server/#{@machine.id}/action", {
19
- :Type => 'PowerOff'
20
- })
21
-
22
- # wait for request to complete
23
- env[:ui].info I18n.t('vagrant_1cloud.info.powering_off')
24
- @client.wait_for_event(env, @machine.id, result['body']['ID'])
25
-
26
- # refresh droplet state with provider
27
- Provider.droplet(@machine, :refresh => true)
28
-
29
- @app.call(env)
30
- end
31
- end
32
- end
33
- end
34
- end
35
-
@@ -1,45 +0,0 @@
1
- require 'vagrant-1cloud/helpers/client'
2
-
3
- module VagrantPlugins
4
- module OneCloud
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::onecloud::power_on')
14
- end
15
-
16
- def call(env)
17
- # submit power on droplet request
18
- result = @client.post("/server/#{@machine.id}/action", {
19
- :Type => 'PowerOn'
20
- })
21
-
22
- # wait for request to complete
23
- env[:ui].info I18n.t('vagrant_1cloud.info.powering_on')
24
- @client.wait_for_event(env, @machine.id, result['body']['ID'])
25
-
26
- # refresh droplet state with provider
27
- Provider.droplet(@machine, :refresh => true)
28
-
29
- user = @machine.config.ssh.username
30
- @machine.config.ssh.username = 'root'
31
-
32
- # wait for ssh to be ready
33
- env[:ui].info I18n.t('vagrant_1cloud.info.ssh')
34
- @client.wait_for_ssh(env, 3, 30)
35
-
36
- @machine.config.ssh.username = user
37
-
38
- @app.call(env)
39
- end
40
- end
41
- end
42
- end
43
- end
44
-
45
-
@@ -1,108 +0,0 @@
1
- require 'vagrant-1cloud/helpers/client'
2
- require 'timeout'
3
-
4
- module VagrantPlugins
5
- module OneCloud
6
- module Actions
7
- class PrivateNetwork
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::onecloud::private_network')
16
- end
17
-
18
- def call(env)
19
- # check if network name is set
20
- return @app.call(env) unless @machine.provider_config.private_net
21
-
22
- @machine.provider_config.private_net.each do |net, ip|
23
- # Getting private network by name
24
- result = @client.request('/network')
25
- private_network = result['body'].find { |network| network['Name'] == net.to_s }
26
-
27
- raise "Private network #{net} is not created" if !private_network
28
-
29
- # Checking if machine is already added to network
30
- result = @client.request("/server/#{@machine.id}")
31
- linked_network = result['body']['LinkedNetworks'].find { |network| network['NetworkID'] == private_network['ID'] }
32
-
33
- if linked_network
34
- env[:ui].info I18n.t('vagrant_1cloud.info.already_connected', network: net)
35
- next
36
- end
37
-
38
- # Adding server to specified network
39
- result = @client.post("/server/#{@machine.id}/Action", {
40
- :Type => "AddNetwork",
41
- :NetworkID => private_network['ID']
42
- })
43
-
44
- # Waiting for server to add to private network
45
- env[:ui].info I18n.t('vagrant_1cloud.info.setting_private_network')
46
- @client.wait_for_event(env, @machine.id, result['body']['ID'])
47
-
48
- # refresh droplet state with provider
49
- Provider.droplet(@machine, :refresh => true)
50
-
51
- result = @client.request("/server/#{@machine.id}")
52
- linked_network = result['body']['LinkedNetworks'].find { |network| network['NetworkID'] == private_network['ID'] }
53
-
54
- if !ip
55
- ip = linked_network['IP']
56
- end
57
-
58
- # override ssh username to root temporarily
59
- user = @machine.config.ssh.username
60
- @machine.config.ssh.username = 'root'
61
-
62
- # set private network rules
63
- if private_network['IsDHCP']
64
- @machine.communicate.execute(<<-BASH)
65
- ifdown -a
66
-
67
- export INTERFACE=$(ifconfig -a | grep #{linked_network['MAC']} | awk '{print $1}')
68
- export MATCHADDR=#{linked_network['MAC']}
69
- export MATCHID=$(ifconfig -a | grep #{linked_network['MAC']} | awk 'system("udevadm info /sys/class/net/" $1)' | grep P: | awk -F/ '{print $(NF-2)}')
70
- /lib/udev/write_net_rules
71
- udevadm control --reload-rules && udevadm trigger
72
-
73
- echo >> /etc/network/interfaces
74
- ifconfig -a | grep #{linked_network['MAC']} | awk '{print "auto " $1}' >> /etc/network/interfaces
75
- ifconfig -a | grep #{linked_network['MAC']} | awk '{print "iface " $1 " inet dhcp"}' >> /etc/network/interfaces
76
-
77
- ifup -a
78
- BASH
79
- else
80
- @machine.communicate.execute(<<-BASH)
81
- ifdown -a
82
-
83
- export INTERFACE=$(ifconfig -a | grep #{linked_network['MAC']} | awk '{print $1}')
84
- export MATCHADDR=#{linked_network['MAC']}
85
- export MATCHID=$(ifconfig -a | grep #{linked_network['MAC']} | awk 'system("udevadm info /sys/class/net/" $1)' | grep P: | awk -F/ '{print $(NF-2)}')
86
- /lib/udev/write_net_rules
87
- udevadm control --reload-rules && udevadm trigger
88
-
89
- echo >> /etc/network/interfaces
90
- ifconfig -a | grep #{linked_network['MAC']} | awk '{print "auto " $1}' >> /etc/network/interfaces
91
- ifconfig -a | grep #{linked_network['MAC']} | awk '{print "iface " $1 " inet static"}' >> /etc/network/interfaces
92
- echo "address #{ip}" >> /etc/network/interfaces
93
- echo "netmask #{private_network['Mask']}" >> /etc/network/interfaces
94
-
95
- ifup -a
96
- BASH
97
- end
98
-
99
- # reset username
100
- @machine.config.ssh.username = user
101
- end
102
-
103
- @app.call(env)
104
- end
105
- end
106
- end
107
- end
108
- end
@@ -1,78 +0,0 @@
1
- require 'vagrant-1cloud/helpers/client'
2
- require 'net/ssh'
3
-
4
- module VagrantPlugins
5
- module OneCloud
6
- module Actions
7
- class Rebuild
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::onecloud::rebuild')
16
- end
17
-
18
- def call(env)
19
-
20
- # submit rebuild request
21
- result = @client.post("/server/#{@machine.id}/rebuild", {
22
- :ImageId => @machine.provider_config.image
23
- })
24
-
25
- # assign the machine id for reference in other commands
26
- @machine.id = result['body']['ID'].to_s
27
-
28
- # wait for request to complete
29
- result = @client.request("/server/#{@machine.id}/action")
30
- env[:ui].info I18n.t('vagrant_1cloud.info.rebuilding')
31
- @client.wait_for_event(env, @machine.id, result['body'].first['ID'])
32
-
33
- # refresh droplet state with provider
34
- droplet = Provider.droplet(@machine, :refresh => true)
35
-
36
- user = @machine.config.ssh.username
37
- @machine.config.ssh.username = 'root'
38
-
39
- # add public key to machine
40
- ssh_key_name = @machine.provider_config.ssh_key_name
41
- result = @client.request('/sshkey')
42
- pub_key = result['body'].find { |k| k['Title'] == ssh_key_name }
43
-
44
- Net::SSH.start(droplet['IP'], droplet['AdminUserName'], :password => droplet['AdminPassword']) do |ssh|
45
- ssh.exec!("mkdir ~/.ssh")
46
- ssh.exec!("touch ~/.ssh/authorized_keys")
47
- ssh.exec!("echo \"ssh-rsa #{pub_key['PublicKey']}\" >> ~/.ssh/authorized_keys")
48
- ssh.exec!("chmod 600 ~/.ssh/authorized_keys")
49
- end
50
-
51
- # wait for ssh to be ready
52
- env[:ui].info I18n.t('vagrant_1cloud.info.ssh')
53
- @client.wait_for_ssh(env, 3, 30)
54
-
55
- # change authorized_keys file permissions, host name and set public network rules
56
- @machine.communicate.execute(<<-BASH)
57
- sed -i -e "s/127.0.1.1.*/127.0.1.1\t#{@machine.config.vm.hostname}/" /etc/hosts
58
- sed -i -e "s/#{droplet['IP']}.*/#{droplet['IP']}\t#{@machine.config.vm.hostname}/" /etc/hosts
59
- echo #{@machine.config.vm.hostname} > /etc/hostname
60
- hostname #{@machine.config.vm.hostname}
61
-
62
- ifdown -a
63
- export INTERFACE=eth0
64
- export MATCHADDR=$(ifconfig -a | grep eth0 | awk '{print $NF}')
65
- export MATCHID=$(udevadm info /sys/class/net/eth0 | grep P: | awk -F/ '{print $(NF-2)}')
66
- /lib/udev/write_net_rules
67
- udevadm control --reload-rules && udevadm trigger
68
- ifup -a
69
- BASH
70
-
71
- @machine.config.ssh.username = user
72
-
73
- @app.call(env)
74
- end
75
- end
76
- end
77
- end
78
- end
@@ -1,42 +0,0 @@
1
- require 'vagrant-1cloud/helpers/client'
2
-
3
- module VagrantPlugins
4
- module OneCloud
5
- module Actions
6
- class Reload
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::onecloud::reload')
14
- end
15
-
16
- def call(env)
17
- # submit reboot droplet request
18
- result = @client.post("/server/#{@machine.id}/action", {
19
- :Type => 'PowerReboot'
20
- })
21
-
22
- # wait for request to complete
23
- env[:ui].info I18n.t('vagrant_1cloud.info.reloading')
24
- @client.wait_for_event(env, @machine.id, result['body']['ID'])
25
-
26
- user = @machine.config.ssh.username
27
- @machine.config.ssh.username = 'root'
28
-
29
- # wait for ssh to be ready
30
- env[:ui].info I18n.t('vagrant_1cloud.info.ssh')
31
- @client.wait_for_ssh(env, 3, 30)
32
-
33
- @machine.config.ssh.username = user
34
-
35
- @app.call(env)
36
- end
37
- end
38
- end
39
- end
40
- end
41
-
42
-
@@ -1,60 +0,0 @@
1
- require 'vagrant-1cloud/helpers/client'
2
-
3
- module VagrantPlugins
4
- module OneCloud
5
- module Actions
6
- class SetupKey
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::onecloud::setup_key')
14
- end
15
-
16
- # TODO check the content of the key to see if it has changed
17
- def call(env)
18
- ssh_key_name = @machine.provider_config.ssh_key_name
19
-
20
- begin
21
- # assigns existing ssh key id to env for use by other commands
22
- env[:ssh_key_id] = @client
23
- .request('/sshkey')
24
- .find_id(:body, :Title => ssh_key_name)
25
-
26
- env[:ui].info I18n.t('vagrant_1cloud.info.using_key', {
27
- :name => ssh_key_name
28
- })
29
- rescue Errors::ResultMatchError
30
- env[:ssh_key_id] = create_ssh_key(ssh_key_name, env)
31
- end
32
-
33
- puts env[:ssh_key_id]
34
-
35
- @app.call(env)
36
- end
37
-
38
- private
39
-
40
- def create_ssh_key(name, env)
41
- # assumes public key exists on the same path as private key with .pub ext
42
- path = @machine.config.ssh.private_key_path
43
- path = path[0] if path.is_a?(Array)
44
- path = File.expand_path(path, @machine.env.root_path)
45
- pub_key = OneCloud.public_key(path)
46
-
47
- env[:ui].info I18n.t('vagrant_1cloud.info.creating_key', {
48
- :name => name
49
- })
50
-
51
- result = @client.post('/sshkey', {
52
- :Title => name,
53
- :PublicKey => pub_key
54
- })
55
- result['body']['ID']
56
- end
57
- end
58
- end
59
- end
60
- end
@@ -1,43 +0,0 @@
1
- module VagrantPlugins
2
- module OneCloud
3
- module Actions
4
- class SetupSudo
5
- def initialize(app, env)
6
- @app = app
7
- @machine = env[:machine]
8
- @logger = Log4r::Logger.new('vagrant::onecloud::setup_sudo')
9
- end
10
-
11
- def call(env)
12
- # override ssh username to root
13
- user = @machine.config.ssh.username
14
- @machine.config.ssh.username = 'root'
15
-
16
- # check for guest name available in Vagrant 1.2 first
17
- guest_name = @machine.guest.name if @machine.guest.respond_to?(:name)
18
- guest_name ||= @machine.guest.to_s.downcase
19
-
20
- case guest_name
21
- when /debian/
22
- env[:ui].info I18n.t('vagrant_1cloud.info.late_sudo_install_deb')
23
- @machine.communicate.execute(<<-'BASH')
24
- if [ ! -x /usr/bin/sudo ] ; then apt-get update -y && apt-get install -y sudo ; fi
25
- BASH
26
- when /redhat/
27
- env[:ui].info I18n.t('vagrant_1cloud.info.modifying_sudo')
28
-
29
- # disable tty requirement for sudo
30
- @machine.communicate.execute(<<-'BASH')
31
- sed -i'.bk' -e 's/\(Defaults\s\+requiretty\)/# \1/' /etc/sudoers
32
- BASH
33
- end
34
-
35
- # reset ssh username
36
- @machine.config.ssh.username = user
37
-
38
- @app.call(env)
39
- end
40
- end
41
- end
42
- end
43
- end