Completed
Pull Request — master (#487)
by
unknown
02:56
created

NcmExecuteScript   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 41
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 0 40 3
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
15
from lib.actions import OrionBaseAction
16
17
18
class NcmExecuteScript(OrionBaseAction):
19
    def run(self, platform, node, script):
20
        """
21
        Excute an Orion NCM script on a node.
22
23
        Args:
24
            platform
25
            node
26
            script
27
28
        Returns:
29
            Output
30
31
        Raises:
32
            ValueError: If Node is not in NCM.
33
        """
34
        results = {}
35
36
        self.connect(platform)
37
38
        orion_node = self.get_node(node)
39
40
        if not orion_node.npm:
41
            raise ValueError("Node not found in NPM {}".format(
42
                orion_node.caption))
43
44
        if not orion_node.ncm:
45
            raise ValueError("Node not found in NCM {}".format(
46
                orion_node.caption))
47
48
        orion_data = self.invoke(
49
            "Cirrus.ConfigArchive",
50
            "ExecuteScript",
51
            [orion_node.ncm_id],
52
            "show failover")
53
        results['job_id'] = orion_data[0]
54
55
        results['transfer'] = self.get_ncm_transfer_results(
56
            results['job_id'])
57
58
        return results
59