Skip to content

Commit 5f59f23

Browse files
committed
Add support for vagrant cloud, Fixes #1
1 parent 9fe582a commit 5f59f23

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

lib/vagrant-vcenter/action/build_vm.rb

+10-2
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,19 @@ def call(env)
2222
dc = config.vcenter_cnx.serviceInstance.find_datacenter(
2323
config.datacenter_name) or abort 'datacenter not found'
2424

25+
if env[:machine].box.name.to_s.include? '/'
26+
box_file = env[:machine].box.name.rpartition('/').last.to_s
27+
box_name = env[:machine].box.name.to_s.gsub(/\//, '-')
28+
else
29+
box_file = env[:machine].box.name.to_s
30+
box_name = box_file
31+
end
32+
2533
if config.template_folder_name.nil?
26-
box_to_search = env[:machine].box.name.to_s
34+
box_to_search = box_name
2735
else
2836
box_to_search = config.template_folder_name + '/' +
29-
env[:machine].box.name.to_s
37+
box_name
3038
end
3139

3240
# FIXME: Raise a correct exception

lib/vagrant-vcenter/action/connect_vcenter.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def call(env)
2020

2121
@logger.debug("config.hostname: #{config.hostname}")
2222
@logger.debug("config.username: #{config.username}")
23-
@logger.debug("config.password: #{config.password}")
23+
@logger.debug('config.password: <hidden>')
2424

2525
# FIXME: fix the insecure flag, catch the exception
2626
config.vcenter_cnx = RbVmomi::VIM.connect(

lib/vagrant-vcenter/action/inventory_check.rb

+23-8
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,14 @@ def vcenter_upload_box(env)
2626
config = env[:machine].provider_config
2727

2828
box_dir = env[:machine].box.directory.to_s
29-
box_file = env[:machine].box.name.to_s
29+
30+
if env[:machine].box.name.to_s.include? '/'
31+
box_file = env[:machine].box.name.rpartition('/').last.to_s
32+
box_name = env[:machine].box.name.to_s.gsub(/\//, '-')
33+
else
34+
box_file = env[:machine].box.name.to_s
35+
box_name = box_file
36+
end
3037

3138
box_ovf = "file://#{box_dir}/#{box_file}.ovf"
3239

@@ -35,7 +42,7 @@ def vcenter_upload_box(env)
3542

3643
@logger.debug("OVF File: #{box_ovf}")
3744

38-
env[:ui].info("Adding [#{env[:machine].box.name.to_s}]")
45+
env[:ui].info("Adding [#{box_name}]")
3946

4047
# FIXME: Raise a correct exception
4148
dc = config.vcenter_cnx.serviceInstance.find_datacenter(
@@ -51,7 +58,7 @@ def vcenter_upload_box(env)
5158
config.template_folder_name,
5259
RbVmomi::VIM::Folder)
5360

54-
template_name = box_file
61+
template_name = box_name
5562

5663
# FIXME: Raise a correct exception
5764
datastore = dc.find_datastore(
@@ -91,28 +98,36 @@ def vcenter_check_inventory(env)
9198
dc = config.vcenter_cnx.serviceInstance.find_datacenter(
9299
config.datacenter_name) or fail 'datacenter not found'
93100

101+
if env[:machine].box.name.to_s.include? '/'
102+
box_file = env[:machine].box.name.rpartition('/').last.to_s
103+
box_name = env[:machine].box.name.to_s.gsub(/\//, '-')
104+
else
105+
box_file = env[:machine].box.name.to_s
106+
box_name = box_file
107+
end
108+
94109
if config.template_folder_name.nil?
95-
box_to_search = env[:machine].box.name.to_s
110+
box_to_search = box_name
96111
else
97112
box_to_search = config.template_folder_name +
98-
'/' + env[:machine].box.name.to_s
113+
'/' + box_name
99114
end
100115

101116
@logger.debug("This is the box we're looking for: #{box_to_search}")
102117

103118
config.template_id = dc.find_vm(box_to_search)
104119

105120
if config.template_id.nil?
106-
env[:ui].warn("Template [#{env[:machine].box.name.to_s}] " +
121+
env[:ui].warn("Template [#{box_name}] " +
107122
'does not exist!')
108123

109124
user_input = env[:ui].ask(
110-
"Would you like to upload the [#{env[:machine].box.name.to_s}]" +
125+
"Would you like to upload the [#{box_name}]" +
111126
" box?\nChoice (yes/no): "
112127
)
113128

114129
if user_input.downcase == 'yes' || user_input.downcase == 'y'
115-
env[:ui].info("Uploading [#{env[:machine].box.name.to_s}]...")
130+
env[:ui].info("Uploading [#{box_name}]...")
116131
vcenter_upload_box(env)
117132
else
118133
env[:ui].error('Template not uploaded, exiting...')

0 commit comments

Comments
 (0)