Skip to content

Commit

Permalink
Merge pull request #82 from murarisumit/master
Browse files Browse the repository at this point in the history
Added destination folder and datastore as command-line params.
  • Loading branch information
snobear authored Jul 10, 2017
2 parents 8a18126 + 59c9afb commit fe6b482
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 11 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,17 @@ 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`.

##### Power Operations

##### Clone a template and put vm is specific folder

```
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 in specified vcenter.


##### Power Operations

Guest shutdown

Expand Down
1 change: 0 additions & 1 deletion ezmomi/config/config.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
26 changes: 17 additions & 9 deletions ezmomi/ezmomi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -201,7 +200,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']
Expand Down Expand Up @@ -237,21 +241,25 @@ 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:
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(
Expand Down
29 changes: 29 additions & 0 deletions ezmomi/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -229,6 +241,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,
Expand Down

0 comments on commit fe6b482

Please sign in to comment.