Skip to content

Commit

Permalink
put in organized way
Browse files Browse the repository at this point in the history
Signed-off-by: Nikhil Dhandre <ndhandre@redhat.com>
  • Loading branch information
digitronik committed Mar 25, 2019
1 parent 126f24b commit bb827f0
Showing 1 changed file with 50 additions and 50 deletions.
100 changes: 50 additions & 50 deletions wrapanapi/systems/virtualcenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,56 @@ def creation_time(self):
# localize and make tz-naive
return creation_time.astimezone(pytz.UTC)

@property
def cpu_hot_plug(self):
return self.raw.config.cpuHotAddEnabled

@property
def memory_hot_plug(self):
return self.raw.config.memoryHotAddEnabled

@cpu_hot_plug.setter
def cpu_hot_plug(self, value):
"""
Set cpuHotPlug (enabled/disabled) for VM/Instance.
Args:
value (bool): cpu hot plug state
"""
if self.cpu_hot_plug != value:
if self.is_stopped:
spec = vim.vm.ConfigSpec()
spec.cpuHotAddEnabled = value
task = self.raw.ReconfigVM_Task(spec)

try:
wait_for(lambda: task.info.state not in ["running", "queued"])
except TimedOutError:
self.logger.exception("Task did not go to success state: %s", task)
else:
raise VMInstanceNotStopped(self.name, "cpuHotPlug")

@memory_hot_plug.setter
def memory_hot_plug(self, value):
"""
Set memoryHotPlug (enabled/disabled) for VM/Instance
Args:
value (bool): memory hot plug state
"""
if self.memory_hot_plug != value:
if self.is_stopped:
spec = vim.vm.ConfigSpec()
spec.memoryHotAddEnabled = value
task = self.raw.ReconfigVM_Task(spec)

try:
wait_for(lambda: task.info.state not in ["running", "queued"])
except TimedOutError:
self.logger.exception("Task did not go to success state: %s", task)
else:
raise VMInstanceNotStopped(self.name, "memoryHotPlug")

def start(self):
if self.is_running:
self.logger.info(" vSphere VM %s is already running", self.name)
Expand Down Expand Up @@ -544,56 +594,6 @@ def clone(self, vm_name, **kwargs):
self.ensure_state(VmState.STOPPED)
return self._clone(**kwargs)

@property
def cpu_hot_plug(self):
return self.raw.config.cpuHotAddEnabled

@cpu_hot_plug.setter
def cpu_hot_plug(self, value):
"""
Set cpuHotPlug (enabled/disabled) for VM/Instance.
Args:
value (bool): cpu hot plug state
"""
if self.cpu_hot_plug != value:
if self.is_stopped:
spec = vim.vm.ConfigSpec()
spec.cpuHotAddEnabled = value
task = self.raw.ReconfigVM_Task(spec)

try:
wait_for(lambda: task.info.state not in ["running", "queued"])
except TimedOutError:
self.logger.exception("Task did not go to success state: %s", task)
else:
raise VMInstanceNotStopped(self.name, "cpuHotPlug")

@property
def memory_hot_plug(self):
return self.raw.config.memoryHotAddEnabled

@memory_hot_plug.setter
def memory_hot_plug(self, value):
"""
Set memoryHotPlug (enabled/disabled) for VM/Instance
Args:
value (bool): memory hot plug state
"""
if self.memory_hot_plug != value:
if self.is_stopped:
spec = vim.vm.ConfigSpec()
spec.memoryHotAddEnabled = value
task = self.raw.ReconfigVM_Task(spec)

try:
wait_for(lambda: task.info.state not in ["running", "queued"])
except TimedOutError:
self.logger.exception("Task did not go to success state: %s", task)
else:
raise VMInstanceNotStopped(self.name, "memoryHotPlug")


class VMWareTemplate(VMWareVMOrTemplate, Template):
def refresh(self):
Expand Down

0 comments on commit bb827f0

Please sign in to comment.