Re: [Users] Unable to get latest resource status

2012-04-28 Thread Michael Pasternak

Hi Alex,

On 04/28/2012 06:19 AM, Alex Jia wrote:
 On 04/27/2012 11:30 PM, Juan Hernandez wrote:
 On 04/27/2012 05:27 PM, Alex Jia wrote:
 Although I haven't try it, I think you're right, I should refresh VM
 in loop body.
 Let me know what is the result in your environment.
 I have tried it and indeed works well for me.
 In addition, as I said, it will be convenient if we have wait_for_status
 function like before.
 I will look into it. I would greatly appreciate if you can open a bug to
 request and track it.

 It's okay for me, I want to know I need to file a fedora bug? which component?
 because I'm doing these on RHEL6.2.

it's not a bug, since we using RESTful api, you get resource representation
which is holding vm metadata relevant only for the given moment,

if you want to poll this vm for the status change, you'll have to retrieve
it on each iteration.

not relevant to vm execution, but we also have /sync execution mode/ (mostly
on storage related actions, see our user guide [1]), so you can block
action till it get accomplished on server side.

[1] 
http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Virtualization/3.0/html/REST_API_Guide/

-- 

Michael Pasternak
RedHat, ENG-Virtualization RD
___
Users mailing list
Users@ovirt.org
http://lists.ovirt.org/mailman/listinfo/users


Re: [Users] Unable to get latest resource status

2012-04-28 Thread Alex Jia
Hi Michael,
Thanks for your reply, yeah, it's not a bug, I mean whether we may support
wait_for_status function in ovirt-engine-sdk like python-rhev, as I said,
it will be more convenient for users. so it should be RFE.

In addition, I know this user guide, however, I think I need to see it carefully
again.


Thanks,
Alex


- Original Message -
From: Michael Pasternak mpast...@redhat.com
To: Alex Jia a...@redhat.com
Cc: Juan Hernandez juan.hernan...@redhat.com, users@ovirt.org, Rita Wu 
r...@redhat.com, Itamar Heim ih...@redhat.com
Sent: Saturday, April 28, 2012 7:21:59 PM
Subject: Re: [Users] Unable to get latest resource status


Hi Alex,

On 04/28/2012 06:19 AM, Alex Jia wrote:
 On 04/27/2012 11:30 PM, Juan Hernandez wrote:
 On 04/27/2012 05:27 PM, Alex Jia wrote:
 Although I haven't try it, I think you're right, I should refresh VM
 in loop body.
 Let me know what is the result in your environment.
 I have tried it and indeed works well for me.
 In addition, as I said, it will be convenient if we have wait_for_status
 function like before.
 I will look into it. I would greatly appreciate if you can open a bug to
 request and track it.

 It's okay for me, I want to know I need to file a fedora bug? which component?
 because I'm doing these on RHEL6.2.

it's not a bug, since we using RESTful api, you get resource representation
which is holding vm metadata relevant only for the given moment,

if you want to poll this vm for the status change, you'll have to retrieve
it on each iteration.

not relevant to vm execution, but we also have /sync execution mode/ (mostly
on storage related actions, see our user guide [1]), so you can block
action till it get accomplished on server side.

[1] 
http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Virtualization/3.0/html/REST_API_Guide/

-- 

Michael Pasternak
RedHat, ENG-Virtualization RD
___
Users mailing list
Users@ovirt.org
http://lists.ovirt.org/mailman/listinfo/users


Re: [Users] Unable to get latest resource status

2012-04-27 Thread Juan Hernandez
On 04/26/2012 05:49 PM, Alex Jia wrote:
 I built ovirt-engine-sdk rpm based on git repo 
 'http://gerrit.ovirt.org/p/ovirt-engine-sdk.git',
 then the ovirt-engine-sdk works well for me, I can get resource information 
 from Ovirt/RHEVM(3.0)
 on the rhel6.2.
 
 The only question is I can't get latest resource status when I changed VM 
 from 'suspended' to 'up'
 status, the api.vms.get(vm_name).status.state is always 'suspended' status, I 
 can get a correct
 VM status unless I reconnect Ovirt/RHEVM, it's not convenient for users, I 
 remember there are reload 
 and wait_for_status method in old python binding API of RHEV(python-rhev), 
 the wait_for_status method 
 will reload resource then get current resource status, however, I haven't 
 found similar method in 
 ovirt-engine-sdk.

Are you sure you are calling api.vms.get(vm_name) each time? Or are you
doing something like this:

vm = api.vms.get(vm_name)
while vm.status.state == suspended:
sleep(10)

If you are doing that the vm information is retrieved only once, not
each time. If this is the case try something like this:

while api.vms.get(VM_NAME).status.state == suspended:
sleep(1)

Can you share that snippet of code so that I can try to reproduce it?

-- 
Dirección Comercial: C/Jose Bardasano Baos, 9, Edif. Gorbea 3, planta
3ºD, 28016 Madrid, Spain
Inscrita en el Reg. Mercantil de Madrid – C.I.F. B82657941 - Red Hat S.L.
___
Users mailing list
Users@ovirt.org
http://lists.ovirt.org/mailman/listinfo/users


Re: [Users] Unable to get latest resource status

2012-04-27 Thread Juan Hernandez
On 04/26/2012 05:49 PM, Alex Jia wrote:
 I built ovirt-engine-sdk rpm based on git repo 
 'http://gerrit.ovirt.org/p/ovirt-engine-sdk.git',
 then the ovirt-engine-sdk works well for me, I can get resource information 
 from Ovirt/RHEVM(3.0)
 on the rhel6.2.
 
 The only question is I can't get latest resource status when I changed VM 
 from 'suspended' to 'up'
 status, the api.vms.get(vm_name).status.state is always 'suspended' status, I 
 can get a correct
 VM status unless I reconnect Ovirt/RHEVM, it's not convenient for users, I 
 remember there are reload 
 and wait_for_status method in old python binding API of RHEV(python-rhev), 
 the wait_for_status method 
 will reload resource then get current resource status, however, I haven't 
 found similar method in 
 ovirt-engine-sdk.

Are you sure you are calling api.vms.get(vm_name) each time? Or are you
doing something like this:

vm = api.vms.get(vm_name)
while vm.status.state == suspended:
sleep(10)

If you are doing that the vm information is retrieved only once, not
each time. If this is the case try something like this:

while api.vms.get(VM_NAME).status.state == suspended:
sleep(1)

Can you share that snippet of code so that I can try to reproduce it?
___
Users mailing list
Users@ovirt.org
http://lists.ovirt.org/mailman/listinfo/users


Re: [Users] Unable to get latest resource status

2012-04-27 Thread Alex Jia

On 04/27/2012 04:06 PM, Juan Hernandez wrote:

On 04/26/2012 05:49 PM, Alex Jia wrote:

I built ovirt-engine-sdk rpm based on git repo 
'http://gerrit.ovirt.org/p/ovirt-engine-sdk.git',
then the ovirt-engine-sdk works well for me, I can get resource information 
from Ovirt/RHEVM(3.0)
on the rhel6.2.

The only question is I can't get latest resource status when I changed VM from 
'suspended' to 'up'
status, the api.vms.get(vm_name).status.state is always 'suspended' status, I 
can get a correct
VM status unless I reconnect Ovirt/RHEVM, it's not convenient for users, I 
remember there are reload
and wait_for_status method in old python binding API of RHEV(python-rhev), the 
wait_for_status method
will reload resource then get current resource status, however, I haven't found 
similar method in
ovirt-engine-sdk.

Are you sure you are calling api.vms.get(vm_name) each time? Or are you
doing something like this:

vm = api.vms.get(vm_name)
while vm.status.state == suspended:
 sleep(10)

Yeah, I put 'api.vms.get(vm_name)' in a loop body like above codes.

If you are doing that the vm information is retrieved only once, not
each time. If this is the case try something like this:

while api.vms.get(VM_NAME).status.state == suspended:
 sleep(1)

Can you share that snippet of code so that I can try to reproduce it?
Okay, I will list my snippet of code in here, you may replace 'logging' 
with 'print' then remove

useless '()' if need. thanks.


snip
import time, logging
from ovirtsdk.api import API
from ovirtsdk.xml import params

class RHEV(object):

RHEV class


def __init__(self, url, username, password):
try:
self.api = API(url, username, password)
except Exception as e:
logging.error('could not connect: %s\n' % str(e))
else:
logging.info('success: RHEV manager could be reached OK\n')

def vm_start(self, vm_name):
try:
vm = self.api.vms.get(vm_name)
if vm.status.state != 'up':
logging.info('Starting VM')
vm.start()
logging.info('Waiting for VM to reach Up status')
while vm.status.state != 'up':
time.sleep(1)
else:
logging.debug('VM already up')
except Exception as e:
logging.error('Failed to start VM:\n%s' % str(e))

def vm_suspend(self, vm_name):
vm = self.api.vms.get(vm_name)
while vm.status.state != 'suspended':
try:
logging.info('Suspend VM')
vm.suspend()
logging.info('Waiting for VM to reach suspended status')
while vm.status.state != 'suspended':
time.sleep(1)

except Exception as e:
if e.reason == 'Bad Request' \
and 'asynchronous running tasks' in e.detail:
logging.warning('VM has asynchronous running tasks, 
trying again')

time.sleep(1)
else:
logging.error('Failed to suspend VM:\n%s' % str(e))
break

def vm_resume(self, vm_name):
try:
vm = self.api.vms.get(vm_name)
if vm.status.state != 'up':
logging.info('Resume VM')
vm.start()
logging.info('Waiting for VM to resume')
while vm.status.state != 'up':
time.sleep(1)
else:
logging.debug('VM already up')
except Exception as e:
logging.error('Failed to resume VM:\n%s' % str(e))

/snip

___
Users mailing list
Users@ovirt.org
http://lists.ovirt.org/mailman/listinfo/users


Re: [Users] Unable to get latest resource status

2012-04-27 Thread Juan Hernandez
On 04/27/2012 12:06 PM, Alex Jia wrote:
 On 04/27/2012 04:06 PM, Juan Hernandez wrote:
 On 04/26/2012 05:49 PM, Alex Jia wrote:
 I built ovirt-engine-sdk rpm based on git repo 
 'http://gerrit.ovirt.org/p/ovirt-engine-sdk.git',
 then the ovirt-engine-sdk works well for me, I can get resource information 
 from Ovirt/RHEVM(3.0)
 on the rhel6.2.

 The only question is I can't get latest resource status when I changed VM 
 from 'suspended' to 'up'
 status, the api.vms.get(vm_name).status.state is always 'suspended' status, 
 I can get a correct
 VM status unless I reconnect Ovirt/RHEVM, it's not convenient for users, I 
 remember there are reload
 and wait_for_status method in old python binding API of RHEV(python-rhev), 
 the wait_for_status method
 will reload resource then get current resource status, however, I haven't 
 found similar method in
 ovirt-engine-sdk.
 Are you sure you are calling api.vms.get(vm_name) each time? Or are you
 doing something like this:

 vm = api.vms.get(vm_name)
 while vm.status.state == suspended:
  sleep(10)
 Yeah, I put 'api.vms.get(vm_name)' in a loop body like above codes.
 If you are doing that the vm information is retrieved only once, not
 each time. If this is the case try something like this:

 while api.vms.get(VM_NAME).status.state == suspended:
  sleep(1)

 Can you share that snippet of code so that I can try to reproduce it?
 Okay, I will list my snippet of code in here, you may replace 'logging' 
 with 'print' then remove
 useless '()' if need. thanks.
 
 
 snip
 import time, logging
 from ovirtsdk.api import API
 from ovirtsdk.xml import params
 
 class RHEV(object):
  
  RHEV class
  
 
  def __init__(self, url, username, password):
  try:
  self.api = API(url, username, password)
  except Exception as e:
  logging.error('could not connect: %s\n' % str(e))
  else:
  logging.info('success: RHEV manager could be reached OK\n')
 
  def vm_start(self, vm_name):
  try:
  vm = self.api.vms.get(vm_name)
  if vm.status.state != 'up':
  logging.info('Starting VM')
  vm.start()
  logging.info('Waiting for VM to reach Up status')
  while vm.status.state != 'up':

I think that the problem is with the line above. The VM object that you
get with self.api.vms.get(vm_name) is not automatically refreshed, you
have to refresh it before each iteration calling the api.vms.get(...)
method again:

  while api.vms.get(vm_name).status.state != 'up':

Can you try that?

  time.sleep(1)
  else:
  logging.debug('VM already up')
  except Exception as e:
  logging.error('Failed to start VM:\n%s' % str(e))
 
  def vm_suspend(self, vm_name):
  vm = self.api.vms.get(vm_name)
  while vm.status.state != 'suspended':
  try:
  logging.info('Suspend VM')
  vm.suspend()
  logging.info('Waiting for VM to reach suspended status')
  while vm.status.state != 'suspended':

Same here ^.

  time.sleep(1)
 
  except Exception as e:
  if e.reason == 'Bad Request' \
  and 'asynchronous running tasks' in e.detail:
  logging.warning('VM has asynchronous running tasks, 
 trying again')
  time.sleep(1)
  else:
  logging.error('Failed to suspend VM:\n%s' % str(e))
  break
 
  def vm_resume(self, vm_name):
  try:
  vm = self.api.vms.get(vm_name)
  if vm.status.state != 'up':
  logging.info('Resume VM')
  vm.start()
  logging.info('Waiting for VM to resume')
  while vm.status.state != 'up':

Same here ^.

  time.sleep(1)
  else:
  logging.debug('VM already up')
  except Exception as e:
  logging.error('Failed to resume VM:\n%s' % str(e))
 
 /snip
 

___
Users mailing list
Users@ovirt.org
http://lists.ovirt.org/mailman/listinfo/users


Re: [Users] Unable to get latest resource status

2012-04-27 Thread Alex Jia
Hi Juan,
Although I haven't try it, I think you're right, I should refresh VM
in loop body. 

In addition, as I said, it will be convenient if we have wait_for_status 
function like before.

Thanks,
Alex 


- Original Message -
From: Juan Hernandez juan.hernan...@redhat.com
To: Alex Jia a...@redhat.com
Cc: users@ovirt.org, Rita Wu r...@redhat.com
Sent: Friday, April 27, 2012 8:17:05 PM
Subject: Re: [Users] Unable to get latest resource status

On 04/27/2012 12:06 PM, Alex Jia wrote:
 On 04/27/2012 04:06 PM, Juan Hernandez wrote:
 On 04/26/2012 05:49 PM, Alex Jia wrote:
 I built ovirt-engine-sdk rpm based on git repo 
 'http://gerrit.ovirt.org/p/ovirt-engine-sdk.git',
 then the ovirt-engine-sdk works well for me, I can get resource information 
 from Ovirt/RHEVM(3.0)
 on the rhel6.2.

 The only question is I can't get latest resource status when I changed VM 
 from 'suspended' to 'up'
 status, the api.vms.get(vm_name).status.state is always 'suspended' status, 
 I can get a correct
 VM status unless I reconnect Ovirt/RHEVM, it's not convenient for users, I 
 remember there are reload
 and wait_for_status method in old python binding API of RHEV(python-rhev), 
 the wait_for_status method
 will reload resource then get current resource status, however, I haven't 
 found similar method in
 ovirt-engine-sdk.
 Are you sure you are calling api.vms.get(vm_name) each time? Or are you
 doing something like this:

 vm = api.vms.get(vm_name)
 while vm.status.state == suspended:
  sleep(10)
 Yeah, I put 'api.vms.get(vm_name)' in a loop body like above codes.
 If you are doing that the vm information is retrieved only once, not
 each time. If this is the case try something like this:

 while api.vms.get(VM_NAME).status.state == suspended:
  sleep(1)

 Can you share that snippet of code so that I can try to reproduce it?
 Okay, I will list my snippet of code in here, you may replace 'logging' 
 with 'print' then remove
 useless '()' if need. thanks.
 
 
 snip
 import time, logging
 from ovirtsdk.api import API
 from ovirtsdk.xml import params
 
 class RHEV(object):
  
  RHEV class
  
 
  def __init__(self, url, username, password):
  try:
  self.api = API(url, username, password)
  except Exception as e:
  logging.error('could not connect: %s\n' % str(e))
  else:
  logging.info('success: RHEV manager could be reached OK\n')
 
  def vm_start(self, vm_name):
  try:
  vm = self.api.vms.get(vm_name)
  if vm.status.state != 'up':
  logging.info('Starting VM')
  vm.start()
  logging.info('Waiting for VM to reach Up status')
  while vm.status.state != 'up':

I think that the problem is with the line above. The VM object that you
get with self.api.vms.get(vm_name) is not automatically refreshed, you
have to refresh it before each iteration calling the api.vms.get(...)
method again:

  while api.vms.get(vm_name).status.state != 'up':

Can you try that?

  time.sleep(1)
  else:
  logging.debug('VM already up')
  except Exception as e:
  logging.error('Failed to start VM:\n%s' % str(e))
 
  def vm_suspend(self, vm_name):
  vm = self.api.vms.get(vm_name)
  while vm.status.state != 'suspended':
  try:
  logging.info('Suspend VM')
  vm.suspend()
  logging.info('Waiting for VM to reach suspended status')
  while vm.status.state != 'suspended':

Same here ^.

  time.sleep(1)
 
  except Exception as e:
  if e.reason == 'Bad Request' \
  and 'asynchronous running tasks' in e.detail:
  logging.warning('VM has asynchronous running tasks, 
 trying again')
  time.sleep(1)
  else:
  logging.error('Failed to suspend VM:\n%s' % str(e))
  break
 
  def vm_resume(self, vm_name):
  try:
  vm = self.api.vms.get(vm_name)
  if vm.status.state != 'up':
  logging.info('Resume VM')
  vm.start()
  logging.info('Waiting for VM to resume')
  while vm.status.state != 'up':

Same here ^.

  time.sleep(1)
  else:
  logging.debug('VM already up')
  except Exception as e:
  logging.error('Failed to resume VM:\n%s' % str(e))
 
 /snip
 

___
Users mailing list
Users@ovirt.org
http://lists.ovirt.org/mailman/listinfo/users


Re: [Users] Unable to get latest resource status

2012-04-27 Thread Juan Hernandez
On 04/27/2012 05:27 PM, Alex Jia wrote:
 Although I haven't try it, I think you're right, I should refresh VM
 in loop body.

Let me know what is the result in your environment.

 In addition, as I said, it will be convenient if we have wait_for_status 
 function like before.

I will look into it. I would greatly appreciate if you can open a bug to
request and track it.

 - Original Message -
 From: Juan Hernandez juan.hernan...@redhat.com
 To: Alex Jia a...@redhat.com
 Cc: users@ovirt.org, Rita Wu r...@redhat.com
 Sent: Friday, April 27, 2012 8:17:05 PM
 Subject: Re: [Users] Unable to get latest resource status
 
 On 04/27/2012 12:06 PM, Alex Jia wrote:
 On 04/27/2012 04:06 PM, Juan Hernandez wrote:
 On 04/26/2012 05:49 PM, Alex Jia wrote:
 I built ovirt-engine-sdk rpm based on git repo 
 'http://gerrit.ovirt.org/p/ovirt-engine-sdk.git',
 then the ovirt-engine-sdk works well for me, I can get resource 
 information from Ovirt/RHEVM(3.0)
 on the rhel6.2.

 The only question is I can't get latest resource status when I changed VM 
 from 'suspended' to 'up'
 status, the api.vms.get(vm_name).status.state is always 'suspended' 
 status, I can get a correct
 VM status unless I reconnect Ovirt/RHEVM, it's not convenient for users, I 
 remember there are reload
 and wait_for_status method in old python binding API of RHEV(python-rhev), 
 the wait_for_status method
 will reload resource then get current resource status, however, I haven't 
 found similar method in
 ovirt-engine-sdk.
 Are you sure you are calling api.vms.get(vm_name) each time? Or are you
 doing something like this:

 vm = api.vms.get(vm_name)
 while vm.status.state == suspended:
  sleep(10)
 Yeah, I put 'api.vms.get(vm_name)' in a loop body like above codes.
 If you are doing that the vm information is retrieved only once, not
 each time. If this is the case try something like this:

 while api.vms.get(VM_NAME).status.state == suspended:
  sleep(1)

 Can you share that snippet of code so that I can try to reproduce it?
 Okay, I will list my snippet of code in here, you may replace 'logging' 
 with 'print' then remove
 useless '()' if need. thanks.


 snip
 import time, logging
 from ovirtsdk.api import API
 from ovirtsdk.xml import params

 class RHEV(object):
  
  RHEV class
  

  def __init__(self, url, username, password):
  try:
  self.api = API(url, username, password)
  except Exception as e:
  logging.error('could not connect: %s\n' % str(e))
  else:
  logging.info('success: RHEV manager could be reached OK\n')

  def vm_start(self, vm_name):
  try:
  vm = self.api.vms.get(vm_name)
  if vm.status.state != 'up':
  logging.info('Starting VM')
  vm.start()
  logging.info('Waiting for VM to reach Up status')
  while vm.status.state != 'up':
 
 I think that the problem is with the line above. The VM object that you
 get with self.api.vms.get(vm_name) is not automatically refreshed, you
 have to refresh it before each iteration calling the api.vms.get(...)
 method again:
 
   while api.vms.get(vm_name).status.state != 'up':
 
 Can you try that?
 
  time.sleep(1)
  else:
  logging.debug('VM already up')
  except Exception as e:
  logging.error('Failed to start VM:\n%s' % str(e))

  def vm_suspend(self, vm_name):
  vm = self.api.vms.get(vm_name)
  while vm.status.state != 'suspended':
  try:
  logging.info('Suspend VM')
  vm.suspend()
  logging.info('Waiting for VM to reach suspended status')
  while vm.status.state != 'suspended':
 
 Same here ^.
 
  time.sleep(1)

  except Exception as e:
  if e.reason == 'Bad Request' \
  and 'asynchronous running tasks' in e.detail:
  logging.warning('VM has asynchronous running tasks, 
 trying again')
  time.sleep(1)
  else:
  logging.error('Failed to suspend VM:\n%s' % str(e))
  break

  def vm_resume(self, vm_name):
  try:
  vm = self.api.vms.get(vm_name)
  if vm.status.state != 'up':
  logging.info('Resume VM')
  vm.start()
  logging.info('Waiting for VM to resume')
  while vm.status.state != 'up':
 
 Same here ^.
 
  time.sleep(1)
  else:
  logging.debug('VM already up')
  except Exception as e:
  logging.error('Failed to resume VM:\n%s' % str(e))

 /snip

 

___
Users mailing list
Users@ovirt.org
http://lists.ovirt.org/mailman/listinfo/users


Re: [Users] Unable to get latest resource status

2012-04-27 Thread Alex Jia

On 04/27/2012 11:30 PM, Juan Hernandez wrote:

On 04/27/2012 05:27 PM, Alex Jia wrote:

Although I haven't try it, I think you're right, I should refresh VM
in loop body.

Let me know what is the result in your environment.

I have tried it and indeed works well for me.

In addition, as I said, it will be convenient if we have wait_for_status
function like before.

I will look into it. I would greatly appreciate if you can open a bug to
request and track it.

It's okay for me, I want to know I need to file a fedora bug? which 
component?

because I'm doing these on RHEL6.2.

- Original Message -
From: Juan Hernandezjuan.hernan...@redhat.com
To: Alex Jiaa...@redhat.com
Cc: users@ovirt.org, Rita Wur...@redhat.com
Sent: Friday, April 27, 2012 8:17:05 PM
Subject: Re: [Users] Unable to get latest resource status

On 04/27/2012 12:06 PM, Alex Jia wrote:

On 04/27/2012 04:06 PM, Juan Hernandez wrote:

On 04/26/2012 05:49 PM, Alex Jia wrote:

I built ovirt-engine-sdk rpm based on git repo 
'http://gerrit.ovirt.org/p/ovirt-engine-sdk.git',
then the ovirt-engine-sdk works well for me, I can get resource information 
from Ovirt/RHEVM(3.0)
on the rhel6.2.

The only question is I can't get latest resource status when I changed VM from 
'suspended' to 'up'
status, the api.vms.get(vm_name).status.state is always 'suspended' status, I 
can get a correct
VM status unless I reconnect Ovirt/RHEVM, it's not convenient for users, I 
remember there are reload
and wait_for_status method in old python binding API of RHEV(python-rhev), the 
wait_for_status method
will reload resource then get current resource status, however, I haven't found 
similar method in
ovirt-engine-sdk.

Are you sure you are calling api.vms.get(vm_name) each time? Or are you
doing something like this:

vm = api.vms.get(vm_name)
while vm.status.state == suspended:
  sleep(10)

Yeah, I put 'api.vms.get(vm_name)' in a loop body like above codes.

If you are doing that the vm information is retrieved only once, not
each time. If this is the case try something like this:

while api.vms.get(VM_NAME).status.state == suspended:
  sleep(1)

Can you share that snippet of code so that I can try to reproduce it?

Okay, I will list my snippet of code in here, you may replace 'logging'
with 'print' then remove
useless '()' if need. thanks.


snip
import time, logging
from ovirtsdk.api import API
from ovirtsdk.xml import params

class RHEV(object):
  
  RHEV class
  

  def __init__(self, url, username, password):
  try:
  self.api = API(url, username, password)
  except Exception as e:
  logging.error('could not connect: %s\n' % str(e))
  else:
  logging.info('success: RHEV manager could be reached OK\n')

  def vm_start(self, vm_name):
  try:
  vm = self.api.vms.get(vm_name)
  if vm.status.state != 'up':
  logging.info('Starting VM')
  vm.start()
  logging.info('Waiting for VM to reach Up status')
  while vm.status.state != 'up':

I think that the problem is with the line above. The VM object that you
get with self.api.vms.get(vm_name) is not automatically refreshed, you
have to refresh it before each iteration calling the api.vms.get(...)
method again:

   while api.vms.get(vm_name).status.state != 'up':

Can you try that?


  time.sleep(1)
  else:
  logging.debug('VM already up')
  except Exception as e:
  logging.error('Failed to start VM:\n%s' % str(e))

  def vm_suspend(self, vm_name):
  vm = self.api.vms.get(vm_name)
  while vm.status.state != 'suspended':
  try:
  logging.info('Suspend VM')
  vm.suspend()
  logging.info('Waiting for VM to reach suspended status')
  while vm.status.state != 'suspended':

Same here ^.


  time.sleep(1)

  except Exception as e:
  if e.reason == 'Bad Request' \
  and 'asynchronous running tasks' in e.detail:
  logging.warning('VM has asynchronous running tasks,
trying again')
  time.sleep(1)
  else:
  logging.error('Failed to suspend VM:\n%s' % str(e))
  break

  def vm_resume(self, vm_name):
  try:
  vm = self.api.vms.get(vm_name)
  if vm.status.state != 'up':
  logging.info('Resume VM')
  vm.start()
  logging.info('Waiting for VM to resume')
  while vm.status.state != 'up':

Same here ^.


  time.sleep(1)
  else:
  logging.debug('VM already up')
  except Exception as e:
  logging.error('Failed to resume VM:\n%s' % str(e))

/snip