Skip to content

Commit e2c8da5

Browse files
author
Timothy van Zadelhoff
committed
Allow assign private ip in config Fixes #52
1 parent a0a9267 commit e2c8da5

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ to update UUIDs in your Vagrantfile. If both are specified, the id parameter tak
159159
* `group` - Group for the instance
160160
* `ssh_key` - Path to a private key to be used with ssh
161161
* `ssh_user` - User name to be used with ssh
162+
* `private_ip_address` - private (static)ip address to be used by the virtual machine
162163

163164
These can be set like typical provider-specific configuration:
164165

lib/vagrant-cloudstack/action/run_instance.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def call(env)
5252
user_data = domain_config.user_data
5353
ssh_key = domain_config.ssh_key
5454
ssh_user = domain_config.ssh_user
55+
private_ip_address = domain_config.private_ip_address
5556

5657
# If for some reason the user have specified both network_name and network_id, take the id since that is
5758
# more specific than the name. But always try to fetch the name of the network to present to the user.
@@ -144,6 +145,7 @@ def call(env)
144145
options['project_id'] = project_id if project_id != nil
145146
options['key_name'] = keypair if keypair != nil
146147
options['name'] = hostname if hostname != nil
148+
options['ip_address'] = private_ip_address if private_ip_address != nil
147149

148150
if user_data != nil
149151
options['user_data'] = Base64.urlsafe_encode64(user_data)

lib/vagrant-cloudstack/config.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ class Config < Vagrant.plugin("2", :config)
192192
# @return [String]
193193
attr_accessor :ssh_user
194194

195+
# Private ip for the instance
196+
#
197+
# @return [String]
198+
attr_accessor :private_ip_address
199+
195200

196201
def initialize(domain_specific=false)
197202
@host = UNSET_VALUE
@@ -230,6 +235,7 @@ def initialize(domain_specific=false)
230235
@user_data = UNSET_VALUE
231236
@ssh_key = UNSET_VALUE
232237
@ssh_user = UNSET_VALUE
238+
@private_ip_address = UNSET_VALUE
233239

234240
# Internal state (prefix with __ so they aren't automatically
235241
# merged)
@@ -408,6 +414,9 @@ def finalize!
408414
# ssh key is nil by default
409415
@ssh_user = nil if @ssh_user == UNSET_VALUE
410416

417+
# private ip is nil by default
418+
@private_ip_address = nil if @private_ip_address == UNSET_VALUE
419+
411420
# Compile our domain specific configurations only within
412421
# NON-DOMAIN-SPECIFIC configurations.
413422
if !@__domain_specific

spec/vagrant-cloudstack/config_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
its("user_data") { should be_nil }
4747
its("ssh_key") { should be_nil }
4848
its("ssh_user") { should be_nil }
49+
its("private_ip_address") { should be_nil }
4950
end
5051

5152
describe "getting credentials from environment" do
@@ -146,6 +147,7 @@
146147
let(:config_security_groups) { [{:foo => "bar"}, {:bar => "foo"}] }
147148
let(:config_ssh_key) { "./foo.pem" }
148149
let(:config_ssh_user) { "foo" }
150+
let(:config_private_ip_address) { "foo" }
149151

150152
def set_test_values(instance)
151153
instance.host = config_host
@@ -177,6 +179,7 @@ def set_test_values(instance)
177179
instance.security_groups = config_security_groups
178180
instance.ssh_key = config_ssh_key
179181
instance.ssh_user = config_ssh_user
182+
instance.private_ip_address = config_private_ip_address
180183
end
181184

182185
it "should raise an exception if not finalized" do
@@ -225,6 +228,7 @@ def set_test_values(instance)
225228
its("security_groups") { should == config_security_groups }
226229
its("ssh_key") { should == config_ssh_key }
227230
its("ssh_user") { should == config_ssh_user }
231+
its("private_ip_address") { should == config_private_ip_address }
228232
end
229233

230234
context "with a specific config set" do
@@ -272,6 +276,7 @@ def set_test_values(instance)
272276
its("security_groups") { should == config_security_groups }
273277
its("ssh_key") { should == config_ssh_key }
274278
its("ssh_user") { should == config_ssh_user }
279+
its("private_ip_address") { should == config_private_ip_address }
275280
end
276281

277282
describe "inheritance of parent config" do

0 commit comments

Comments
 (0)