1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-14 01:57:24 +03:00

F #5221: sanitize network name in vCenter (#752)

This commit is contained in:
Carlos J. Herrera 2021-02-03 10:09:24 -05:00 committed by GitHub
parent b9f4066e4f
commit a23950434e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 13 deletions

View File

@ -118,17 +118,6 @@ class OpenNebulaVMRC
@logger = logger
end
def sanitize(ticket)
# Bad as defined by wikipedia: https://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
# Also have to escape the backslash
bad_chars = ['/', '\\', '?', '%', '*', ':',
'|', '"', '<', '>', '.', ' ']
bad_chars.each do |bad_char|
ticket.gsub!(bad_char, '_')
end
ticket
end
def proxy(vm_resource, client = nil)
# Check configurations and VM attributes
unless VMRC_STATES.include?(vm_resource['LCM_STATE'])
@ -169,7 +158,7 @@ class OpenNebulaVMRC
:ticket => parameters[:ticket]
}
file = File.open(VMRC_TICKETS + sanitize(data[:ticket]), 'w')
file = File.open(VMRC_TICKETS + VCenterDriver::FileHelper.sanitize(data[:ticket]), 'w')
file.write('https://' + data[:host] + ':' + data[:port].to_s)
file.close

View File

@ -554,7 +554,9 @@ module VCenterDriver
full_process = !args[:short]
vc_network_ref = vc_network._ref
vc_network_name = vc_network.name
vc_network_name = VCenterDriver::FileHelper.sanitize(
vc_network.name
)
vc_network_host = vc_network['host']
vc_network_tag = vc_network['tag']

View File

@ -27,6 +27,19 @@ module VCenterDriver
##########################################################################
class FileHelper
def self.sanitize(text)
# Bad as defined by wikipedia:
# https://en.wikipedia.org/wiki/Filename in
# Reserved_characters_and_words
# Also have to escape the backslash
bad_chars = ['/', '\\', '?', '%', '*', ':',
'|', '"', '<', '>', '.', ' ']
bad_chars.each do |bad_char|
text.gsub!(bad_char, '_')
end
text
end
def self.get_img_name(
disk,
vm_id,