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

BaseAction._connect()   A

Complexity

Conditions 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 5
rs 9.4285
1
import atexit
2
import eventlet
3
4
from pyVim import connect
5
from pyVmomi import vim
6
from st2actions.runners.pythonrunner import Action
7
8
9
class BaseAction(Action):
10
    def __init__(self, config):
11
        super(BaseAction, self).__init__(config)
12
        self.si = self._connect()
13
        self.si_content = self.si.RetrieveContent()
14
15
    def _connect(self):
16
        si = connect.SmartConnect(host=self.config['host'], port=self.config['port'],
17
                                  user=self.config['user'], pwd=self.config['passwd'])
18
        atexit.register(connect.Disconnect, si)
19
        return si
20
21
    def _wait_for_task(self, task):
22
        while task.info.state == vim.TaskInfo.State.running:
23
            eventlet.sleep(1)
24
        return task.info.state == vim.TaskInfo.State.success
25