def config_ambiente(user, hosts, ambientes):
    #ip_config
    ip_config = IPConfig()
    ip_config.subnet = hosts.get("REDE")
    ip_config.new_prefix = hosts.get("PREFIX")
    if hosts.get("VERSION")=="ipv4":
        ip_config.type = IP_VERSION.IPv4[0]
    elif hosts.get("VERSION")=="ipv6":
        ip_config.type = IP_VERSION.IPv6[0]
    tiporede = TipoRede()
    tipo = tiporede.get_by_name(hosts.get("TIPO"))
    ip_config.network_type = tipo

    ip_config.save()

    #ambiente
    config_environment = ConfigEnvironment()
    amb_log = AmbienteLogico()
    div = DivisaoDc()
    amb_log = amb_log.get_by_name(ambientes.get("LOG"))
    div = div.get_by_name(ambientes.get("DC"))
    for j in Ambiente().search(div.id, amb_log.id):
        if j.grupo_l3.nome==ambientes.get("L3"):
            config_environment.environment = j
            
    config_environment.ip_config = ip_config

    config_environment.save()
示例#2
0
def config_ambiente(user, hosts, ambientes):
    # ip_config
    ip_config = IPConfig()
    ip_config.subnet = hosts.get('REDE')
    ip_config.new_prefix = hosts.get('PREFIX')
    if hosts.get('VERSION') == 'ipv4':
        ip_config.type = IP_VERSION.IPv4[0]
    elif hosts.get('VERSION') == 'ipv6':
        ip_config.type = IP_VERSION.IPv6[0]
    tiporede = TipoRede()
    tipo = tiporede.get_by_name(hosts.get('TIPO'))
    ip_config.network_type = tipo

    ip_config.save()

    # ambiente
    config_environment = ConfigEnvironment()
    amb_log = AmbienteLogico()
    div = DivisaoDc()
    amb_log = amb_log.get_by_name(ambientes.get('LOG'))
    div = div.get_by_name(ambientes.get('DC'))
    for j in Ambiente().search(div.id, amb_log.id):
        if j.grupo_l3.nome == ambientes.get('L3'):
            config_environment.environment = j

    config_environment.ip_config = ip_config

    config_environment.save()
def config_ambiente(user, hosts, ambientes):
    #ip_config
    ip_config = IPConfig()
    ip_config.subnet = hosts.get("REDE")
    ip_config.new_prefix = hosts.get("PREFIX")
    if hosts.get("VERSION") == "ipv4":
        ip_config.type = IP_VERSION.IPv4[0]
    elif hosts.get("VERSION") == "ipv6":
        ip_config.type = IP_VERSION.IPv6[0]
    tiporede = TipoRede()
    tipo = tiporede.get_by_name(hosts.get("TIPO"))
    ip_config.network_type = tipo

    ip_config.save()

    #ambiente
    config_environment = ConfigEnvironment()
    amb_log = AmbienteLogico()
    div = DivisaoDc()
    amb_log = amb_log.get_by_name(ambientes.get("LOG"))
    div = div.get_by_name(ambientes.get("DC"))
    for j in Ambiente().search(div.id, amb_log.id):
        if j.grupo_l3.nome == ambientes.get("L3"):
            config_environment.environment = j

    config_environment.ip_config = ip_config

    config_environment.save()
    def handle_post(self, request, user, *args, **kwargs):
        """Treat POST requests to add new Environment Configuration Prefix

        URL: environment/configuration/add
        """

        try:

            self._validate_permission(user)

            xml_map, _ = loads(request.raw_post_data)

            networkapi_map = xml_map.get('networkapi')

            self._validate_xml_networkapi(networkapi_map)

            network_map = networkapi_map.get('ambiente')

            self._validate_xml_network(network_map)

            # Get XML data
            network = network_map.get('network')
            id_environment = network_map.get('id_environment')
            ip_version = network_map.get('ip_version')
            network_type = network_map.get('network_type')
            prefix = network_map.get('prefix')

            self._validate_network(network, prefix)

            self._validate_environment_id(id_environment)

            self._validate_ip_version(ip_version)

            self._validate_network_type(network_type)

            self._validate_prefix_by_net_type(prefix, ip_version)

            environment = Ambiente().get_by_pk(id_environment)

            network_type = TipoRede.get_by_pk(network_type)

            ip_config = IPConfig()
            ip_config.subnet = network
            ip_config.new_prefix = prefix
            ip_config.type = ip_version
            ip_config.network_type = network_type

            ip_config.save()

            config_environment = ConfigEnvironment()
            config_environment.environment = environment
            config_environment.ip_config = ip_config

            config_environment.save()

            return self.response(dumps_networkapi({'network': network_map}))

        except PermissionError:
            return self.not_authorized()

        except AmbienteNotFoundError, e:
            return self.response_error(112)