vagrant-1cloud 1.0.2 → 1.0.3
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 +4 -4
- data/.gitignore +1 -0
- data/lib/vagrant-1cloud/actions/create.rb +1 -1
- data/lib/vagrant-1cloud/actions/power_on.rb +1 -1
- data/lib/vagrant-1cloud/actions/private_network.rb +49 -2
- data/lib/vagrant-1cloud/actions/reload.rb +1 -1
- data/lib/vagrant-1cloud/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5eec683827d327313151a52ada3ac6286330fa1f
|
4
|
+
data.tar.gz: 1d122e8b57ce0d16d7d79fffab20016ac0e6c7b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4f69bb3364b08aea18cb602ab6950d1bed3bdfac473c8a60660f25a5388383d1cd1225edd46d2112d5dc08ae8f5fe144d22e5b5319aaa3a4e68301b4497e8b6
|
7
|
+
data.tar.gz: 75de8eb60668039b7f697153bbf2ed8c6bcb1fc555933bfe96e0b4b8de34d292d8dd57c40e830a9011f299dbbdd47f150352cd8ef494c9b70d425e2b76c7747a
|
data/.gitignore
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
require 'vagrant-1cloud/helpers/client'
|
2
|
+
require 'timeout'
|
2
3
|
|
3
4
|
module VagrantPlugins
|
4
5
|
module OneCloud
|
5
6
|
module Actions
|
6
7
|
class PrivateNetwork
|
7
8
|
include Helpers::Client
|
9
|
+
include Vagrant::Util::Retryable
|
8
10
|
|
9
11
|
def initialize(app, env)
|
10
12
|
@app = app
|
@@ -17,15 +19,28 @@ module VagrantPlugins
|
|
17
19
|
# check if network name is set
|
18
20
|
return @app.call(env) unless @machine.provider_config.net_name
|
19
21
|
|
22
|
+
lockfile = "/tmp/" + @machine.provider_config.net_name.to_s + ".lock"
|
23
|
+
f = File.open(lockfile, "w+")
|
24
|
+
|
25
|
+
retryable(:tries => 120, :sleep => 10) do
|
26
|
+
next if env[:interrupted]
|
27
|
+
raise 'not ready' if check_file_locked?(lockfile)
|
28
|
+
end
|
29
|
+
|
30
|
+
f.flock(File::LOCK_EX)
|
31
|
+
|
32
|
+
# Getting private network by name
|
20
33
|
result = @client.request('/network')
|
21
34
|
private_network = result['body'].find { |network| network['Name'] == @machine.provider_config.net_name.to_s }
|
22
35
|
|
36
|
+
# Creating private network if it doesn't exist
|
23
37
|
if !private_network
|
24
38
|
result = @client.post("/network", {
|
25
39
|
:Name => @machine.provider_config.net_name,
|
26
40
|
:IsDHCP => false,
|
27
41
|
:DCLocation => @machine.provider_config.region
|
28
42
|
})
|
43
|
+
# Waiting for private network to create
|
29
44
|
env[:ui].info I18n.t('vagrant_1cloud.info.creating_private_network')
|
30
45
|
@client.wait_for_network(env, result['body']['ID'])
|
31
46
|
|
@@ -33,11 +48,15 @@ module VagrantPlugins
|
|
33
48
|
private_network = result['body']
|
34
49
|
end
|
35
50
|
|
51
|
+
f.flock(File::LOCK_UN)
|
52
|
+
|
53
|
+
# Adding server to specified network
|
36
54
|
result = @client.post("/Server/#{@machine.id}/Action", {
|
37
55
|
:Type => "AddNetwork",
|
38
56
|
:NetworkID => private_network['ID']
|
39
57
|
})
|
40
58
|
|
59
|
+
# Waiting for server to add to private network
|
41
60
|
env[:ui].info I18n.t('vagrant_1cloud.info.setting_private_network')
|
42
61
|
@client.wait_for_event(env, @machine.id, result['body']['ID'])
|
43
62
|
|
@@ -55,14 +74,31 @@ module VagrantPlugins
|
|
55
74
|
user = @machine.config.ssh.username
|
56
75
|
@machine.config.ssh.username = 'root'
|
57
76
|
|
58
|
-
# set private network
|
77
|
+
# set private and public network
|
59
78
|
@machine.communicate.execute(<<-BASH)
|
79
|
+
ifdown -a
|
80
|
+
|
81
|
+
export INTERFACE=eth0
|
82
|
+
export MATCHADDR=$(ifconfig -a | grep eth0 | awk '{print $NF}')
|
83
|
+
export MATCHID=$(udevadm info /sys/class/net/eth0 | grep P: | awk -F/ '{print $(NF-2)}')
|
84
|
+
/lib/udev/write_net_rules
|
85
|
+
|
86
|
+
export INTERFACE=$(ifconfig -a | grep #{linked_network['MAC']} | awk '{print $1}')
|
87
|
+
export MATCHADDR=#{linked_network['MAC']}
|
88
|
+
export MATCHID=$(ifconfig -a | grep #{linked_network['MAC']} | awk 'system("udevadm info /sys/class/net/" $1)' | grep P: | awk -F/ '{print $(NF-2)}')
|
89
|
+
/lib/udev/write_net_rules
|
90
|
+
|
91
|
+
udevadm control --reload-rules && udevadm trigger
|
92
|
+
|
93
|
+
ifconfig -a | grep eth0 | awk '{print "hwaddress ether " $5}' >> /etc/network/interfaces
|
60
94
|
echo >> /etc/network/interfaces
|
61
95
|
ifconfig -a | grep #{linked_network['MAC']} | awk '{print "auto " $1}' >> /etc/network/interfaces
|
62
96
|
ifconfig -a | grep #{linked_network['MAC']} | awk '{print "iface " $1 " inet static"}' >> /etc/network/interfaces
|
63
97
|
echo "address #{@machine.provider_config.private_ip}" >> /etc/network/interfaces
|
64
98
|
echo "netmask #{private_network['Mask']}" >> /etc/network/interfaces
|
65
|
-
|
99
|
+
echo "hwaddress ether #{linked_network['MAC']}" >> /etc/network/interfaces
|
100
|
+
|
101
|
+
ifup -a
|
66
102
|
BASH
|
67
103
|
|
68
104
|
# reset username
|
@@ -70,6 +106,17 @@ module VagrantPlugins
|
|
70
106
|
|
71
107
|
@app.call(env)
|
72
108
|
end
|
109
|
+
|
110
|
+
def check_file_locked?(file)
|
111
|
+
f = File.open(file, File::CREAT)
|
112
|
+
Timeout::timeout(0.001) { f.flock(File::LOCK_EX) }
|
113
|
+
f.flock(File::LOCK_UN)
|
114
|
+
false
|
115
|
+
rescue
|
116
|
+
true
|
117
|
+
ensure
|
118
|
+
f.close
|
119
|
+
end
|
73
120
|
end
|
74
121
|
end
|
75
122
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-1cloud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bulat Yusupov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|