Completed
Pull Request — master (#460)
by Manas
02:32
created

WaitTask   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 13
Duplicated Lines 0 %
Metric Value
dl 0
loc 13
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 11 3
1
import eventlet
2
3
from pyVmomi import vim
4
5
from vmwarelib import inventory
6
from vmwarelib.actions import BaseAction
7
8
9
class WaitTask(BaseAction):
10
11
    def run(self, task_id):
12
        # convert ids to stubs
13
        task = inventory.get_task(self.si_content, moid=task_id)
14
        while task.info.state == vim.TaskInfo.State.running:
15
            eventlet.sleep(1)
16
        result, error = None, None
17
        if task.info.state == vim.TaskInfo.State.success:
18
            result = task.info.result
19
        else:
20
            error = task.info.error
21
        return {'result': result, 'error': error}
22