~ibmcharmers/charms/trusty/layer-ibm-dsm-enterprise/devel

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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import platform
import os
import subprocess
from charms.reactive import when_not
from charms.reactive import set_state
from charms.reactive import is_state
from charmhelpers.core import hookenv

ARCHITECTURE = os.uname()
CHARM_DIR = os.getcwd()
file_admin_password = CHARM_DIR + "/file_admin_password.txt"


def check_platform_architecture():
    return platform.processor()


@when_not('ibm-dsm.enterprise')
def packge_ibm_dsm_enterprise():

    # save user password
    if not is_state('ibm-dsm-adminpassword.set'):
        config = hookenv.config()
        cfg_dsm_admin_password = config.get('dsm_admin_password')
        if cfg_dsm_admin_password == "":
            hookenv.status_set("blocked",
                               "IBM DSM: Provide dsm_admin_password")
            return 0
        try:
            file_admin_password_obj = open(file_admin_password, "w")
            file_admin_password_obj.write(cfg_dsm_admin_password)
            file_admin_password_obj.close()
            set_state('ibm-dsm-adminpassword.set')
            hookenv.log("packge_ibm_dsm_enterprise: user "
                        "admin password :" + cfg_dsm_admin_password)
        except subprocess.CalledProcessError as e:
            hookenv.log(e.output)
            hookenv.log("packge_ibm_dsm_enterprise: user "
                        "admin password unable to set")
            return 0

    if not (("ppc64le" in ARCHITECTURE) or ("x86_64" in ARCHITECTURE)):
        hookenv.log("packge_ibm_dsm_enterprise: "
                    "supported only on x86_64 or ppc64le")
        hookenv.status_set('blocked',
                           'IBM DSM Enterprise: unsupported architecture')
        return 1

    if "x86_64" in ARCHITECTURE or "ppc64le" in ARCHITECTURE:
        if "x86_64" in ARCHITECTURE:
            hookenv.log("packge_ibm_dsm_enterprise: Architecture is x86_64")
        else:
            hookenv.log("packge_ibm_dsm_enterprise: Architecture is ppc64le")

    CHARM_DIR = os.getcwd()
    DSM_HOME = (CHARM_DIR+"/../resources/DSM/ibm-datasrvrmgr/")
    hookenv.log("packge_ibm_dsm_enterprise: DSM_HOME dir is :"+DSM_HOME)
    if not (os.path.exists(DSM_HOME) or
            (os.path.exists(DSM_HOME+"setup.conf"))):
        hookenv.log("packge_ibm_dsm_enterprise: "
                    "fetching ibm_dsm_installer resource")
        hookenv.status_set('active',
                           'IBM DSM Enterprise: '
                           'fetching ibm_dsm_installer resource')
        dsm_installer = hookenv.resource_get('ibm_dsm_installer')

        hookenv.log("packge_ibm_dsm_enterprise: "
                    "fetching ibm_dsm_license resource")
        hookenv.status_set('active',
                           'IBM DSM Enterprise: '
                           'fetching ibm_dsm_license resource')
        dsm_license = hookenv.resource_get('ibm_dsm_license')

        # If we don't have a package,report blocked status;we can't proceed.
        if (dsm_installer is False):
            hookenv.log("packge_ibm_dsm_enterprise: missing"
                        "required ibm_dsm resources")
            hookenv.status_set("blocked",
                               "IBM DSM Enterprise: Required product "
                               "packages are missing")
            return 0

        # If we don't have a package for license,
        # report blocked status;we can't proceed.
        if (dsm_license is False):
            hookenv.log("packge_ibm_dsm_enterprise:"
                        "missing required ibm_dsm license resources")
            hookenv.status_set("blocked",
                               "IBM DSM Enterprise: required license"
                               "package is missing")
            return 0

        command1 = ["file", dsm_installer]
        p1 = subprocess.Popen(command1, stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE, shell=False)
        output1, err = p1.communicate()
        dsm_installer_msg = str(output1)

        command2 = ["file", dsm_license]
        p2 = subprocess.Popen(command2, stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE, shell=False)
        output2, err = p2.communicate()
        dsm_license_msg = str(output2)

        if (("empty" in dsm_installer_msg) or
           ("empty" in dsm_license_msg)):
            hookenv.log("packge_ibm_dsm_enterprise: missing required ibm_dsm"
                        "resources,empty packages are found")
            hookenv.status_set("blocked",
                               "IBM DSM Enterprise: Required"
                               "packages are empty")
            return 0
        else:
            set_state('ibm-dsm.enterprise')
            hookenv.log("packge_ibm_dsm_enterprise: "
                        "set state to ibm-dsm-enterprise")