from .xlate import XLATOR
-__version__ = '3.1.3'
+__version__ = '3.1.4'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
# --------------------------------------------------------------------------
def create_varfiles(self):
- # vs_name = str([self.vsphere.keys()][0])
+ LOG.debug(_("Creating {!r} ...").format('terraform.tfvars'))
+
vs_name = None
for vs_name in self.vsphere.keys():
break
- LOG.debug(_("Creating varfile for VSPhere {!r} ...").format(vs_name))
+ if self.verbose > 1:
+ LOG.debug(_("Creating {w} for VSPhere {v!r} ...").format(
+ w='dcfile', v=vs_name))
vs_host = self.config.vsphere[vs_name].host
vs_port = self.config.vsphere[vs_name].port
''')
- LOG.debug(_("Creating {!r} ...").format('terraform.tfvars'))
if self.simulate:
if self.verbose:
print(content)
# --------------------------------------------------------------------------
def create_dcfile(self):
+ vs_name = None
+ for vs_name in self.vsphere.keys():
+ break
+
LOG.debug(_("Creating {!r} ...").format('dc.tf'))
+ if self.verbose > 1:
+ LOG.debug(_("Creating {w} for VSPhere {v!r} ...").format(
+ w='dcfile', v=vs_name))
content = textwrap.dedent('''\
# filename: dc.tf
''')
- for cluster in self.vsphere.clusters:
+ for cluster in self.vsphere[vs_name].clusters:
tpl = textwrap.dedent('''\
data "vsphere_resource_pool" "{pv}" {{
name = "{pn}"
if self.used_dc_clusters:
for dsc_name in sorted(self.used_dc_clusters, key=str.lower):
- dsc_tf_name = self.vsphere.ds_cluster_mapping[dsc_name]
+ dsc_tf_name = self.vsphere[vs_name].ds_cluster_mapping[dsc_name]
tpl = textwrap.dedent('''\
data "vsphere_datastore_cluster" "{tn}" {{
name = "{n}"
if self.used_datastores:
for ds_name in sorted(self.used_datastores, key=str.lower):
- ds_tf_name = self.vsphere.ds_mapping[ds_name]
+ ds_tf_name = self.vsphere[vs_name].ds_mapping[ds_name]
tpl = textwrap.dedent('''\
data "vsphere_datastore" "{tn}" {{
name = "{n}"
content += tpl.format(tn=ds_tf_name, n=ds_name)
for net_name in sorted(self.used_networks, key=str.lower):
- net_tf_name = self.vsphere.network_mapping[net_name]
+ net_tf_name = self.vsphere[vs_name].network_mapping[net_name]
tpl = textwrap.dedent('''\
data "vsphere_network" "{tn}" {{
name = "{n}"
}}
''')
+ project = self.full_project_name
+ if not project:
+ project = self.project_name
+
content = tpl.format(
host=self.config.tf_backend_host, scheme=self.config.tf_backend_scheme,
- prefix=self.config.tf_backend_path_prefix, project=self.project_name)
+ prefix=self.config.tf_backend_path_prefix, project=project)
if self.min_version_terraform:
content += ' required_version = ">= {}"\n'.format(str(self.min_version_terraform))
# --------------------------------------------------------------------------
def _create_instfile_general(self, vm, guest_id, tpl_vm):
+ vs_name = vm.vsphere
+
# ## General definitions of VM
if self.verbose > 1:
LOG.debug(_("Generating global definitions of {!r}.").format(vm.name))
''').format(vm.name)
- cluster = self.vsphere.get_cluster_by_name(vm.cluster)
+ cluster = self.vsphere[vs_name].get_cluster_by_name(vm.cluster)
if not cluster:
msg = _("Cluster {!r} not found - this shouldn't be happened.").format(
vm.cluster)
''').format(tn=vm.tf_name, n=vm.name, pv=cluster.resource_pool_var)
if vm.ds_cluster:
- dsc_tf_name = self.vsphere.ds_cluster_mapping[vm.ds_cluster]
+ dsc_tf_name = self.vsphere[vs_name].ds_cluster_mapping[vm.ds_cluster]
tpl = ' datastore_cluster_id = data.vsphere_datastore_cluster.{}.id\n'
content += tpl.format(dsc_tf_name)
if vm.datastore:
- ds_tf_name = self.vsphere.ds_mapping[vm.datastore]
+ ds_tf_name = self.vsphere[vs_name].ds_mapping[vm.datastore]
tpl = ' datastore_id = data.vsphere_datastore.{}.id\n'
content += tpl.format(ds_tf_name)
# --------------------------------------------------------------------------
def _create_instfile_if(self, vm, iface, i, tpl_vm):
+ vs_name = vm.vsphere
+
# ## Interface definition
if self.verbose > 1:
LOG.debug(_("Generating interface definition {i} of {v!r}.").format(i=i, v=vm.name))
nw = iface.network
- nw_name = self.vsphere.network_mapping[nw]
+ nw_name = self.vsphere[vs_name].network_mapping[nw]
content = textwrap.indent(textwrap.dedent('''\
network_interface {{
for vm in self.existing_vms:
+ vs_name = vm.vsphere
print()
LOG.info(_("Importing VM {!r}.").format(vm['name']))
vm_obj = 'vsphere_virtual_machine.{}'.format(vm['tf_name'])
path = '/{dc}/{f}/{p}/{n}'.format(
- dc=self.vsphere.dc, f=self.vsphere.dc_obj.vm_folder,
+ dc=self.vsphere[vs_name].dc, f=self.vsphere[vs_name].dc_obj.vm_folder,
p=vm['path'], n=vm['name'])
cmd = [str(self.terraform_cmd), 'import', vm_obj, path]
result = self.run(