Ejemplo n.º 1
0
with open(filename, mode="r") as file:
    # The FullLoader parameter handles the conversion from YAML
    # scalar values to Python the dictionary format
    config = yaml.load(file, Loader=yaml.FullLoader)

    cloudFlare = CloudFlare(email=config['email'],
                            apikey=config['apiKey'],
                            zone=config['zone'])
    currentIp = cloudFlare._getIp()
    lastIp = config.get('lastIp', "NOT")
    if currentIp != lastIp:
        config.update({'lastIp': currentIp})
        logger.info('Ip is changed ' + lastIp + ' It will be updated ' +
                    currentIp)

        with open(filename, mode='w') as fileToWrite:
            yaml.safe_dump(config,
                           fileToWrite,
                           encoding='utf-8',
                           allow_unicode=True)
            cloudFlare.updateRecordIpById(
                "9ccdfe71e7913f4ec32bc74a70546b64")  #root
            cloudFlare.updateRecordIpById(
                "aba7977d352ada21e607cc1f3afe6209")  #www
            cloudFlare.updateRecordIpById(
                "1a3d2848a0d53386c9f4521f241ccf2b")  #mail
            cloudFlare.updateRecordIpById(
                "e5c5bd5c6b8902d20eefde06485687e4")  #storage
            cloudFlare.updateRecordIpById(
                "d43fb7f301ada8d107e1201716fef0f7")  #development