@@ -26,7 +26,14 @@ def vcenter_upload_box(env)
26
26
config = env [ :machine ] . provider_config
27
27
28
28
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
30
37
31
38
box_ovf = "file://#{ box_dir } /#{ box_file } .ovf"
32
39
@@ -35,7 +42,7 @@ def vcenter_upload_box(env)
35
42
36
43
@logger . debug ( "OVF File: #{ box_ovf } " )
37
44
38
- env [ :ui ] . info ( "Adding [#{ env [ :machine ] . box . name . to_s } ]" )
45
+ env [ :ui ] . info ( "Adding [#{ box_name } ]" )
39
46
40
47
# FIXME: Raise a correct exception
41
48
dc = config . vcenter_cnx . serviceInstance . find_datacenter (
@@ -51,7 +58,7 @@ def vcenter_upload_box(env)
51
58
config . template_folder_name ,
52
59
RbVmomi ::VIM ::Folder )
53
60
54
- template_name = box_file
61
+ template_name = box_name
55
62
56
63
# FIXME: Raise a correct exception
57
64
datastore = dc . find_datastore (
@@ -91,28 +98,36 @@ def vcenter_check_inventory(env)
91
98
dc = config . vcenter_cnx . serviceInstance . find_datacenter (
92
99
config . datacenter_name ) or fail 'datacenter not found'
93
100
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
+
94
109
if config . template_folder_name . nil?
95
- box_to_search = env [ :machine ] . box . name . to_s
110
+ box_to_search = box_name
96
111
else
97
112
box_to_search = config . template_folder_name +
98
- '/' + env [ :machine ] . box . name . to_s
113
+ '/' + box_name
99
114
end
100
115
101
116
@logger . debug ( "This is the box we're looking for: #{ box_to_search } " )
102
117
103
118
config . template_id = dc . find_vm ( box_to_search )
104
119
105
120
if config . template_id . nil?
106
- env [ :ui ] . warn ( "Template [#{ env [ :machine ] . box . name . to_s } ] " +
121
+ env [ :ui ] . warn ( "Template [#{ box_name } ] " +
107
122
'does not exist!' )
108
123
109
124
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 } ]" +
111
126
" box?\n Choice (yes/no): "
112
127
)
113
128
114
129
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 } ]..." )
116
131
vcenter_upload_box ( env )
117
132
else
118
133
env [ :ui ] . error ( 'Template not uploaded, exiting...' )
0 commit comments