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

GetDiscoveryProgress._disc_status_to_text()   A

Complexity

Conditions 1

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 21
rs 9.3142
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 xml.etree.ElementTree as ET
17
18
from lib.actions import OrionBaseAction
19
20
21
class GetDiscoveryProgress(OrionBaseAction):
22
    def _disc_status_to_text(self, status):
23
        """
24
        Convert a Discovery Status code into meaningful text.
25
26
        Args:
27
            status: Staus code from Orion.
28
29
        Returns:
30
            String: Human text for status code.
31
        """
32
        discovery_statuses = {"0": 'Unknown',
33
                              "1": 'InProgress',
34
                              "2": 'Finished',
35
                              "3": 'Error',
36
                              "4": "NotScheduled",
37
                              "5": "Scheduled",
38
                              "6": "NotCompleted",
39
                              "7": "Canceling",
40
                              "8": "ReadyForImport"}
41
42
        return discovery_statuses[status]
43
44
    def run(self, profileId, platform):
45
        """
46
        Get the progress of a discovery profile.
47
48
        Args:
49
            profileId: The id of the profile to query.
50
            platform: The orion platform to act on.
51
52
        Returns:
53
            dict: Of information from GetDiscoveryProgress Orion.Discovery
54
                  verb.
55
56
        Raises:
57
            None: Does not raise any exceptions.
58
        """
59
        results = {}
60
61
        self.connect(platform)
62
63
        orion_data = self.invoke("Orion.Discovery",
64
                                 "GetDiscoveryProgress",
65
                                 profileId)
66
67
        print orion_data
68
69
        root = ET.fromstring(orion_data)
70
71
        # FIXME - action disabled - this does not work as status is a nested element
72
        for child in root:
73
            key = child.tag
74
            results[key.replace("{http://schemas.solarwinds.com/2008/Orion}",
75
                                "")] = child.text
76
77
        return results
78