Skip to content

Commit

Permalink
vmware plugin: fix restore to different vmname
Browse files Browse the repository at this point in the history
Bugfix for restore to different vmname in same folder failing with
duplicate name error. Check for invalid plugin option also works
correctly now for both plugin options and config file.
  • Loading branch information
sduehr authored and arogge committed Mar 1, 2023
1 parent 7cec0e6 commit 6a4db27
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions core/src/plugins/filed/python/vmware/BareosFdPluginVMware.py
Expand Up @@ -110,7 +110,14 @@ def __init__(self, plugindef):
"restore_resourcepool",
"restore_datastore",
"restore_powerstate",
"poweron_timeout",
"config_file",
]
self.allowed_options = (
self.mandatory_options_default
+ self.mandatory_options_vmname
+ self.optional_options
)
self.utf8_options = ["vmname", "folder"]
self.config = None
self.config_parsed = False
Expand Down Expand Up @@ -175,11 +182,6 @@ def check_config(self):
"""
bareosfd.DebugMessage(100, "BareosFdPluginVMware: check_config()\n")
mandatory_sections = ["vmware_plugin_options"]
allowed_options = (
self.mandatory_options_default
+ self.mandatory_options_vmname
+ self.optional_options
)

for section in mandatory_sections:
if not self.config.has_section(section):
Expand All @@ -191,7 +193,7 @@ def check_config(self):
return False

for option in self.config.options(section):
if option not in allowed_options:
if option not in self.allowed_options:
bareosfd.JobMessage(
bareosfd.M_FATAL,
"BareosFdPluginVMware: Invalid option %s in Section [%s] in config file %s\n"
Expand Down Expand Up @@ -266,6 +268,15 @@ def check_plugin_options(self, mandatory_options=None):

return bareosfd.bRC_Error

invalid_options = ",".join(list(set(self.options) - set(self.allowed_options)))
if invalid_options:
bareosfd.JobMessage(
bareosfd.M_FATAL,
"BareosFdPluginVMware: Invalid plugin options: %s\n"
% (invalid_options),
)
return bareosfd.bRC_Error

for option in self.utf8_options:
if self.options.get(option):
# make sure to convert to utf8
Expand Down Expand Up @@ -1442,7 +1453,9 @@ def create_vm(self):
return False
self.vmfs_vm_path_changed = True

config = transformer.transform(target_datastore_name=datastore_name)
config = transformer.transform(
target_datastore_name=datastore_name, target_vm_name=self.options["vmname"]
)

for child in self.si.content.rootFolder.childEntity:
if child.name == self.options["dc"]:
Expand Down Expand Up @@ -2626,7 +2639,7 @@ def __init__(self, config_info):
self.backing_filename_snapshot_rex = re.compile(r"(-\d{6})\.vmdk$")
self.target_datastore_name = None

def transform(self, target_datastore_name=None):
def transform(self, target_datastore_name=None, target_vm_name=None):
config_spec = vim.vm.ConfigSpec()
self.target_datastore_name = target_datastore_name
config_spec.alternateGuestName = self.config_info["alternateGuestName"]
Expand Down Expand Up @@ -2668,6 +2681,8 @@ def transform(self, target_datastore_name=None):
]
config_spec.migrateEncryption = self.config_info["migrateEncryption"]
config_spec.name = self.config_info["name"]
if target_vm_name:
config_spec.name = target_vm_name
config_spec.nestedHVEnabled = self.config_info["nestedHVEnabled"]
config_spec.numCoresPerSocket = self.config_info["hardware"][
"numCoresPerSocket"
Expand Down Expand Up @@ -3408,7 +3423,6 @@ def _transform_vAppConfig(self):
return vapp_config_spec

def _transform_VAppIpAssignmentInfo(self, ip_assignment_info):

ip_assignment = vim.vApp.IPAssignmentInfo()
ip_assignment.ipAllocationPolicy = ip_assignment_info["ipAllocationPolicy"]
ip_assignment.ipProtocol = ip_assignment_info["ipProtocol"]
Expand Down

0 comments on commit 6a4db27

Please sign in to comment.