Ejemplo n.º 1
0
    def __present(self):
        try:
            self.module.log("argument_spec with config=" +
                            str(self.module.params['config']) + " hostname=" +
                            str(self.module.params['hostname']) +
                            " firmware_type=" +
                            str(self.module.params['firmware_type']))

            # instance of common class
            common = IsmCommon(self.module)

            # convert parameters to unicode string
            self.module.params['config'] = common.covert_unicode(
                self.module.params['config'])
            self.module.params['hostname'] = common.covert_unicode(
                self.module.params['hostname'])
            self.module.params['firmware_type'] = common.covert_unicode(
                self.module.params['firmware_type'])

            # config file open
            try:
                config_path = path.abspath(self.module.params['config'])
                f = open(config_path)
            except Exception as e:
                self.module.log("file open error: " + str(config_path) +
                                ", e=" + str(e))
                self.module.fail_json(msg="file open error: " +
                                      str(config_path))

            # config loads
            try:
                json_data = json.load(f)
            except Exception as e:
                f.close()
                self.module.log("Not json format data: " + str(config_path) +
                                ", e=" + str(e))
                self.module.fail_json(msg="It is not json format data: " +
                                      str(config_path))

            f.close()

            # ip transformation
            match = re.match(r'^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$',
                             self.module.params['hostname'])
            if match == None:
                try:
                    self.module.params['hostname'] = socket.gethostbyname(
                        self.module.params['hostname'])
                    self.module.debug(
                        "Host name is converted to IP address: " +
                        str(self.module.params['hostname']))
                except Exception as e:
                    self.module.log("ip transformation error: IP address=" +
                                    str(self.module.params['hostname']) +
                                    ", e=" + str(e))
                    self.module.fail_json(
                        msg="Host name could not be converted to IP address: "
                        + str(self.module.params['hostname']))

            # ISM login
            common.ismLogin(json_data)

            # License Check
            common.licenseCheck(license_check=False)

            # get node OS
            common.getNodeOS()

            # get node hard
            if common.getNodeId() == "":
                common.getNodeHard()

            # node check
            if common.getNodeId() == "":
                self.module.log("The target host name was not found.: " +
                                str(self.module.params['hostname']))
                self.module.fail_json(
                    msg="The target host name was not found.: " +
                    str(self.module.params['hostname']))
            else:
                self.module.debug("node_id: " + str(common.getNodeId()))

            # firmware list execution
            result = self.execFirmwareList(common)

            # ISM logout
            common.ismLogout()

            # return json
            changed_result = False
            self.module.log("ism_firmware_list successful completion")
            self.module.exit_json(changed=changed_result,
                                  ism_firmware_list=result)

        except Exception as e:
            self.module.log(str(e))
            self.module.fail_json(msg=str(e))
    def __present(self):
        try:
            self.module.log("argument_spec with config=" +
                            str(self.module.params['config']) + " hostname=" +
                            str(self.module.params['hostname']) + " mode=" +
                            str(self.module.params['mode']))

            # instance of common class
            common = IsmCommon(self.module)

            # convert parameters to unicode string
            self.module.params['config'] = common.covert_unicode(
                self.module.params['config'])
            self.module.params['hostname'] = common.covert_unicode(
                self.module.params['hostname'])
            self.module.params['mode'] = common.covert_unicode(
                self.module.params['mode'])

            # config file open
            try:
                config_path = path.abspath(self.module.params['config'])
                f = open(config_path)
            except Exception as e:
                self.module.log("file open error: " + str(config_path) +
                                ", e=" + str(e))
                self.module.fail_json(msg="file open error: " +
                                      str(config_path))

            # config loads
            try:
                json_data = json.load(f)
            except Exception as e:
                f.close()
                self.module.log("Not json format data: " + str(config_path) +
                                ", e=" + str(e))
                self.module.fail_json(msg="It is not json format data: " +
                                      str(config_path))

            f.close()

            # ip transformation
            match = re.match(r'^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$',
                             self.module.params['hostname'])
            if match == None:
                try:
                    self.module.params['hostname'] = socket.gethostbyname(
                        self.module.params['hostname'])
                    self.module.debug(
                        "Host name is converted to IP address: " +
                        str(self.module.params['hostname']))
                except Exception as e:
                    self.module.log("ip transformation error: IP address=" +
                                    str(self.module.params['hostname']) +
                                    ", e=" + str(e))
                    self.module.fail_json(
                        msg="Host name could not be converted to IP address: "
                        + str(self.module.params['hostname']))

            # ISM login
            common.ismLogin(json_data)

            # get node OS
            common.getNodeOS()

            # get node hard
            if common.getNodeId() == "":
                common.getNodeHard()

            # node check
            if common.getNodeId() == "":
                self.module.log("The target host name was not found.: " +
                                str(self.module.params['hostname']))
                self.module.fail_json(
                    msg="The target host name was not found.: " +
                    str(self.module.params['hostname']))
            else:
                self.module.debug("node_id: " + common.getNodeId())

            mode = ""
            if self.module.params['mode'] == "On":
                mode = "Maintenance"
            elif self.module.params['mode'] == "Off":
                mode = "Normal"
            else:
                self.module.log(
                    "A value other than On or Off is specified for mode parameter: "
                    + str(self.module.params['mode']))
                self.module.fail_json(
                    msg=
                    "A value other than On or Off is specified for mode parameter: "
                    + str(self.module.params['mode']))

            # check maintenance mode
            chk = self.checkMaintenanceMode(common, mode)

            # set maintenance mode
            if chk is True:
                result = self.maintenanceModeSetting(common, mode)
                changed_result = True
            else:
                result = "Success"
                changed_result = False

            # ISM logout
            common.ismLogout()

            # return json
            args = dict(ism_maintenance_mode=result)
            self.module.log("ism_maintenance_mode successful completion")
            self.module.exit_json(changed=changed_result, **args)

        except Exception as e:
            self.module.log(str(e))
            self.module.fail_json(msg=str(e))
Ejemplo n.º 3
0
 def __present(self):
     try :
         self.module.log("argument_spec with config=" + str(self.module.params['config']) + " hostname=" + str(self.module.params['hostname']) + " ism_profile_name=" + str(self.module.params['ism_profile_name']) + " assign_mode=" + str(self.module.params['assign_mode']) + " advanced_kind=" + str(self.module.params['advanced_kind']) + " assign_range=" + str(self.module.params['assign_range']))
         
         # instance of common class
         common = IsmCommon(self.module)
         
         # convert parameters to unicode string
         self.module.params['config'] = common.covert_unicode(self.module.params['config'])
         self.module.params['hostname'] = common.covert_unicode(self.module.params['hostname'])
         self.module.params['ism_profile_name'] = common.covert_unicode(self.module.params['ism_profile_name'])
         self.module.params['assign_mode'] = common.covert_unicode(self.module.params['assign_mode'])
         self.module.params['advanced_kind'] = common.covert_unicode(self.module.params['advanced_kind'])
         if self.module.params['assign_range'] is not None:
             for key in self.module.params['assign_range']:
                 key = common.covert_unicode(key)
                 
         # config file open
         try :
             config_path = path.abspath(self.module.params['config'])
             f = open(config_path)
         except Exception as e:
             self.module.log("file open error: " + str(config_path) + ", e=" + str(e))
             self.module.fail_json(msg="file open error: " + str(config_path))
         
         # config loads
         try :
             json_data = json.load(f)
         except Exception as e:
             f.close()
             self.module.log("Not json format data: " + str(config_path) + ", e=" + str(e))
             self.module.fail_json(msg="It is not json format data: " + str(config_path))
             
         f.close()
         
         # ip transformation
         match = re.match(r'^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$', self.module.params['hostname'])
         if match is None:
             try :
                 self.module.params['hostname'] = socket.gethostbyname(self.module.params['hostname'])
                 self.module.debug("Host name is converted to IP address: " + str(self.module.params['hostname']))
             except Exception as e:
                 self.module.log("ip transformation error: IP address=" + str(self.module.params['hostname']) + ", e=" + str(e))
                 self.module.fail_json(msg="Host name could not be converted to IP address: " + str(self.module.params['hostname']))
                 
         # ISM login
         common.ismLogin(json_data)
         
         # License Check
         common.licenseCheck()
         
         # get node OS
         common.getNodeOS()
         
         # get node hard
         if common.getNodeId() == "":
             common.getNodeHard()
             
         # node check
         if common.getNodeId() == "":
             self.module.log("The target host name was not found.: " + str(self.module.params['hostname']))
             self.module.fail_json(msg="The target host name was not found.: " + str(self.module.params['hostname']))
         else:
             self.module.debug("node_id: " + common.getNodeId())
             
         # get profileId
         profile_id = self.getProfileId(common)
         
         if profile_id == "":
             self.module.log("Profile name matching the profile name of the parameter could not be found. profile name:" + self.module.params['ism_profile_name'])
             self.module.fail_json(msg="Profile name matching the profile name of the parameter could not be found. profile name:" + self.module.params['ism_profile_name'])
             
         if self.module.params['assign_mode'] == "Advanced" and self.module.params['advanced_kind'] == "ForcedAssign":
             # profile assignment execution
             result = self.profileAssignment(common, profile_id)
             changed_result = True
         else:
             # check profile assignment
             chk = self.checkProfileAssignment(common, profile_id)
             
             # profile assignment execution
             if chk is True:
                 result = self.profileAssignment(common, profile_id)
                 changed_result = True
             else:
                 result = "Success"
                 changed_result = False
             
         # ISM logout
         common.ismLogout()
         
         # return json
         args = dict(
             ism_profile_assignment = result
         )
         self.module.log("ism_profile_assignment successful completion")
         self.module.exit_json(changed=changed_result, **args)
         
     except Exception as e:
         self.module.log(str(e))
         self.module.fail_json(msg=str(e))
Ejemplo n.º 4
0
    def __present(self):
        try:
            self.module.log("argument_spec with config=" +
                            str(self.module.params['config']) + " hostname=" +
                            str(self.module.params['hostname']) +
                            " firmware_update_list=" +
                            str(self.module.params['firmware_update_list']))

            # instance of common class
            common = IsmCommon(self.module)

            # param check
            common.param_check(self.module.params['firmware_update_list'])

            # convert parameters to unicode string
            self.module.params['config'] = common.covert_unicode(
                self.module.params['config'])
            self.module.params['hostname'] = common.covert_unicode(
                self.module.params['hostname'])

            # config file open
            try:
                config_path = path.abspath(self.module.params['config'])
                f = open(config_path)
            except Exception as e:
                self.module.log("file open error: " + str(config_path) +
                                ", e=" + str(e))
                self.module.fail_json(msg="file open error: " +
                                      str(config_path))

            # config loads
            try:
                json_data = json.load(f)
            except Exception as e:
                f.close()
                self.module.log("Not json format data: " + str(config_path) +
                                ", e=" + str(e))
                self.module.fail_json(msg="It is not json format data: " +
                                      str(config_path))

            f.close()

            # ip transformation
            match = re.match(r'^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$',
                             self.module.params['hostname'])
            if match == None:
                try:
                    self.module.params['hostname'] = socket.gethostbyname(
                        self.module.params['hostname'])
                    self.module.debug(
                        "Host name is converted to IP address: " +
                        str(self.module.params['hostname']))
                except Exception as e:
                    self.module.log("ip transformation error: IP address=" +
                                    str(self.module.params['hostname']) +
                                    ", e=" + str(e))
                    self.module.fail_json(
                        msg="Host name could not be converted to IP address: "
                        + str(self.module.params['hostname']))

            # ISM login
            common.ismLogin(json_data)

            # License Check
            common.licenseCheck(usable_essential=True)

            # get node OS
            common.getNodeOS()

            # get node hard
            if common.getNodeId() == "":
                common.getNodeHard()

            # node check
            if common.getNodeId() == "":
                self.module.log("The target host name was not found.: " +
                                str(self.module.params['hostname']))
                self.module.fail_json(
                    msg="The target host name was not found.: " +
                    str(self.module.params['hostname']))
            else:
                self.module.debug("node_id: " + common.getNodeId())

            # Check type and model of node are supporetd on Essential mode
            common.checkNodeSupportedOnEssential()

            # firmware update execution
            firmware_update_list = []
            for update_param_hash in self.module.params[
                    'firmware_update_list']:

                if "firmware_version" in update_param_hash:
                    self.module.debug("***** firmwareversion specified *****")

                    if update_param_hash[
                            'firmware_version'] == "" or update_param_hash[
                                'firmware_version'] == None:
                        # latest firmware version
                        latest_firmware_version = self.getFirmwareVersion(
                            common, update_param_hash['firmware_name'],
                            update_param_hash['operation_mode'])
                        update_param_hash[
                            'firmware_version'] = latest_firmware_version

                    # check firmware version
                    chk = self.checkFirmwareVersion(
                        common, update_param_hash['firmware_name'],
                        update_param_hash['firmware_version'])

                else:
                    self.module.debug(
                        "***** firmwareversion not specified *****")

                    # latest firmware version
                    latest_firmware_version = self.getFirmwareVersion(
                        common, update_param_hash['firmware_name'],
                        update_param_hash['operation_mode'])
                    update_param_hash[
                        'firmware_version'] = latest_firmware_version

                    # check firmware version
                    chk = self.checkFirmwareVersion(
                        common, update_param_hash['firmware_name'],
                        update_param_hash['firmware_version'])

                if chk is True:
                    firmware_update_list.append(update_param_hash)

            # firmware update start execution
            if len(firmware_update_list) == 0:
                result = "Success"
                changed_result = False
            else:
                result = self.firmwareUpdate(common, firmware_update_list)
                changed_result = True

            # ISM logout
            common.ismLogout()

            # return json
            args = dict(ism_firmware_update=result)
            self.module.log("ism_firmware_update successful completion")
            self.module.exit_json(changed=changed_result, **args)
        except Exception as e:
            self.module.log(str(e))
            self.module.fail_json(msg=str(e))
Ejemplo n.º 5
0
 def __present(self):
     try :
         self.module.log("argument_spec with config=" + str(self.module.params['config']) + " hostname=" + str(self.module.params['hostname']))
         
         # instance of common class
         common = IsmCommon(self.module)
         
         # convert parameters to unicode string
         self.module.params['config'] = common.covert_unicode(self.module.params['config'])
         self.module.params['hostname'] = common.covert_unicode(self.module.params['hostname'])
         
         # config file open
         try :
             config_path = path.abspath(self.module.params['config'])
             f = open(config_path)
         except Exception as e:
             self.module.log("file open error: " + str(config_path) + ", e=" + str(e))
             self.module.fail_json(msg="file open error: " + str(config_path))
         
         # config loads
         try :
             json_data = json.load(f)
         except Exception as e:
             f.close()
             self.module.log("Not json format data: " + str(config_path) + ", e=" + str(e))
             self.module.fail_json(msg="It is not json format data: " + str(config_path))
             
         f.close()
         
         # ip transformation
         match = re.match(r'^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$', self.module.params['hostname'])
         if match is None:
             try :
                 self.module.params['hostname'] = socket.gethostbyname(self.module.params['hostname'])
                 self.module.debug("Host name is converted to IP address: " + str(self.module.params['hostname']))
             except Exception as e:
                 self.module.log("ip transformation error: IP address=" + str(self.module.params['hostname']) + ", e=" + str(e))
                 self.module.fail_json(msg="Host name could not be converted to IP address: " + str(self.module.params['hostname']))
                 
         # ISM login
         common.ismLogin(json_data)
         
          # License Check
         common.licenseCheck(usable_essential = True)
         
         # get node OS
         common.getNodeOS()
         
         # get node hard
         if common.getNodeId() == "":
             common.getNodeHard()
             
         # node check
         if common.getNodeId() == "":
             self.module.log("The target host name was not found.: " + str(self.module.params['hostname']))
             self.module.fail_json(msg="The target host name was not found.: " + str(self.module.params['hostname']))
         else:
             self.module.debug("node_id: " + common.getNodeId())
         
         # Check type and model of node are supporetd on Essential mode
         common.checkNodeSupportedOnEssential()
             
         # check powercontrol
         chk = self.checkPowerControl(common)
         
         # power on execution
         if chk is True:
             result = self.powerOn(common)
             changed_result = True
         else:
             result = "Success"
             changed_result = False
         
         # ISM logout
         common.ismLogout()
         
         # return json
         args = dict(
             ism_power_on = result
         )
         self.module.log("ism_power_on successful completion")
         self.module.exit_json(changed=changed_result, **args)
         
     except Exception as e:
         self.module.log(str(e))
         self.module.fail_json(msg=str(e))