def deviceHealth(device, interfaces, configuration):
    logger.log("\n---- deviceHealth with parameters\n--> 'device' : {}\n--> 'interfaces' : {}\n--> 'configuration' : {}".format(device, interfaces, configuration))

    nginx_device = NginxDevice(device)

    # Try to ping first
    logger.log("Ping {}...".format(nginx_device.host_ip))
    if not ConnectivityChecking.ping(nginx_device.host_ip):
        return return_transient(0, faults=[Fault([], FaultCode.DeviceNotReachable, "Device not responding.").value()])
    logger.log("Ping OK!")

    # logger.log("Checking device status...")
    # status, device_status = nginx_device.check_device_status()
    #
    # logger.log("Status: {} ; Device: {}".format(status, device_status))
    #
    # if not status or device_status != 0:
    #     return return_transient(50, faults=[Fault([], FaultCode.AgentNotReachable, "Agent not responding.").value()])

    status, score = nginx_device.check_device_status()

    if not status:
        return return_transient(50, faults=[Fault([], FaultCode.AgentNotReachable, "Agent not responding.").value()])

    return return_ok(score=score)
Beispiel #2
0
def deviceHealth(device, interfaces, configuration):
    logger.log(
        "\n---- deviceHealth with parameters\n--> 'device' : {}\n--> 'interfaces' : {}\n--> 'configuration' : {}"
        .format(device, interfaces, configuration))

    nginx_device = NginxDevice(device)

    # Try to ping first
    logger.log("Ping {}...".format(nginx_device.host_ip))
    if not ConnectivityChecking.ping(nginx_device.host_ip):
        return return_transient(0,
                                faults=[
                                    Fault([], FaultCode.DeviceNotReachable,
                                          "Device not responding.").value()
                                ])
    logger.log("Ping OK!")

    # logger.log("Checking device status...")
    # status, device_status = nginx_device.check_device_status()
    #
    # logger.log("Status: {} ; Device: {}".format(status, device_status))
    #
    # if not status or device_status != 0:
    #     return return_transient(50, faults=[Fault([], FaultCode.AgentNotReachable, "Agent not responding.").value()])

    status, score = nginx_device.check_device_status()

    if not status:
        return return_transient(50,
                                faults=[
                                    Fault([], FaultCode.AgentNotReachable,
                                          "Agent not responding.").value()
                                ])

    return return_ok(score=score)
Beispiel #3
0
def serviceModify(device, configuration):
    logger.log(
        "\n---- serviceModify with parameters\n--> 'device' : {}\n--> 'configuration' : {}"
        .format(device, configuration))
    logger.log("Initialize the configurations...")
    # Convert configuration into API object
    api_config = Configuration(configuration)
    logger.log("> Configuration\n{}".format(api_config))

    # Create NginxDevice
    nginx_device = NginxDevice(device)
    logger.log("> Device\n{}".format(nginx_device))

    # Convert configuration into NGINX objects
    parser = ConfigurationParser()
    parser.from_API_configuration(api_config)
    nginx_configurations = parser.get_nginx_configurations()
    management_configuration = parser.get_management_configuration()
    logger.log("Nginxconfig: {}".format(nginx_configurations))
    logger.log("Management: {}".format(management_configuration))
    https_enable = management_configuration['https']

    if not https_enable:
        nginx_device.disable_https()

    logger.log("Configuration: {} (len {})".format(nginx_configurations,
                                                   len(nginx_configurations)))

    for nginx_configuration in nginx_configurations:
        logger.log(">> For configuration {}".format(nginx_configuration.name))
        logger.log("Generating the string...")
        # Generate (nginx) string of the configuration
        string_config_file = nginx_configuration.accept(file_exporter())

        logger.log("Getting the list of the sites...")
        # Get the list of existing configurations
        status, sites = nginx_device.get_site_list(all_available_sites=True)
        logger.log('Status: {} ; Sites: {}'.format(status, sites))

        if status:
            logger.log("Pushing the configuration...")
            # Push
            if nginx_configuration.name in sites:
                logger.log("Update '{}'".format(nginx_configuration.name))
                nginx_device.update_site_config(
                    nginx_configuration.name,
                    string_config_file,
                    enable=nginx_configuration.enabled)
            else:
                logger.log("Add '{}'".format(nginx_configuration.name))
                nginx_device.create_site_config(
                    nginx_configuration.name,
                    string_config_file,
                    enable=nginx_configuration.enabled)

    return return_ok()
def serviceModify(device, configuration):
    logger.log("\n---- serviceModify with parameters\n--> 'device' : {}\n--> 'configuration' : {}".format(device, configuration))
    logger.log("Initialize the configurations...")
    # Convert configuration into API object
    api_config = Configuration(configuration)
    logger.log("> Configuration\n{}".format(api_config))

    # Create NginxDevice
    nginx_device = NginxDevice(device)
    logger.log("> Device\n{}".format(nginx_device))

    # Convert configuration into NGINX objects
    parser = ConfigurationParser()
    parser.from_API_configuration(api_config)
    nginx_configurations = parser.get_nginx_configurations()
    management_configuration = parser.get_management_configuration()
    logger.log("Nginxconfig: {}".format(nginx_configurations))
    logger.log("Management: {}".format(management_configuration))
    https_enable = management_configuration['https']

    if not https_enable:
        nginx_device.disable_https()

    logger.log("Configuration: {} (len {})".format(nginx_configurations, len(nginx_configurations)))

    for nginx_configuration in nginx_configurations:
        logger.log(">> For configuration {}".format(nginx_configuration.name))
        logger.log("Generating the string...")
        # Generate (nginx) string of the configuration
        string_config_file = nginx_configuration.accept(file_exporter())

        logger.log("Getting the list of the sites...")
        # Get the list of existing configurations
        status, sites = nginx_device.get_site_list(all_available_sites=True)
        logger.log('Status: {} ; Sites: {}'.format(status, sites))

        if status:
            logger.log("Pushing the configuration...")
            # Push
            if nginx_configuration.name in sites:
                logger.log("Update '{}'".format(nginx_configuration.name))
                nginx_device.update_site_config(nginx_configuration.name, string_config_file, enable=nginx_configuration.enabled)
            else:
                logger.log("Add '{}'".format(nginx_configuration.name))
                nginx_device.create_site_config(nginx_configuration.name, string_config_file, enable=nginx_configuration.enabled)

    return return_ok()
Beispiel #5
0
                },
                'state': 1,
                'transaction': 0
            }
        }
    }
}

# print("\n---- serviceModify with parameters\n--> 'device' : {}\n--> 'configuration' : {}".format(device, configuration))
# print("Initialize the configurations...")
# # Convert configuration into API object
# api_config = Configuration(configuration)
# print("> Configuration\n{}".format(api_config))
#
# Create NginxDevice
nginx_device = NginxDevice(device)
print("> Device\n{}".format(nginx_device))

nginx_device.disable_https()

print("PING")
status, device_status = nginx_device.check_device_status()
print(status)
print(device_status)

# # Convert configuration into NGINX objects
# nginx_configurations, management_configuration = ConfigurationParser.from_API_configuration(api_config)
# https_enable = management_configuration['https']
#

# if not https_enable:
Beispiel #6
0
                    'NginxDevice_Device_1': 'eth2'
                },
                'state': 1,
                'transaction': 0
            }
        }
    }
}

print("Initialize the configurations...")
# Convert configuration into API object
api_config = Configuration(configuration)
print("> Configuration\n{}".format(api_config))

# Create NginxDevice
nginx_device = NginxDevice(device)
print("> Device\n{}".format(nginx_device))

# Convert configuration into NGINX objects
parser = ConfigurationParser()
parser.from_API_configuration(api_config)
nginx_configurations = parser.get_nginx_configurations()
management_configuration = parser.get_management_configuration()
https_enable = management_configuration['https']

print("Configuration: {} (len {})".format(nginx_configurations,
                                          len(nginx_configurations)))

for nginx_configuration in nginx_configurations:
    print(">> For configuration {}".format(nginx_configuration.name))
    print("Generating the string...")
Beispiel #7
0
                                                            'state': 1,
                                                            'transaction': 0},
                           (10, '', 'NginxDevice_pool'): {'ackedstate': 0,
                                                          'cifs': {'NginxDevice_Device_1': 'eth2'},
                                                          'state': 1,
                                                          'transaction': 0}}}}


# print("\n---- serviceModify with parameters\n--> 'device' : {}\n--> 'configuration' : {}".format(device, configuration))
# print("Initialize the configurations...")
# # Convert configuration into API object
# api_config = Configuration(configuration)
# print("> Configuration\n{}".format(api_config))
#
# Create NginxDevice
nginx_device = NginxDevice(device)
print("> Device\n{}".format(nginx_device))

nginx_device.disable_https()

print("PING")
status, device_status = nginx_device.check_device_status()
print(status)
print(device_status)

# # Convert configuration into NGINX objects
# nginx_configurations, management_configuration = ConfigurationParser.from_API_configuration(api_config)
# https_enable = management_configuration['https']
#

# if not https_enable: