Completed
Pull Request — master (#429)
by Tomaz
03:32
created

SetNodeConfAction.run()   A

Complexity

Conditions 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 3
dl 0
loc 12
rs 9.4285
1
import requests
2
import yaml
3
4
from lib.base import OpscenterAction
5
6
7
class SetNodeConfAction(OpscenterAction):
8
9
    def run(self, node_ip, node_conf, cluster_id=None):
10
        if not cluster_id:
11
            cluster_id = self.cluster_id
12
13
        try:
14
            yaml.safe_load(node_conf)  # If this throws, fail the action.
15
        except:
16
            self.logger.error('Configuration is not valid YAML.')
17
            raise
18
        url = self._get_full_url([cluster_id, 'nodeconf', node_ip])
19
20
        return requests.post(url, data=node_conf).json()
21