from .config import CrTplConfiguration
-__version__ = '0.3.3'
+__version__ = '0.4.1'
LOG = logging.getLogger(__name__)
# =============================================================================
-class TempVmExistsError(HandlerError):
+class ExpectedHandlerError(HandlerError):
+ """Base class for all errors, which could be expected in application object
+ and displayed without stack trace."""
+
+ pass
+
+# =============================================================================
+class TempVmExistsError(ExpectedHandlerError):
"""Special error class for the case, if the temporary VM is already existing."""
# -------------------------------------------------------------------------
# =============================================================================
-class NoDatastoreFoundError(HandlerError):
+class NoDatastoreFoundError(ExpectedHandlerError):
"""Special error class for the case, that no SAN based data store was with
enogh free space was found."""
# =============================================================================
-class NetworkNotExistingError(HandlerError):
+class NetworkNotExistingError(ExpectedHandlerError):
"""Special error class for the case, if the expected network is not existing."""
# -------------------------------------------------------------------------
# =============================================================================
-class CannotConnectError(HandlerError):
+class CannotConnectError(ExpectedHandlerError):
"""Special error class for the case, it cannot connect
to the given vSphere server."""
self.tpl_vm_folder = None
self.tpl_data_store = None
self.tpl_network = None
+ self.tpl_cluster = None
if initialized:
self.initialized = True
user=self.config.vsphere_user)
try:
+ self.get_cluster()
self.ensure_vm_folder()
self.check_for_temp_tpl_vm()
self.select_data_store()
def get_obj(self, content, vimtype, name):
obj = None
- container = content.viewManager.CreateContainerView(
- content.rootFolder, vimtype, True)
+ container = content.viewManager.CreateContainerView(content.rootFolder, vimtype, True)
for c in container.view:
if c.name == name:
obj = c
return obj
+ # -------------------------------------------------------------------------
+ def get_obj_list(self, content, vimtype):
+
+ result = []
+
+ container = content.viewManager.CreateContainerView(content.rootFolder, vimtype, True)
+ for c in container.view:
+ result.append(c)
+
+ return result
+
+ # -------------------------------------------------------------------------
+ def get_cluster(self, content=None):
+
+ if not content:
+ content = self.server_instance.RetrieveContent()
+
+ cluster_list = self.get_obj_list(content, [vim.ClusterComputeResource])
+ if not len(cluster_list):
+ raise HandlerError(
+ "Strange: did not found a cluster object in data center {!r}.".format(
+ self.config.dc))
+
+ self.tpl_cluster = cluster_list[0]
+ LOG.debug("Using cluster {!r}.".format(self.tpl_cluster.name))
+
# -------------------------------------------------------------------------
def _create_folder(self, host_folder, folder_name, ftype=None):