argos83 / pysphere

Automatically exported from code.google.com/p/pysphere
88 stars 76 forks source link

start_command runs asynchronously #31

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

While running a long running command, the API call will return before
completing.   This causes race conditions and there is no option
to run synchronously or get_state.

What version of the product are you using? On what operating system?
1.7, RedHat 6

Original issue reported on code.google.com by ctg...@gmail.com on 14 Mar 2013 at 8:40

GoogleCodeExporter commented 9 years ago
There's no start_command method in pysphere. I guess you mean "start_process".

VMWare vSphere SDK does not provide sync methods for executing processes in the 
guest system. You'll have to implement the logic on your side. I.e. Is a 
vSpshere SDK's limitation, not pysphere's

start_command returns the pid of the process started, which you can look in the 
list returned by list_processes. If you wish to kill the process you can call 
terminate_process.

You might try doing something like:

def start_process_sync(path, args, ...):
  pid = vm.start_process(path, args...)
  if not pid:
    raise Exception("process not started")
  while 1:
    myproc = [p for p in vm.list_processses() if p['pid'] == pid]
    if not myproc or myproc[0]['exit_code'] != None:
       return
    time.sleep(1)

Original comment by argo...@gmail.com on 14 Mar 2013 at 12:52

GoogleCodeExporter commented 9 years ago
Thank you.  I should have researched further.  A long day and late night
equates to bad judgement.

Original comment by ctg...@gmail.com on 14 Mar 2013 at 5:11