Skip to content

Commit

Permalink
Merge pull request #73 from michaelw/mw/synctimewithhost
Browse files Browse the repository at this point in the history
Add command syncTimeWithHost
  • Loading branch information
snobear authored Sep 22, 2016
2 parents c87d4c1 + 86aa461 commit 1477676
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ezmomi/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ def cli():
ez.powerOff()
elif kwargs['mode'] == 'powerOn':
ez.powerOn()
elif kwargs['mode'] == 'syncTimeWithHost':
ez.syncTimeWithHost()
15 changes: 15 additions & 0 deletions ezmomi/ezmomi.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,21 @@ def powerOn(self):
result = self.WaitForTasks(tasks)
print "%s poweredOn" % vm.name

def syncTimeWithHost(self):
vm = self.get_vm_failfast(self.config['name'])
flag = self.config['value']

if vm.config.tools.syncTimeWithHost == flag:
print "%s syncTimeWithHost already %s" % (vm.name, str(flag))
else:
spec = vim.vm.ConfigSpec()
spec.tools = vim.vm.ToolsConfigInfo()
spec.tools.syncTimeWithHost = flag

task = vm.ReconfigVM_Task(spec)
result = self.WaitForTasks([task])
print "%s syncTimeWithHost %s" % (vm.name, str(flag))

'''
Helper methods
'''
Expand Down
21 changes: 21 additions & 0 deletions ezmomi/params.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
"""Command line option definitions"""


def add_boolean_argument(parser, name, default=False):
"""Add a boolean argument to an ArgumentParser instance."""
group = parser.add_mutually_exclusive_group()
group.add_argument('--set', action='store_true', dest=name,
default=default)
group.add_argument('--unset', action='store_false', dest=name,
default=default)


def arg_setup():
from .version import __version__
import argparse
Expand Down Expand Up @@ -295,4 +304,16 @@ def arg_setup():
help="VM name (case-sensitive)"
)

# syncTimeWithHost
syncTimeWithHost_parser = subparsers.add_parser(
"syncTimeWithHost",
parents=[common_parser],
help="Virtual Machine syncs time with host"
)
syncTimeWithHost_parser.add_argument(
"--name",
required=True,
help="VM name (case-sensitive)"
)
add_boolean_argument(syncTimeWithHost_parser, "value", default=True)
return main_parser.parse_args()

0 comments on commit 1477676

Please sign in to comment.