Completed
Pull Request — master (#515)
by
unknown
02:55
created

NodesPollNow   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 41
rs 10
c 2
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 0 40 6
1
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
2
# contributor license agreements.  See the NOTICE file distributed with
3
# this work for additional information regarding copyright ownership.
4
# The ASF licenses this file to You under the Apache License, Version 2.0
5
# (the "License"); you may not use this file except in compliance with
6
# the License.  You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15
16
import time
17
18
from lib.actions import OrionBaseAction
19
from lib.utils import send_user_error
20
21
22
class NodesPollNow(OrionBaseAction):
23
    def run(self, nodes, platform, count, pause):
24
        """
25
        Invoke a PollNow verb against a Orion Node.
26
27
        Args:
28
        - node: The caption in Orion of the node to poll.
29
        - platform: The orion platform to act on.
30
        - count: Number of polls to complete.
31
        - pause: Number of seconds to wait between each cycle.
32
33
        Returns
34
            True: As PollNow does not return any data.
35
36
        Raises:
37
            IndexError: When a nodes is not found.
38
        """
39
40
        self.connect(platform)
41
        orion_nodes = []
42
43
        for node in nodes:
44
            orion_node = self.get_node(node)
45
46
            if orion_node.npm:
47
                orion_nodes.append(orion_node.npm_id)
48
            else:
49
                error_msg = "Node not found"
50
                send_user_error(error_msg)
51
                raise ValueError(error_msg)
52
53
        for c in range(count):
54
            for npm_id in orion_nodes:
55
                self.invoke("Orion.Nods",
56
                            "PollNow",
57
                            npm_id)
58
            else:
59
                time.sleep(pause)
60
61
        # These Invoke's return None, so we just return True
62
        return True
63