def handle_post(self, request, user, *args, **kwargs):
        """Treat requests POST to add Division Dc.

        URL: divisiondc/
        """

        try:

            self.log.info('Add Division Dc')

            # User permission
            if not has_perm(user, AdminPermission.ENVIRONMENT_MANAGEMENT, AdminPermission.WRITE_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                raise UserNotAuthorizedError(None)

            # Load XML data
            xml_map, attrs_map = loads(request.raw_post_data)

            # XML data format
            networkapi_map = xml_map.get('networkapi')
            if networkapi_map is None:
                return self.response_error(3, u'There is no value to the networkapi tag  of XML request.')

            division_dc_map = networkapi_map.get('division_dc')
            if division_dc_map is None:
                return self.response_error(3, u'There is no value to the division_dc tag  of XML request.')

            # Get XML data
            name = division_dc_map.get('name')

            try:
                DivisaoDc.get_by_name(name)
                raise DivisaoDcNameDuplicatedError(
                    None, u'Já existe um divisào dc com o valor name %s.' % name)
            except DivisaoDcNotFoundError:
                pass

            division_dc = DivisaoDc()

            # set variables
            division_dc.nome = name

            try:
                # save Division Dc
                division_dc.save()
            except Exception, e:
                self.log.error(u'Failed to save the Division Dc.')
                raise AmbienteError(e, u'Failed to save the Division Dc.')

            division_dc_map = dict()
            division_dc_map['division_dc'] = model_to_dict(
                division_dc, exclude=['nome'])

            return self.response(dumps_networkapi(division_dc_map))
def criar_vlan(user, variablestochangecore1, ambientes, active=1):

    #get environment
    ambiente = Ambiente()
    divisaodc = DivisaoDc()
    divisaodc = divisaodc.get_by_name(ambientes.get('DC'))
    ambiente_log = AmbienteLogico()
    ambiente_log = ambiente_log.get_by_name(ambientes.get('LOG'))
    ambiente = ambiente.search(divisaodc.id, ambiente_log.id)
    for  amb in ambiente:
        if amb.grupo_l3.nome==ambientes.get('L3'):
            id_ambiente = amb
    # set vlan
    vlan = Vlan()
    vlan.acl_file_name = None
    vlan.acl_file_name_v6 = None
    vlan.num_vlan = variablestochangecore1.get("VLAN_NUM")
    vlan.nome = variablestochangecore1.get("VLAN_NAME")
    vlan.descricao = ""
    vlan.ambiente = id_ambiente
    vlan.ativada = active
    vlan.acl_valida = 0
    vlan.acl_valida_v6 = 0

    vlan.insert_vlan(user)

    return vlan
Пример #3
0
def criar_vlan(user, variablestochangecore1, ambientes, active=1):

    # get environment
    ambiente = Ambiente()
    divisaodc = DivisaoDc()
    divisaodc = divisaodc.get_by_name(ambientes.get('DC'))
    ambiente_log = AmbienteLogico()
    ambiente_log = ambiente_log.get_by_name(ambientes.get('LOG'))
    ambiente = ambiente.search(divisaodc.id, ambiente_log.id)
    for amb in ambiente:
        if amb.grupo_l3.nome == ambientes.get('L3'):
            id_ambiente = amb
    # set vlan
    vlan = Vlan()
    vlan.acl_file_name = None
    vlan.acl_file_name_v6 = None
    vlan.num_vlan = variablestochangecore1.get('VLAN_NUM')
    vlan.nome = variablestochangecore1.get('VLAN_NAME')
    vlan.descricao = ''
    vlan.ambiente = id_ambiente
    vlan.ativada = active
    vlan.acl_valida = 0
    vlan.acl_valida_v6 = 0

    vlan.insert_vlan(user)

    return vlan
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()
Пример #5
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_put(self, request, user, *args, **kwargs):
        """Treat requests PUT to edit Division Dc.

        URL: divisiondc/<id_divisiondc>/
        """
        try:

            self.log.info('Edit Division Dc')

            # User permission
            if not has_perm(user, AdminPermission.ENVIRONMENT_MANAGEMENT,
                            AdminPermission.WRITE_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                raise UserNotAuthorizedError(None)

            id_divisiondc = kwargs.get('id_divisiondc')

            # Load XML data
            xml_map, attrs_map = loads(request.raw_post_data)

            # XML data format
            networkapi_map = xml_map.get('networkapi')
            if networkapi_map is None:
                return self.response_error(
                    3,
                    u'There is no value to the networkapi tag  of XML request.'
                )

            division_dc_map = networkapi_map.get('division_dc')
            if division_dc_map is None:
                return self.response_error(
                    3,
                    u'There is no value to the division_dc tag  of XML request.'
                )

            # Get XML data
            name = division_dc_map.get('name')

            # Valid ID Division Dc
            if not is_valid_int_greater_zero_param(id_divisiondc):
                self.log.error(
                    u'The id_divisiondc parameter is not a valid value: %s.',
                    id_divisiondc)
                raise InvalidValueError(None, 'id_divisiondc', id_divisiondc)

            # Valid name
            if not is_valid_string_minsize(
                    name, 2) or not is_valid_string_maxsize(name, 80):
                self.log.error(u'Parameter name is invalid. Value: %s', name)
                raise InvalidValueError(None, 'name', name)

            # Find Division Dc by ID to check if it exist
            division_dc = DivisaoDc.get_by_pk(id_divisiondc)

            with distributedlock(LOCK_DC_DIVISION % id_divisiondc):

                try:
                    if division_dc.nome.lower() != name.lower():
                        DivisaoDc.get_by_name(name)
                        raise DivisaoDcNameDuplicatedError(
                            None,
                            u'Já existe um Divisão Dc com o valor name %s.' %
                            name)
                except DivisaoDcNotFoundError:
                    pass

                # set variables
                division_dc.nome = name

                try:
                    # update Division Dc
                    division_dc.save()
                except Exception, e:
                    self.log.error(u'Failed to update the Division Dc.')
                    raise AmbienteError(e,
                                        u'Failed to update the Division Dc.')

                return self.response(dumps_networkapi({}))

        except InvalidValueError, e:
            return self.response_error(269, e.param, e.value)
    def handle_put(self, request, user, *args, **kwargs):
        """Treat requests PUT to edit Division Dc.

        URL: divisiondc/<id_divisiondc>/
        """
        try:

            self.log.info("Edit Division Dc")

            # User permission
            if not has_perm(user, AdminPermission.ENVIRONMENT_MANAGEMENT, AdminPermission.WRITE_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                raise UserNotAuthorizedError(None)

            id_divisiondc = kwargs.get('id_divisiondc')

            # Load XML data
            xml_map, attrs_map = loads(request.raw_post_data)

            # XML data format
            networkapi_map = xml_map.get('networkapi')
            if networkapi_map is None:
                return self.response_error(3, u'There is no value to the networkapi tag  of XML request.')

            division_dc_map = networkapi_map.get('division_dc')
            if division_dc_map is None:
                return self.response_error(3, u'There is no value to the division_dc tag  of XML request.')

            # Get XML data
            name = division_dc_map.get('name')

            # Valid ID Division Dc
            if not is_valid_int_greater_zero_param(id_divisiondc):
                self.log.error(
                    u'The id_divisiondc parameter is not a valid value: %s.', id_divisiondc)
                raise InvalidValueError(None, 'id_divisiondc', id_divisiondc)

            # Valid name
            if not is_valid_string_minsize(name, 2) or not is_valid_string_maxsize(name, 80):
                self.log.error(u'Parameter name is invalid. Value: %s', name)
                raise InvalidValueError(None, 'name', name)

            # Find Division Dc by ID to check if it exist
            division_dc = DivisaoDc.get_by_pk(id_divisiondc)

            with distributedlock(LOCK_DC_DIVISION % id_divisiondc):

                try:
                    if division_dc.nome.lower() != name.lower():
                        DivisaoDc.get_by_name(name)
                        raise DivisaoDcNameDuplicatedError(
                            None, u'Já existe um Divisão Dc com o valor name %s.' % name)
                except DivisaoDcNotFoundError:
                    pass

                # set variables
                division_dc.nome = name

                try:
                    # update Division Dc
                    division_dc.save(user)
                except Exception, e:
                    self.log.error(u'Failed to update the Division Dc.')
                    raise AmbienteError(
                        e, u'Failed to update the Division Dc.')

                return self.response(dumps_networkapi({}))

        except InvalidValueError, e:
            return self.response_error(269, e.param, e.value)
    def handle_post(self, request, user, *args, **kwargs):
        """Treat requests POST to add Division Dc.

        URL: divisiondc/
        """

        try:

            self.log.info('Add Division Dc')

            # User permission
            if not has_perm(user, AdminPermission.ENVIRONMENT_MANAGEMENT,
                            AdminPermission.WRITE_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                raise UserNotAuthorizedError(None)

            # Load XML data
            xml_map, attrs_map = loads(request.raw_post_data)

            # XML data format
            networkapi_map = xml_map.get('networkapi')
            if networkapi_map is None:
                return self.response_error(
                    3,
                    u'There is no value to the networkapi tag  of XML request.'
                )

            division_dc_map = networkapi_map.get('division_dc')
            if division_dc_map is None:
                return self.response_error(
                    3,
                    u'There is no value to the division_dc tag  of XML request.'
                )

            # Get XML data
            name = division_dc_map.get('name')

            try:
                DivisaoDc.get_by_name(name)
                raise DivisaoDcNameDuplicatedError(
                    None,
                    u'Já existe um divisào dc com o valor name %s.' % name)
            except DivisaoDcNotFoundError:
                pass

            division_dc = DivisaoDc()

            # set variables
            division_dc.nome = name

            try:
                # save Division Dc
                division_dc.save()
            except Exception, e:
                self.log.error(u'Failed to save the Division Dc.')
                raise AmbienteError(e, u'Failed to save the Division Dc.')

            division_dc_map = dict()
            division_dc_map['division_dc'] = model_to_dict(division_dc,
                                                           exclude=['nome'])

            return self.response(dumps_networkapi(division_dc_map))