Beispiel #1
0
def _napalm_ipv4_converter(hostname: str(),
                           plateform: str(),
                           cmd_output: json,
                           *,
                           filters=dict()) -> ListIPV4Interface:

    ipv4_addresses_lst = ListIPV4Interface(hostname=hostname,
                                           ipv4_addresses_lst=list())

    for interface_name in cmd_output.get('get_interfaces_ip'):
        if _generic_interface_filter(
                interface_name=_mapping_interface_name(interface_name),
                plateform=plateform,
                filters=filters):
            for ip_addr in cmd_output.get('get_interfaces_ip').get(
                    interface_name).get('ipv4'):

                ipv4_addresses_lst.ipv4_addresses_lst.append(
                    IPV4Interface(
                        interface_name=_mapping_interface_name(interface_name),
                        ip_address_with_mask=ip_addr,
                        netmask=cmd_output.get('get_interfaces_ip').get(
                            interface_name).get('ipv4').get(ip_addr).get(
                                'prefix_length')))

    print(ipv4_addresses_lst)
    return ipv4_addresses_lst
Beispiel #2
0
 def update_testcase(self, updated_values: json):
     """update testcase from self parameters"""
     url = f'{self._baseurl}/testcase/{self.testcase["key"]}'
     folder = updated_values['folder'] if updated_values['folder'][0] == '/' \
         else f"/{updated_values['folder']}"
     testcase = {
         'name': updated_values['name'],
         'objective': updated_values.get('objective', None),
         'precondition': updated_values.get('precondition', None),
         'status': updated_values['status'],
         'priority': updated_values.get('priority', None),
         'owner': updated_values.get('owner', None),
         'estimatedTime': updated_values.get('estimatedTime', None),
         'component': updated_values.get('component', None),
         'labels': updated_values.get('labels', None),
         'folder': folder,
         'parameters': updated_values.get('parameters', None),
         'issueLinks': updated_values.get('issueLinks', None),
         'customFields': updated_values.get('customFields', None),
         'testScript': {'type': 'STEP_BY_STEP', 'steps':
                        [{k: v for k, v in d.items() if k != 'index'}
                         for d in updated_values.get('testScript', [])['steps']]}
     }
     try:
         self._do('put', url, payload=strip_none_values(testcase))
     except TM4JFolderNotFound:
         self._create_folder('TEST_CASE', folder.strip('/'))
         self._do('put', url, payload=strip_none_values(testcase))
     finally:
         self._put_testcase_paramtype_property()
Beispiel #3
0
    def from_json(cls, sched_json: json):
        timezone = tz.gettz(sched_json['tzname'])
        schedule_date = dt.datetime.strptime(sched_json["schedule_date"],
                                             date_format)
        schedule_date = schedule_date.replace(tzinfo=timezone)

        new_bs = BellSchedule(
            sched_json["name"],
            tzname=sched_json["tzname"],
            schedule_date=schedule_date,
        )
        new_bs.campus, new_bs.division = sched_json.get(
            'campus'), sched_json.get('division')
        new_bs.ts = sched_json.get("ts", dt.datetime.utcnow().timestamp())
        for period in sched_json["periods"]:
            start_time = iso8601.parse_date(period.get("start_time"))
            end_time = iso8601.parse_date(period.get("end_time"))
            new_bs.add_period(period=Period(
                period.get("name"),
                start_time,
                end_time,
                (end_time - start_time).seconds / 60,
            ))

        return new_bs
Beispiel #4
0
    def loadDataInObs(
        self,
        my_measure: json,
        obs_meteor: ObsMeteor,
        target_key: str,
        delta_values: json,
        my_values: json,
        trace_flag: bool,
    ):
        """
            loadObservationDatarow

            load Observation dataRow from json measures

            load delta_values from json mesures
        """
        obs_j = obs_meteor.data.j

        my_value_avg = my_values.get(target_key + '_a')
        my_value_instant = my_values.get(target_key + '_i')
        my_value_dir = my_values.get(target_key + '_di')
        tmp_duration = my_values.get(target_key + '_du')
        if isFlagged(my_measure['special'], MeasureProcessingBitMask.MeasureIsOmm):
            tmp_duration = 60
        if my_value_avg is None and my_value_instant is None:
            return
        tmp_sum = my_value_avg if my_value_avg is not None else my_value_instant

        if my_value_avg is None:
            if my_value_instant is None:
                # no data suitable for us
                return
            else:
                my_value_avg = my_value_instant

        # get current values from our aggregations
        tmp_sum_old = tmp_duration_old = 0
        if obs_j.get(target_key) is not None:
            tmp_sum_old = obs_j[target_key]
            if tmp_sum == tmp_sum_old:
                # no change on avg computation
                return
            tmp_duration_old = obs_j.get(target_key + '_duration')
            if tmp_duration is None:
                tmp_duration_old = obs_meteor.data.duration
            if tmp_duration != tmp_duration_old:
                raise('loadDataInObs', 'duration mitchmath for ' + target_key + ': in obs' + str(tmp_duration_old) + ', in json: ' + str(tmp_duration))
            delta_values[target_key + '_sum_old'] = tmp_sum_old
            delta_values[target_key + '_duration_old'] = tmp_duration_old

        # save data in dv
        delta_values[target_key + '_sum'] = tmp_sum
        delta_values[target_key + '_duration'] = tmp_duration

        # save data in obs
        if my_value_instant is not None:
            obs_j[target_key] = my_value_instant

        if my_value_dir is not None:
            obs_j[target_key + '_dir'] = my_value_dir
def _compare_mlag(host_keys, hostname, mlag_host_data: None,
                  mlag_yaml_data: json) -> bool:

    if mlag_yaml_data is None:
        return False

    if MLAG_DATA_HOST_KEY in host_keys and hostname in mlag_yaml_data.keys():

        verity_mlag = MLAG(
            hostname=hostname,
            local_id=mlag_yaml_data.get(hostname).get("local_id", NOT_SET),
            peer_id=mlag_yaml_data.get(hostname).get("peer_id", NOT_SET),
            peer_alive=mlag_yaml_data.get(hostname).get("peer_alive", NOT_SET),
            peer_int=mlag_yaml_data.get(hostname).get("peer_int", NOT_SET),
            peer_ip=mlag_yaml_data.get(hostname).get("peer_ip", NOT_SET),
            sys_mac=mlag_yaml_data.get(hostname).get("sys_mac", NOT_SET),
            local_role=mlag_yaml_data.get(hostname).get("local_role", NOT_SET),
            peer_role=mlag_yaml_data.get(hostname).get("peer_role", NOT_SET),
            local_priority=mlag_yaml_data.get(hostname).get(
                "local_priority", NOT_SET),
            peer_priority=mlag_yaml_data.get(hostname).get(
                "peer_priority", NOT_SET),
            vxlan_anycast_ip=mlag_yaml_data.get(hostname).get(
                "vxlan_anycast_ip", NOT_SET),
        )

        return verity_mlag == mlag_host_data

    else:
        print(
            f"[{HEADER_GET}] {hostname} is not present in {PATH_TO_VERITY_FILES}/{TEST_TO_EXC_MLAG_KEY}."
        )
def _arista_ipv6_converter(hostname: str(),
                           plateform: str(),
                           cmd_output: json,
                           *,
                           filters=dict()) -> ListIPV6Interface:

    if cmd_output is None or cmd_output == "":
        return None

    ipv6_addresses_lst = ListIPV6Interface(ipv6_addresses_lst=list())
    if "interfaces" in cmd_output.keys():
        for interface_name in cmd_output.get("interfaces"):
            if _generic_interface_filter(
                    plateform=plateform,
                    interface_name=_mapping_interface_name(interface_name),
                    filters=filters):

                for address in cmd_output.get("interfaces").get(
                        interface_name).get("addresses"):

                    index_slash = str(address.get("subnet", NOT_SET)).find("/")

                    ipv6_addresses_lst.ipv6_addresses_lst.append(
                        IPV6Interface(interface_name=_mapping_interface_name(
                            interface_name),
                                      ip_address_with_mask=address.get(
                                          "address", NOT_SET),
                                      netmask=str(
                                          address.get("subnet",
                                                      NOT_SET))[index_slash +
                                                                1:]))

    return ipv6_addresses_lst
Beispiel #7
0
def parse_config(config: json, logger: AirbyteLogger) -> Dict[str, Any]:
    """
    Convert dict of config values to firebolt.db.Connection arguments

    :param config: json-compatible dict of settings
    :param logger: AirbyteLogger instance to print logs.

    :return: dictionary of firebolt.db.Connection-compatible kwargs
    """
    connection_args = {
        "database": config["database"],
        "auth": UsernamePassword(config["username"], config["password"]),
        "api_endpoint": config.get("host", DEFAULT_API_URL),
        "account_name": config.get("account"),
    }
    # engine can be a name or a full URL of a cluster
    engine = config.get("engine")
    if engine:
        if "." in engine:
            connection_args["engine_url"] = engine
        else:
            connection_args["engine_name"] = engine
    else:
        logger.info(
            "Engine parameter was not provided. Connecting to the default engine."
        )
    return connection_args
def extractappfields(appjson:json):
    """ parse Apple Lookup API result and return dictionary of fields """
    result = {}
    if 'results' in appjson and len(appjson['results']) >= 1:
        appjson = appjson['results'][0]

    # get type of 'adam' (PHG terminology for iTunes product)
    if 'kind' not in appjson:
        if 'wrapperType' not in appjson:
            adamtype = 'NO APPLE RESULT'
        else:
            adamtype = appjson['wrapperType']
    else:
        adamtype = appjson['kind']

    result['adamtype'] = adamtype
    result['title'] = appjson.get('trackName', 'NULL')
    result['description'] = appjson.get('description', 'NULL')
    result['price'] = appjson.get('price', 'NULL')
    result['primarygenre'] = appjson.get('primaryGenreName', 'NULL')
    result['version'] = appjson.get('version', 'NULL')
    try:
        result['releasedate'] = datetime.strptime(appjson['releaseDate'],'%Y-%m-%dT%H:%M:%SZ')
    except:
        result['releasedate'] = 'NULL'
    result['rating'] = appjson.get('averageUserRating', 'NULL')
    result['ratings'] = appjson.get('userRatingCount', 'NULL')
    result['currrating'] = appjson.get('averageUserRatingForCurrentVersion', 'NULL')
    result['currratings'] = appjson.get('userRatingCountForCurrentVersion', 'NULL')
    result['currentVersionReleaseDate'] = appjson.get('currentVersionReleaseDate', 'NULL')

    return result
Beispiel #9
0
    def __init__(self, data: json, score_calculator: ScoreCalculator):
        general_data = data.get('general_data')
        geo_data = data.get('geo_data')

        # GENERAL DATA
        self._id = int(general_data.get('obj_scoutId'))
        self._region_1 = general_data.get('obj_regio1')
        self._region_2 = general_data.get('obj_regio2')
        self._region_3 = general_data.get('obj_regio3')
        self._street = general_data.get('obj_street')
        self._heating_type = general_data.get('central_heating')
        self._total_rent = Decimal(general_data.get('obj_totalRent') or '0.0')
        self._base_rent = Decimal(general_data.get('obj_baseRent'))
        self._year_construction = int(
            general_data.get('obj_yearConstructed') or 1920)
        self._living_space = float(general_data.get('obj_livingSpace'))
        self._zipcode = general_data.get('obj_zipCode')
        self._condition = general_data.get('obj_condition')
        self._pets_allowed = general_data.get('obj_petsAllowed')
        self._internet_down_speed = general_data.get(
            'obj_telekomDownloadSpeed')
        self._has_kitchen = general_data.get('obj_hasKitchen')
        self._has_garden = general_data.get('obj_hasGarden')
        self._no_rooms = float(general_data.get('obj_noRooms') or -1)
        self._no_subways = 0
        self._no_trains = 0
        self._no_supermarkets = 0

        # SCORE
        self._score = 0
        self._score_calculator = score_calculator

        # GEO DATA
        self._lat = geo_data.lat
        self._lng = geo_data.lng
def _ios_format_data(cmd_outputs: json) -> json:
    """
    This function will retrieve data from differents commands outputs and gegroup them in a structured data format.
    Three command are executed on devices
        -> show ip ospf neighbor detail
        -> show ip ospf interface
        -> show ip ospf

    :param cmd_outputs:
    :return json: Structured data
    """

    return_val = dict()
    result = dict()
    mapping_instance_vrf = dict()
    router_id = dict()

    if OSPF_RIB_KEY in cmd_outputs.keys():
        for vrf in cmd_outputs.get(OSPF_RIB_KEY):
            result[vrf[0]] = dict()

            if vrf[2] == '':
                return_val['default'] = dict()
                mapping_instance_vrf[vrf[0]] = 'default'
                router_id['default'] = vrf[1]
            else:
                return_val[vrf[2]] = dict()
                mapping_instance_vrf[vrf[0]] = vrf[2]
                router_id[vrf[2]] = vrf[1]

    if OSPF_INT_KEY in cmd_outputs.keys():
        for interface in cmd_outputs.get(OSPF_INT_KEY):

            if interface[1] in result.keys():
                if interface[2] not in result.get(interface[1]).keys():
                    result[interface[1]][interface[2]] = dict()

                result[interface[1]][interface[2]][_mapping_interface_name(
                    interface[0])] = list()

    if OSPF_NEI_KEY in cmd_outputs.keys() and OSPF_RIB_KEY in cmd_outputs.keys(
    ):
        for neighbor in cmd_outputs.get(OSPF_NEI_KEY):
            for instance_id in result:
                for area in result.get(instance_id):
                    if _mapping_interface_name(neighbor[3]) in result.get(
                            instance_id).get(area).keys():

                        result[instance_id][area][_mapping_interface_name(
                            neighbor[3])].append({
                                'peer_rid': neighbor[0],
                                'peer_ip': neighbor[1],
                                'session_state': neighbor[4]
                            })

    for mapping in mapping_instance_vrf.keys():
        return_val[mapping_instance_vrf.get(mapping)] = result[mapping]

    return return_val, router_id
    def build_query(self, q: json) -> str:
        """
        Constructs a SQL query from a JSON input.
        Args:
            q ({}): JSON query input
        Returns (str): the SQL query string
        """
        try:
            # table name required
            table = q.get('table')
            if table is None:
                raise RequestParseException("No table named in request")
            elif table not in self.db_tables:
                raise RequestParseException(invalid_table_msg(table))

            if table == 'intake':
                from .models import IntakeRow
                self.col_names = [x.name.lower() for x in IntakeRow.ColNames]
            elif table == 'archive':
                from .models import ArchiveRow
                self.col_names = [x.name.lower() for x in ArchiveRow.ColNames]
            elif table == 'metadata':
                from .models import MetadataRow
                self.col_names = [x.name.lower() for x in MetadataRow.ColNames]
            elif table == 'txn_history':
                from .models import TxnHistoryRow
                self.col_names = [x.name.lower() for x in TxnHistoryRow.ColNames]
            elif table == 'reports':
                from .models import ReportsRow
                self.col_names = [x.name.lower() for x in ReportsRow.ColNames]
            elif table == 'violations':
                from .models import ViolationsRow
                self.col_names = [x.name.lower() for x in ViolationsRow.ColNames]
            else:
                raise RequestParseException("Requested table not found")

            # if columns not listed, assume all
            columns = q.get('columns')
            if columns is None:
                columns = '*'
            elif not isinstance(columns, list):
                raise RequestParseException("Columns must be present as list in request body")
            if columns != '*':
                for col in columns:
                    self.validate_column(col)

            query = f"SELECT {', '.join(columns)} FROM {table} "
            # get extended filtering
            where = q.get('where')
            if where is not None:
                query += 'WHERE '
                # iterate over operators
                query += self.parse_op(where)

            return query + ';'

        except RequestParseException as e:
            e.msg = invalid_request_msg(e.msg)
            raise e
Beispiel #12
0
 def try_connect(self, logger: AirbyteLogger, config: json):
     google_client = GoogleClient(
         credentials_json=config.get("credentials_json"),
         email=config.get("email"))
     site_urls = config.get("site_urls").replace(" ", "").split(",")
     for site in site_urls:
         google_client.get(method_name="get",
                           resource_name="sites",
                           params={"siteUrl": site})
Beispiel #13
0
 def __init__(self, league_name: str, data: json):
     self.league = league_name
     self._data = data
     self.sport = data.get('sport')
     self.baseUrl = data.get('base_url')
     self._teams = []
     self._conferences = []
     self._rankings = {}
     self._currentGames = []
Beispiel #14
0
 def __init__(self, api: GrocyApiClient, endpoint: str, parsed_json: json):
     self.__api = api
     self.__parsed_json = parsed_json
     self.__id = parse_int(parsed_json.get('id'))
     self.__endpoint = f"{endpoint}/{self.__id}"
     self.__userfields_enpoint = self.__endpoint.replace(
         'objects', 'userfields')
     self.__row_created_timestamp = parse_date(
         parsed_json.get('row_created_timestamp'))
 def sort_output_json(self, output_json: json, movie_names: List) -> List:
     """
     This function is to be used by parse_output_json to sort the dict.
     :rtype: Sorted list of movies
     """
     if self.imdb_col:
         return sorted(movie_names, key=lambda x: output_json.get(x).get("imdb_info").get(self.column))
     else:
         return sorted(movie_names, key=lambda x: output_json.get(x).get(self.column))
Beispiel #16
0
 def __init__(self, json_parameter: json):
     self.name = json_parameter['name']
     self.description = json_parameter.get('description')
     self.types = json_parameter.get('types')
     self.optional = json_parameter.get('optional', False)
     self.depth = json_parameter.get('depth', 0)
     self.type = None
     if 'types' in json_parameter:
         self.type = TsType.parse(json_parameter['types'])
     self.sub_parameters = []
Beispiel #17
0
 def __init__(self, player_id: str, data: json):
     self.playerID = player_id
     self._data = data
     self.league = data.get('league')
     self.sport = data.get('sport')
     self.baseUrl = data.get('base_url')
     self.firstName = None
     self.lastName = None
     self.position = None
     self.jerseyNumber = None
     self._team = None
     self.update_player_info()
def _juniper_ospf_converter(hostname: str(), cmd_outputs: json) -> OSPF:

    if cmd_outputs is None:
        return None

    ospf_vrf_lst = ListOSPFSessionsVRF(list())

    for vrf in cmd_outputs:
        if OSPF_RIB_KEY in cmd_outputs.get(
                vrf).keys() and OSPF_NEI_KEY in cmd_outputs.get(vrf).keys():

            area_in_vrf_dict = dict()

            ospf_area_lst = ListOSPFSessionsArea(ospf_sessions_area_lst=list())

            for nei in cmd_outputs.get(vrf).get(OSPF_NEI_KEY).get(
                    "ospf-neighbor-information")[0].get("ospf-neighbor"):

                if nei.get("ospf-area")[0].get("data") not in area_in_vrf_dict:
                    area_in_vrf_dict[nei.get("ospf-area")[0].get(
                        "data")] = list()

                area_in_vrf_dict.get(
                    nei.get("ospf-area")[0].get("data")).append(
                        OSPFSession(
                            hostname=hostname,
                            peer_rid=nei.get("neighbor-id")[0].get("data"),
                            peer_hostname=NOT_SET,
                            session_state=nei.get(
                                "ospf-neighbor-state")[0].get("data"),
                            local_interface=nei.get("interface-name")[0].get(
                                "data"),
                            peer_ip=nei.get("neighbor-address")[0].get(
                                "data")))

            for area in area_in_vrf_dict:
                ospf_area_lst.ospf_sessions_area_lst.append(
                    OSPFSessionsArea(
                        area_number=area,
                        ospf_sessions=ListOSPFSessions(
                            ospf_sessions_lst=area_in_vrf_dict.get(area))))

        ospf_vrf_lst.ospf_sessions_vrf_lst.append(
            OSPFSessionsVRF(
                vrf_name=vrf,
                router_id=cmd_outputs.get(vrf).get(OSPF_RIB_KEY).get(
                    "ospf-overview-information")[0].get("ospf-overview")
                [0].get("ospf-router-id")[0].get("data", NOT_SET),
                ospf_sessions_area_lst=ospf_area_lst))

    return OSPF(hostname=hostname, ospf_sessions_vrf_lst=ospf_vrf_lst)
Beispiel #19
0
def get_company_details(company: json, link=None, proxy=None):
    '''Extracts the company data from JSON response'''

    id = company.get('id', None)
    company_name = company.get('name', None)
    company_logo = company.get('logo', None)
    slogan = company.get('headline', None)
    description = company.get('description', None)

    if locations := get_by_path(company,
                                ('products', 0, 'available_countries'),
                                default=None):
        locations = '; '.join(
            [location['name'].strip() for location in locations if locations])
Beispiel #20
0
    def get_body(body: json) -> APIBodyModel:
        """
        Extracts the contents from the body json. Either raw or urlencoded
        :param body: the current APIModel object being explored
        :return: instance of APIBodyModel
        """
        api_body = APIBodyModel()
        api_body.mode = body.get(MODE, '')
        if body.get(RAW, None) is not None:
            api_body.raw = body.get(RAW)
        elif body.get(api_body.mode, None) is not None:
            api_body.key_values = DocumentGenerator.get_key_values(body.get(api_body.mode))

        return api_body
Beispiel #21
0
 def _get_contact(self, contact_data: json) -> iter:
     contact_all = contact_data.get('linkmanList')
     gname_map: dict = contact_data.get('uuidGuuidGnameMap')
     if contact_all is None or len(contact_all) == 0:
         self._logger.error("No contact in this account.")
         return
     for line_one in contact_all:
         contact_id = line_one.get('uuid')
         data_one = CONTACT_ONE(self._userid, contact_id, self.task, self.task.apptype)
         data_one.phone = line_one.get('mobile')
         data_one.email = line_one.get('email')
         data_one.nickname = line_one.get('name')
         data_one.group = gname_map[contact_id][0][0]['groupName']
         yield data_one
def _cumulus_lldp_converter(hostname: str(), cmd_output: json) -> ListLLDP:

    if cmd_output is None or cmd_output == "":
        return None

    lldp_neighbors_lst = ListLLDP(lldp_neighbors_lst=list())

    if "lldp" in cmd_output.keys():
        if "interface" in cmd_output.get('lldp')[0].keys():
            for lldp_neighbor in cmd_output.get('lldp')[0].get("interface"):

                if lldp_neighbor.get("via", NOT_SET) == "LLDP":

                    neighbor_type_lst = list()

                    if lldp_neighbor.get("chassis",
                                         NOT_SET)[0].get("descr",
                                                         NOT_SET) == NOT_SET:
                        neighbor_os = NOT_SET
                    else:
                        neighbor_os = lldp_neighbor.get(
                            "chassis",
                            NOT_SET)[0].get("descr",
                                            NOT_SET)[0].get("value", NOT_SET)

                    for capability in lldp_neighbor.get(
                            "chassis", NOT_SET)[0].get("capability", NOT_SET):
                        neighbor_type_lst.append(
                            capability.get("type", NOT_SET))

                    lldp_neighbors_lst.lldp_neighbors_lst.append(
                        LLDP(local_name=hostname,
                             local_port=_mapping_interface_name(
                                 lldp_neighbor.get("name", NOT_SET)),
                             neighbor_mgmt_ip=lldp_neighbor.get(
                                 "chassis",
                                 NOT_SET)[0].get("mgmt-ip", NOT_SET)[0].get(
                                     "value", NOT_SET),
                             neighbor_name=lldp_neighbor.get(
                                 "chassis",
                                 NOT_SET)[0].get("name", NOT_SET)[0].get(
                                     "value", NOT_SET),
                             neighbor_port=_mapping_interface_name(
                                 lldp_neighbor.get("port", NOT_SET)[0].get(
                                     "id", NOT_SET)[0].get("value", NOT_SET)),
                             neighbor_os=neighbor_os,
                             neighbor_type=neighbor_type_lst))

    return lldp_neighbors_lst
Beispiel #23
0
 def __init__(self, game_id: str, data: json):
     self.gameID = game_id
     self._data = data
     self.league = data.get('league')
     self.sport = data.get('sport')
     self.baseUrl = data.get('base_url')
     self._awayTeam = None
     self._homeTeam = None
     self.winProbability = {}
     self.spread = None
     self.overUnder = None
     self.venue = None
     self.attendance = None
     self.broadcast = None
     self._make_game()
Beispiel #24
0
def _compare_bond(host_keys, hostname, bond_host_data:None, bond_yaml_data:json) -> bool:

    if bond_yaml_data is None:
        return False

    verity_bonds_lst = ListBOND(
        bonds_lst=list()
    )

    if BOND_DATA_HOST_KEY in host_keys and hostname in bond_yaml_data.keys():
        for bond in bond_yaml_data.get(hostname):

            ports_members = list()
            for port in bond.get("ports_members", NOT_SET):
                ports_members.append(
                    _mapping_interface_name(
                        port
                    )
                )

            verity_bonds_lst.bonds_lst.append(
                BOND(
                    bond_name=bond.get("bond_name", NOT_SET),
                    ports_members=ports_members,
                    vlans_members=bond.get("vlans_members", list()),
                    native_vlan=bond.get("native_vlan", NOT_SET),
                    mode=bond.get("mode", NOT_SET),
                )
            )

        return verity_bonds_lst == bond_host_data

    else:
        print(f"{HEADER_GET} {hostname} is not present in {PATH_TO_VERITY_FILES}/{TEST_TO_EXC_BOND_KEY}.")
        return False
Beispiel #25
0
def start_dbg(config: json):
    global mod

    mod = WAModule.from_file(config['program'], out=config['out'])
    filtered = filter(lambda c: c.get('enable', True), config['devices'])
    dbgs = []
    for c in filtered:
        d = load_device(c)
        deb = Debugger(d, mod)
        deb.policies = c.get('policy', [])
        dbgs.append(deb)

    _loc = next((d for d in dbgs if d.device.is_local), None)
    _rmt = next((d for d in dbgs if d.device.is_remote), None)
    if _loc is not None:
        if _rmt is None:
            raise ValueError(
                f'configuration error: function proxy requires a remote device. Enable a remote device'
            )
        proxy_config = {}
        proxy_config['proxy'] = config.get('proxy', [])
        proxy_config['host'] = _rmt.device.host
        proxy_config['port'] = _rmt.device.port
        _loc.add_proxyconfig(proxy_config)
    return Test(_rmt, _loc)
def _napalm_lldp_converter(hostname: str(), cmd_output: json) -> ListLLDP:

    if cmd_output is None or cmd_output == "":
        return None

    lldp_neighbors_lst = ListLLDP(lldp_neighbors_lst=list())

    if "get_lldp_neighbors_detail" in cmd_output.keys():
        for interface_name, facts in cmd_output.get(
                "get_lldp_neighbors_detail", NOT_SET).items():

            for neighbors in facts:

                lldp_neighbors_lst.lldp_neighbors_lst.append(
                    LLDP(local_name=hostname,
                         local_port=_mapping_interface_name(interface_name),
                         neighbor_mgmt_ip=NOT_SET,
                         neighbor_name=neighbors.get('remote_system_name',
                                                     NOT_SET),
                         neighbor_port=_mapping_interface_name(
                             neighbors.get('remote_port', NOT_SET)),
                         neighbor_os=neighbors.get('remote_system_description',
                                                   NOT_SET),
                         neighbor_type=_mapping_sys_capabilities(
                             neighbors.get('remote_system_capab', NOT_SET))))

    return lldp_neighbors_lst
Beispiel #27
0
def callback_delay_docker(ch, method, properties, body: json):
    instance_id = body.get('id')
    delay_container(instance_id)

    ch.basic_ack(delivery_tag=method.delivery_tag)

    callback_get_docker_info(instance_id)
Beispiel #28
0
def handle_status_page_update(user_id: str, channel_id: str, submission: json,
                              response_url: str, state: json):
    incident_id = state
    incident = Incident.objects.get(pk=incident_id)
    statuspage_incident_id, created = IncidentExtension.objects.get_or_create(
        incident=incident, key='statuspage_incident_id')

    vars = {
        'name':
        submission['name'],
        'status':
        submission['incident_status'],
        'message':
        submission['message'] or '',
        'impact_override':
        submission['impact_override'] or '',
        'wants_twitter_update':
        bool(submission.get('wants_twitter_update', "False") == "True"),
    }
    try:
        if statuspage_incident_id.value:
            get_status_page_conn().incidents.update(
                incident_id=statuspage_incident_id.value, **vars)
        else:
            response = get_status_page_conn().incidents.create(**vars)
            statuspage_incident_id.value = response['id']
            statuspage_incident_id.save()

        msg = f'The status page has been updated ЁЯСН'

    except Exception as ex:
        msg = f'тЪая╕П {repr(ex)}'

    send_ephemeral_message(channel_id, user_id, msg)
Beispiel #29
0
    def ComputAggregFromSvc(self, data: json):
        """entry point called from worker"""
        self.stopRequested = False

        # load params
        if data is None or data.get("param") is None or data["param"] == {}:
            t.LogError("wrong data")
        params = data["param"]

        # Stop request
        if params.get("StopMe") is True:
            self.stopRequested = True
            return

        # load parameters (global trace, then params.trace_flag)
        if RefManager.GetInstance().GetRef("calcAgg_trace_flag") is None:
            trace_flag = False
        else:
            trace_flag = RefManager.GetInstance().GetRef("calcAgg_trace_flag")
        if params.get("trace_flag") is not None:
            trace_flag = params["trace_flag"]

        # load other params
        is_tmp = False
        ret = []
        if params.get("is_tmp") is not None:
            is_tmp = params["is_tmp"]

        # run now
        try:
            ret = self._computeAggreg(is_tmp, trace_flag)
            return ret

        except Exception as inst:
            t.LogCritical(inst)
Beispiel #30
0
    def check_config(self, logger: AirbyteLogger, config_path: str, config: json) -> AirbyteConnectionStatus:
        token = {"refresh_token": config["refresh_token"], "token_type": "Bearer", "access_token": "wrong", "expires_in": "-30"}
        extra = {"client_id": config["client_id"], "client_secret": config["client_secret"]}

        sandbox = bool(config.get("sandbox", False))

        user_agent = config["user_agent"]
        realm_id = config["realm_id"]
        session = OAuth2Session(
            config["client_id"],
            token=token,
            auto_refresh_url=TOKEN_REFRESH_URL,
            auto_refresh_kwargs=extra,
            token_updater=self._write_config,
        )

        endpoint = f"/v3/company/{realm_id}/query"
        params = {"query": "SELECT * FROM CompanyInfo"}
        headers = {"Accept": "application/json", "User-Agent": user_agent}

        if sandbox:
            full_url = SANDBOX_ENDPOINT_BASE + endpoint
        else:
            full_url = PROD_ENDPOINT_BASE + endpoint

        try:
            session.request("GET", full_url, headers=headers, params=params)
            return AirbyteConnectionStatus(status=Status.SUCCEEDED)
        except Exception as e:
            return AirbyteConnectionStatus(status=Status.FAILED, message=f"An exception occurred: {str(e)}")
def _nexus_cdp_converter(hostname:str(), cmd_output:json) -> ListCDP:

    cdp_neighbors_lst = ListCDP(list())

    if "TABLE_cdp_neighbor_detail_info" in cmd_output.keys():

        for cdp_neighbor in cmd_output.get('TABLE_cdp_neighbor_detail_info', NOT_SET).get(
                "ROW_cdp_neighbor_detail_info", NOT_SET):

                neighbor_type_lst = list()

                for sys_capability in cdp_neighbor.get("capability", NOT_SET):
                    neighbor_type_lst.append(_mapping_sys_capabilities(sys_capability))

                lldp_obj = CDP(
                    local_name=hostname,
                    local_port=_mapping_interface_name(cdp_neighbor.get("intf_id", NOT_SET)),
                    neighbor_mgmt_ip=cdp_neighbor.get("v4addr", NOT_SET),
                    neighbor_name=cdp_neighbor.get("device_id", NOT_SET),
                    neighbor_port=_mapping_interface_name(cdp_neighbor.get("port_id", NOT_SET)),
                    neighbor_os=cdp_neighbor.get("version", NOT_SET),
                    neighbor_type=neighbor_type_lst
                )

                cdp_neighbors_lst.cdp_neighbors_lst.append(lldp_obj)

    return cdp_neighbors_lst
Beispiel #32
0
 def get_chat_id(parsed_json: json) -> None or int:
     if not parsed_json:
         return None
     try:
         chat_id: int = parsed_json.get("message").get("chat").get("id")
     except BaseException as e:
         print('TelegramBot: Failed to get chat id from: {}: {}'.format(parsed_json, e))  # Log Error
         return None
     return chat_id