aboutsummaryrefslogtreecommitdiffstats
path: root/deploy/dha_adapters/zte_adapter.py
blob: 1e610ca4164c28a4ec170de14844284aa0f7938a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
###############################################################################
# Copyright (c) 2015 Ericsson AB and others.
# szilard.cserey@ericsson.com
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
###############################################################################


import time
from ipmi_adapter import IpmiAdapter

from common import (
    log,
    exec_cmd,
    err,
)


class ZteAdapter(IpmiAdapter):

    def __init__(self, yaml_path):
        super(ZteAdapter, self).__init__(yaml_path)

    def node_reset(self, node_id):
        WAIT_LOOP = 600
        log('RESET Node %s' % node_id)
        cmd_prefix = self.ipmi_cmd(node_id)
        state = exec_cmd('%s chassis power status' % cmd_prefix, mask_args=[8,10])
        if state == 'Chassis Power is on':
            was_shut_off = False
            done = False
            exec_cmd('%s chassis power cycle' % cmd_prefix, mask_args=[8,10])
            for i in range(WAIT_LOOP):
                state, _ = exec_cmd('%s chassis power status' % cmd_prefix,
                                    check=False,
                                    mask_args=[8,10])
                if state == 'Chassis Power is off':
                    was_shut_off = True
                elif state == 'Chassis Power is on' and was_shut_off:
                    done = True
                    break
                time.sleep(1)
            if not done:
                err('Could Not RESET Node %s' % node_id)
        else:
            err('Cannot RESET Node %s because it\'s not Active, state: %s'
                % (node_id, state))