Esempio n. 1
0
def update(isamAppliance,
           extId,
           config_data=None,
           third_party_package=None,
           check_mode=False,
           force=False):
    """
    Update an existing installed extension

    :param isamAppliance:
    :param extId: extension id
    :param config_data: all the config data in a single string.  For example, "agentName:ISAM_Monitoring,ipAddress:10.10.10.10,port:9998"
    :param third_party_package: list of third_party files
    :param check_mode:
    :param force:
    :return:
    """

    if force is True or search(isamAppliance, extId=extId):
        if check_mode:
            return isamAppliance.create_return_object(changed=True)
        else:
            if config_data:
                config_str = '{extId:' + extId + ',' + config_data + '}'
            else:
                config_str = '{extId:' + extId + '}'

            files = {}

            files['config_data'] = (None, config_str)

            if third_party_package:
                if isinstance(third_party_package, basestring):
                    files['third_party_package'] = (
                        tools.path_leaf(third_party_package),
                        open(third_party_package, 'rb'))
                elif len(third_party_package) == 1:
                    files['third_party_package'] = (tools.path_leaf(
                        third_party_package[0]),
                                                    open(
                                                        third_party_package[0],
                                                        'rb'))
                else:
                    counter = 0
                    for file in third_party_package:
                        third_party = 'third_party_package{0}'.format(counter)
                        files[third_party] = (tools.path_leaf(file),
                                              open(file, 'rb'))
                        counter = counter + 1

            return isamAppliance.invoke_post_files(
                "Update an Extension",
                "{0}/{1}".format(uri, extId), [],
                files,
                requires_modules=requires_modules,
                requires_version=requires_version,
                json_response=False,
                data_as_files=True)

    return isamAppliance.create_return_object()
Esempio n. 2
0
def add(isamAppliance,
        extension,
        config_data=None,
        third_party_package=None,
        check_mode=False,
        force=False):
    """
    Installing an Extension

    :param isamAppliance:
    :param extension: path/filename to .ext file
    :param config_data: all the config data in a single string.  For example, "agentName:ISAM_Monitoring,ipAddress:10.10.10.10,port:9998"
    :param third_party_package: an array of the supporting files required.
    :param check_mode:
    :param force:
    :return:
    """

    try:
        id = inspect(isamAppliance, extension)
    except Exception as e:
        return isamAppliance.create_return_object(warnings=e)

    if config_data:
        config_str = '{extId:' + id + ',' + config_data + '}'
    else:
        config_str = '{extId:' + id + '}'

    files = {}

    files['extension_support_package'] = (tools.path_leaf(extension),
                                          open(extension, 'rb'))
    files['config_data'] = (None, config_str)

    if third_party_package:
        if isinstance(third_party_package, basestring):
            files['third_party_package'] = (
                tools.path_leaf(third_party_package),
                open(third_party_package, 'rb'))
        elif len(third_party_package) == 1:
            files['third_party_package'] = (tools.path_leaf(
                third_party_package[0]), open(third_party_package[0], 'rb'))
        else:
            counter = 0
            for file in third_party_package:
                third_party = 'third_party_package{0}'.format(counter)
                files[third_party] = (tools.path_leaf(file), open(file, 'rb'))
                counter = counter + 1

    if check_mode:
        return isamAppliance.create_return_object(changed=True)

    return isamAppliance.invoke_post_files("Installing an Extension",
                                           "{0}/activate".format(uri), [],
                                           files,
                                           requires_modules=requires_modules,
                                           requires_version=requires_version,
                                           json_response=False,
                                           data_as_files=True)
Esempio n. 3
0
    def invoke_post_files(self, description, uri, fileinfo, data, ignore_error=False, requires_modules=None,
                          requires_version=None, warnings=[], json_response=True, data_as_files=False,
                          requires_model=None):
        """
        Send multipart/form-data upload file request to the appliance.
        """
        self._log_desc(description=description)

        warnings, return_call = self._process_warnings(uri=uri, requires_modules=requires_modules,
                                                       requires_version=requires_version,
                                                       warnings=warnings, requires_model=requires_model)
        return_obj = self.create_return_object(warnings=warnings)
        if return_call:
            return return_obj

        # Build up the URL and header information.
        if json_response:
            headers = {
                'Accept': 'application/json,text/html,application/xhtml+xml,application/xml'
            }
        else:
            headers = {
                'Accept': 'text/html,application/xhtml+xml,application/xml'
            }
        self.logger.debug("Headers are: {0}".format(headers))

        if data_as_files is False:
            files = list()
            for file2post in fileinfo:
                files.append((file2post['file_formfield'],
                              (tools.path_leaf(file2post['filename']), open(file2post['filename'], 'rb'),
                               file2post['mimetype'])))
        else:
            files = data

        self._suppress_ssl_warning()

        try:
            if data_as_files is False:
                r = self.session.post(url=self._url(uri=uri), data=data, files=files, verify=False, headers=headers)
            else:
                r = self.session.post(url=self._url(uri=uri), files=files, verify=False, headers=headers)
            return_obj['changed'] = True  # POST of file would be a change
            self._process_response(return_obj=return_obj, http_response=r, ignore_error=ignore_error)

        except requests.exceptions.ConnectionError:
            if not ignore_error:
                self.logger.critical("Failed to connect to server.")
                raise IBMError("HTTP Return code: 502", "Failed to connect to server")
            else:
                self.logger.debug("Failed to connect to server.")
                return_obj.rc = 502

        return return_obj