vagrant-1cloud 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7bb17fc50b50b1d2fb51b2b906e48fdfc369e667
4
- data.tar.gz: b321c58f57d2eb58c5c04b637c7d63a8a1242fec
3
+ metadata.gz: 5eec683827d327313151a52ada3ac6286330fa1f
4
+ data.tar.gz: 1d122e8b57ce0d16d7d79fffab20016ac0e6c7b8
5
5
  SHA512:
6
- metadata.gz: d2df9beff77ac26ebc69896402b9f1cee28ee526385f9061bf3e872a397f468e1eb51132fadc534d3853d2a7ad198c9357e208b0eec69fc00c99627611ccaf6f
7
- data.tar.gz: 8a30db21c821c29a1dee964ec1aa5e7a3984a5e3ceca4ec19db8ec86135b3b051b9159645efd03134efd793d63e6e75f99488c97b4e0674faa0fcb00a803d9cc
6
+ metadata.gz: d4f69bb3364b08aea18cb602ab6950d1bed3bdfac473c8a60660f25a5388383d1cd1225edd46d2112d5dc08ae8f5fe144d22e5b5319aaa3a4e68301b4497e8b6
7
+ data.tar.gz: 75de8eb60668039b7f697153bbf2ed8c6bcb1fc555933bfe96e0b4b8de34d292d8dd57c40e830a9011f299dbbdd47f150352cd8ef494c9b70d425e2b76c7747a
data/.gitignore CHANGED
@@ -10,3 +10,4 @@
10
10
  vagrant-1cloud.iml
11
11
  /.idea/
12
12
  /.svn/
13
+ .rake_tasks~
@@ -54,7 +54,7 @@ module VagrantPlugins
54
54
 
55
55
  # wait for ssh to be ready
56
56
  $reboot_num = 3
57
- $check_num = 20
57
+ $check_num = 30
58
58
  $i = 0
59
59
  while $i <= $reboot_num do
60
60
  $j = 0
@@ -31,7 +31,7 @@ module VagrantPlugins
31
31
 
32
32
  # wait for ssh to be ready
33
33
  $reboot_num = 3
34
- $check_num = 20
34
+ $check_num = 30
35
35
  $i = 0
36
36
  while $i <= $reboot_num do
37
37
  $j = 0
@@ -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
- ifconfig -a | grep #{linked_network['MAC']} | awk '{system("ifdown "$1" && ifup "$1)}'
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
@@ -28,7 +28,7 @@ module VagrantPlugins
28
28
 
29
29
  # wait for ssh to be ready
30
30
  $reboot_num = 3
31
- $check_num = 20
31
+ $check_num = 30
32
32
  $i = 0
33
33
  while $i <= $reboot_num do
34
34
  $j = 0
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module OneCloud
3
- VERSION = '1.0.2'
3
+ VERSION = '1.0.3'
4
4
  end
5
5
  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.2
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-21 00:00:00.000000000 Z
11
+ date: 2017-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday