From 1ff9660860e7284eaccfee4129aee8d83216700c Mon Sep 17 00:00:00 2001 From: Sumit Murari Date: Thu, 29 Jun 2017 16:39:19 +0530 Subject: [PATCH 1/3] Added destination folder and datastore as command-line params while cloning the template. These two params are optional the datastore will take default values from config file if not explicitly given. --- README.md | 2 +- ezmomi/ezmomi.py | 21 +++++++++++++++------ ezmomi/params.py | 17 +++++++++++++++++ 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 732c1ba..132601c 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ pip install ezmomi ##### Clone a template with two static IPs: ``` -ezmomi clone --template centos67 --hostname test01 --cpus 2 --mem 4 --ips 172.10.16.203 172.10.16.204 +ezmomi clone --template centos67 --hostname test01 --cpus 2 --mem 4 --destination-folder "/DC/folder/" --ips 172.10.16.203 172.10.16.204 ``` `ips` takes any number of ips. See `ezmomi clone --help` for a list of params. diff --git a/ezmomi/ezmomi.py b/ezmomi/ezmomi.py index 8554207..26ef783 100644 --- a/ezmomi/ezmomi.py +++ b/ezmomi/ezmomi.py @@ -201,7 +201,12 @@ def clone(self): ) # get the folder where VMs are kept for this datacenter - destfolder = datacenter.vmFolder + if self.config['destination_folder']: + destfolder = self.content.searchIndex.FindByInventoryPath( + self.config['destination_folder'] + ) + else: + destfolder = datacenter.vmFolder cluster = self.get_obj([vim.ClusterComputeResource], ip_settings[0]['cluster'] @@ -237,14 +242,18 @@ def clone(self): resource_pool = cluster.resourcePool datastore = None - if 'datastore' in ip_settings[0]: + + if self.config['datastore']: + datastore = self.get_obj( + [vim.Datastore], self.config['datastore']) + elif 'datastore' in ip_settings[0]: datastore = self.get_obj( [vim.Datastore], ip_settings[0]['datastore']) - if datastore is None: - print "Error: Unable to find Datastore '%s'" \ - % ip_settings[0]['datastore'] - sys.exit(1) + if datastore is None: + print "Error: Unable to find Datastore '%s'" \ + % ip_settings[0]['datastore'] + sys.exit(1) if template_path: template_vm = self.get_vm_failfast( diff --git a/ezmomi/params.py b/ezmomi/params.py index 0b048f9..86e7b04 100644 --- a/ezmomi/params.py +++ b/ezmomi/params.py @@ -229,6 +229,23 @@ def arg_setup(): default="Resources", help="Resource Pool, e.g. 'Linux Servers'" ) + + clone_parser.add_argument( + "--destination-folder", + required=False, + default='', + type=str, + help="Name of the destination folder" + ) + + clone_parser.add_argument( + "--datastore", + required=False, + default='', + type=str, + help="Name of the datastore" + ) + clone_parser.add_argument( "--post-clone-cmd", type=str, From f27ca42f75d5b5cf5a190e0bbdbe53c0a808dcde Mon Sep 17 00:00:00 2001 From: Sumit Murari Date: Thu, 29 Jun 2017 19:49:54 +0530 Subject: [PATCH 2/3] Updated readme as per suggestion --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6e99fdc..b2c3e70 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ pip install ezmomi ##### Clone a template with two static IPs: ``` -ezmomi clone --template centos67 --hostname test01 --cpus 2 --mem 4 --destination-folder "/DC/folder/" --ips 172.10.16.203 172.10.16.204 +ezmomi clone --template centos67 --hostname test01 --cpus 2 --mem 4 --ips 172.10.16.203 172.10.16.204 ``` `ips` takes any number of ips. See `ezmomi clone --help` for a list of params. @@ -40,6 +40,16 @@ ezmomi clone --template centos6 --hostname test01 --cpus 2 --mem 4 --ips 172.10. This example would run /usr/local/bin/additional-provisioning-steps.sh on the same host ezmomi is run on. You can reference the `EZMOMI_CLONE_HOSTNAME` environment variable in your script to retrieve the `--hostname`. + +##### Clone a template and put vm is specific folder + +``` +ezmomi clone --template centos67 --hostname test01 --cpus 2 --mem 4 --destination-folder "/DC/folder/" --ips 172.10.16.203 172.10.16.204 +``` + +This ^ example will put the cloned vm to specific destination folder + + ##### Power Operations Guest shutdown From 59c9afb9de79673140f00d93b9213a739cf36ef3 Mon Sep 17 00:00:00 2001 From: Sumit Murari Date: Wed, 5 Jul 2017 11:50:36 +0530 Subject: [PATCH 3/3] Added setting to add vcenter url as param and fixed a bug created due to default_template_path in config --- README.md | 6 +++--- ezmomi/config/config.yml.example | 1 - ezmomi/ezmomi.py | 5 ++--- ezmomi/params.py | 12 ++++++++++++ 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index b2c3e70..a2eabaa 100644 --- a/README.md +++ b/README.md @@ -44,13 +44,13 @@ This example would run /usr/local/bin/additional-provisioning-steps.sh on the sa ##### Clone a template and put vm is specific folder ``` -ezmomi clone --template centos67 --hostname test01 --cpus 2 --mem 4 --destination-folder "/DC/folder/" --ips 172.10.16.203 172.10.16.204 +ezmomi clone --server vcenter_url --template centos67 --hostname test01 --cpus 2 --mem 4 --destination-folder "/DC/folder/" --ips 172.10.16.203 172.10.16.204 ``` -This ^ example will put the cloned vm to specific destination folder +This example will put the cloned vm to specific destination folder in specified vcenter. -##### Power Operations +##### Power Operations Guest shutdown diff --git a/ezmomi/config/config.yml.example b/ezmomi/config/config.yml.example index 93c0b6b..e7cdef7 100644 --- a/ezmomi/config/config.yml.example +++ b/ezmomi/config/config.yml.example @@ -17,7 +17,6 @@ password: "mypass#123" cpus: 1 mem: 3 -default_templates_path: "Specific_folder_for_the_template_This_is_option_like_/DC/folder1/folder2" #Optional template: centos65 domain: example diff --git a/ezmomi/ezmomi.py b/ezmomi/ezmomi.py index 26ef783..af17ae6 100644 --- a/ezmomi/ezmomi.py +++ b/ezmomi/ezmomi.py @@ -162,7 +162,6 @@ def clone(self): self.config['hostname'] = self.config['hostname'].lower() self.config['mem'] = int(self.config['mem'] * 1024) # convert GB to MB - template_path = self.config['default_templates_path'] print "Cloning %s to new host %s with %sMB RAM..." % ( self.config['template'], self.config['hostname'], @@ -255,12 +254,12 @@ def clone(self): % ip_settings[0]['datastore'] sys.exit(1) - if template_path: + if self.config['template_folder']: template_vm = self.get_vm_failfast( self.config['template'], False, 'Template VM', - path=template_path + path=self.config['template_folder'] ) else: template_vm = self.get_vm_failfast( diff --git a/ezmomi/params.py b/ezmomi/params.py index 86e7b04..02ec0a9 100644 --- a/ezmomi/params.py +++ b/ezmomi/params.py @@ -46,6 +46,12 @@ def arg_setup(): help="Set this flag to disable ssl verification" ) + common_parser.add_argument( + "--server", + required=False, + help="vsphere server to connect to." + ) + # list list_parser = subparsers.add_parser( "list", @@ -178,6 +184,12 @@ def arg_setup(): type=str, help="VM template name to clone from" ) + clone_parser.add_argument( + "--template-folder", + type=str, + default="", + help="Folder to pull templates from" + ) clone_parser.add_argument( "--host", required=False,