-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f867468
commit 969915d
Showing
9 changed files
with
714 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
minor_changes: | ||
- folder_template_from_vm - add module and tests to create a template from an existing VM in vcenter and store the template in a folder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright: (c) 2023, Ansible Cloud Team (@ansible-collections) | ||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
from __future__ import absolute_import, division, print_function | ||
__metaclass__ = type | ||
|
||
|
||
FOLDER_TYPES = ('vm', 'host', 'network', 'datastore') | ||
|
||
|
||
def __prepend_datacenter_and_folder_type(folder_path, datacenter_name, folder_type=None): | ||
""" | ||
Formats a folder path so it is absolute, meaning it includes the datacenter name and | ||
type (vm, host, etc) at the start of the path. If path already starts with | ||
the datacenter name, nothing is added. | ||
Eg: rest/of/path -> datacenter name/type/rest/of/path | ||
""" | ||
folder_path = folder_path.lstrip('/') | ||
if folder_path.startswith(datacenter_name): | ||
return folder_path | ||
|
||
if folder_type not in FOLDER_TYPES: | ||
raise ValueError("folder_type %s not in acceptable " % folder_type + | ||
"folder type values %s" % ', '.join(FOLDER_TYPES)) | ||
|
||
return '/'.join([datacenter_name, folder_type, folder_path]) | ||
|
||
|
||
def format_folder_path_as_vm_fq_path(folder_path, datacenter_name): | ||
""" | ||
Formats a VM folder path so it is absolute, meaning it prepends | ||
'datacenter name/vm/' to the path if needed. If path already starts with | ||
the datacenter name, nothing is added. | ||
Eg: rest/of/path -> datacenter name/vm/rest/of/path | ||
""" | ||
return __prepend_datacenter_and_folder_type(folder_path, datacenter_name, folder_type='vm') | ||
|
||
|
||
def format_folder_path_as_host_fq_path(folder_path, datacenter_name): | ||
""" | ||
Formats a host folder path so it is absolute, meaning it prepends | ||
'datacenter name/vm/' to the path if needed. If path already starts with | ||
the datacenter name, nothing is added. | ||
Eg: rest/of/path -> datacenter name/host/rest/of/path | ||
""" | ||
return __prepend_datacenter_and_folder_type(folder_path, datacenter_name, folder_type='host') | ||
|
||
|
||
def format_folder_path_as_network_fq_path(folder_path, datacenter_name): | ||
""" | ||
Formats a network folder path so it is absolute, meaning it prepends | ||
'datacenter name/network/' to the path if needed. If path already starts with | ||
the datacenter name, nothing is added. | ||
Eg: rest/of/path -> datacenter name/network/rest/of/path | ||
""" | ||
return __prepend_datacenter_and_folder_type(folder_path, datacenter_name, folder_type='network') | ||
|
||
|
||
def format_folder_path_as_datastore_fq_path(folder_path, datacenter_name): | ||
""" | ||
Formats a datastore folder path so it is absolute, meaning it prepends | ||
'datacenter name/datastore/' to the path if needed. If path already starts with | ||
the datacenter name, nothing is added. | ||
Eg: rest/of/path -> datacenter name/datastore/rest/of/path | ||
""" | ||
return __prepend_datacenter_and_folder_type(folder_path, datacenter_name, folder_type='datastore') |
Oops, something went wrong.