예제 #1
0
    def set_acl_settings(self,
                         autoupdate=None,
                         autoinstall=None,
                         installtime=None):
        if autoupdate is not None:
            command = "setautoupdate"
            key = "enable"
            value = autoupdate

        elif autoinstall is not None:
            command = "setautoinstall"
            key = "enable"
            value = autoinstall

        elif installtime is not None:
            command = "setinstalltime"
            key = "hour"
            value = autoinstall

        if value in [True, "yes", "y", "1"]:
            value = "yes"

        if value in [False, "no", "n", "0"]:
            value = "no"

        parameters = {
            key: value
        }

        response = self._get("/geoacl/{}".format(command), parameters)

        if is_successful(response):
            pass
        else:
            raise KempTechApiException(get_error_msg(response))
예제 #2
0
    def acl_install(self):
        response = self._get("/geoacl/installnow")

        if is_successful(response):
            pass
        else:
            raise KempTechApiException(get_error_msg(response))
예제 #3
0
    def get_acl_settings(self):
        response = self._get("/geoacl/getsettings")

        if is_successful(response):
            data = get_data(response)
            data = data['GeoAcl']
        else:
            raise KempTechApiException(get_error_msg(response))

        acl_settings = {}

        for k, v in data.items():
            if v == "yes":
                v = True
            elif v == "no":
                v = False
            elif v == "Never":
                v = None
            else:
                try:
                    v = int(v)  # pylint: disable=redefined-variable-type
                except ValueError:
                    pass

            acl_settings[k.lower()] = v

        return acl_settings
예제 #4
0
    def refresh_dns(self):
        api = "/resolvenow"
        response = self._get(api)

        if is_successful(response):
            pass
        else:
            raise KempTechApiException(get_error_msg(response))
예제 #5
0
    def acl_changes(self):
        response = self._get("/geoacl/downloadchanges")

        if is_successful(response):
            pass
        else:
            raise KempTechApiException(get_error_msg(response))

        return response
예제 #6
0
    def remove_acl(self, type, value):
        parameters = {
            "type": type,
            "addr": value
        }

        response = self._get("/geoacl/removecustom", parameters)

        if is_successful(response):
            pass
        else:
            raise KempTechApiException(get_error_msg(response))
예제 #7
0
    def get_eula(self):
        api = "/readeula"

        response = self._get(api)

        if is_successful(response):
            data = get_data(response)
        else:
            raise KempTechApiException(get_error_msg(response))

        self.magic = data['Magic']
        return data['Eula']
예제 #8
0
    def initial_password(self, password="******"):
        api = "/set_initial_passwd"

        parameters = {
            "passwd": password
        }

        response = self._get(api, parameters=parameters)

        if not is_successful(response):
            raise KempTechApiException(get_error_msg(response))

        self.password = password
예제 #9
0
    def accept_eula(self, license_type="trial"):
        api = "/accepteula"

        parameters = {
            "type": license_type,
            "magic": self.magic
        }

        response = self._get(api, parameters=parameters)

        if is_successful(response):
            data = get_data(response)
        else:
            raise KempTechApiException(get_error_msg(response))

        self.magic = data['Magic']
예제 #10
0
    def set_callhome(self, enabled=True):
        api = "/accepteula2"

        if enabled is True:
            enabled = "yes"
        else:
            enabled = "no"

        parameters = {
            "accept": enabled,
            "magic": self.magic
        }

        response = self._get(api, parameters=parameters)

        if not is_successful(response):
            raise KempTechApiException(get_error_msg(response))
예제 #11
0
    def apply_template(self, virtual_ip, port, protocol, template_name,
                       nickname=None):
        params = {
            'vs': virtual_ip,
            'port': port,
            'prot': protocol,
            'name': template_name,
        }

        existing = self.vs.keys()

        if nickname is not None:
            params['nickname'] = nickname

        response = self._get("/addvs", parameters=params)

        if is_successful(response):
            vs = {k: v for k, v in self.vs.items()
                  if k not in existing}
        else:
            raise KempTechApiException(get_error_msg(response))

        return vs
예제 #12
0
    def get_acl(self, type):
        parameters = {
            "type": type
        }
        response = self._get("/geoacl/listcustom", parameters)

        if is_successful(response):
            data = get_data(response)
        else:
            raise KempTechApiException(get_error_msg(response))

        list_tag = "{}list".format(type).capitalize()

        acl_list = data[list_tag]

        if acl_list is None:
            acl_list = []
        elif isinstance(acl_list, dict):
            acl_list = acl_list.get('addr')

        if not isinstance(acl_list, list):
            acl_list = [acl_list]

        return acl_list
예제 #13
0
    def license(self):
        """Current license on the LoadMaster

        :return: License information
        """
        response = self._get("/licenseinfo")

        if is_successful(response):
            data = get_data(response)
            license_info = {}

            # Fix annoying API weirdness
            for k, v in data.items():
                k = k.lower()

                try:
                    if v[0] == '"':
                        v = v[1:]

                    if v[-1] == '"':
                        v = v[:-1]

                    if v[-1] == "\n":
                        v = v[:-1]
                except (IndexError, KeyError):
                    # Catch scenarios where there is no data
                    pass

                if isinstance(v, str):
                    v = v.replace("  ", " ")

                license_info[k] = v
        else:
            raise KempTechApiException(get_error_msg(response))

        return license_info
예제 #14
0
def send_response(response):
    parsed_resp = parse_to_dict(response)
    if is_successful(parsed_resp):
        return parsed_resp
    else:
        raise KempTechApiException(get_error_msg(parsed_resp))
예제 #15
0
def test_get_error_msg():
    with patch.object(api_xml, '_get_xml_field') as _get_xml_field:
        _get_xml_field.return_value = {'Error': sentinel.data}
        res = api_xml.get_error_msg('anyxml')
        assert_equal("{'Error': sentinel.data}", res)