예제 #1
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()
예제 #2
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()
예제 #3
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...")
    # Generate (nginx) string of the configuration
    string_config_file = nginx_configuration.accept(file_exporter())
    print(string_config_file)
                           (10, '', 'NginxDevice_pool'): {'ackedstate': 0,
                                                          'cifs': {'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...")
    # Generate (nginx) string of the configuration
    string_config_file = nginx_configuration.accept(file_exporter())
    print(string_config_file)