当前位置: 首页>>代码示例>>Python>>正文


Python TipoRede.get_by_name方法代码示例

本文整理汇总了Python中networkapi.vlan.models.TipoRede.get_by_name方法的典型用法代码示例。如果您正苦于以下问题:Python TipoRede.get_by_name方法的具体用法?Python TipoRede.get_by_name怎么用?Python TipoRede.get_by_name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在networkapi.vlan.models.TipoRede的用法示例。


在下文中一共展示了TipoRede.get_by_name方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle_post

# 需要导入模块: from networkapi.vlan.models import TipoRede [as 别名]
# 或者: from networkapi.vlan.models.TipoRede import get_by_name [as 别名]
    def handle_post(self, request, user, *args, **kwargs):
        """Treat POST requests to add new network types.

        URL: /net_type/ 

        """

        try:
            # Check permission
            if not has_perm(user, AdminPermission.NETWORK_TYPE_MANAGEMENT, AdminPermission.WRITE_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                return self.not_authorized()

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

            # Get networkapi tag map
            networkapi_map = xml_map.get('networkapi')
            if networkapi_map is None:
                return self.response_error(3, u'There is no networkapi tag from request XML.')

            # Get net_type tag map
            net_type_map = networkapi_map.get('net_type')
            if net_type_map is None:
                return self.response_error(3, u'There is no tipo_rede tag from request XML.')

            # Valid name attribute
            name = net_type_map.get('name')
            if not is_valid_string_minsize(name, 3) or not is_valid_string_maxsize(name, 100):
                self.log.error(
                    u'Parameter %s is invalid. Value: %s.', 'name', name)
                raise InvalidValueError(None, 'name', name)

            net_type = TipoRede(tipo_rede=name)

            try:
                TipoRede.get_by_name(net_type.tipo_rede)
                raise NetworkTypeNameDuplicatedError(
                    None, u'Network type with name %s already exist' % net_type.tipo_rede)
            except NetworkTypeNotFoundError:
                pass

            try:
                net_type.save(user)
            except Exception, e:
                self.log.error(u'Failed to insert network type.')
                raise VlanError(e, u'Failed to insert network type.')

            net_type_map = dict()
            net_type_map['id'] = net_type.id

            return self.response(dumps_networkapi({'net_type': net_type_map}))
开发者ID:andrewsmedina,项目名称:GloboNetworkAPI,代码行数:55,代码来源:NetworkTypeResource.py

示例2: config_ambiente

# 需要导入模块: from networkapi.vlan.models import TipoRede [as 别名]
# 或者: from networkapi.vlan.models.TipoRede import get_by_name [as 别名]
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()
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:30,代码来源:RackAplicarConfigResource.py

示例3: criar_rede

# 需要导入模块: from networkapi.vlan.models import TipoRede [as 别名]
# 或者: from networkapi.vlan.models.TipoRede import get_by_name [as 别名]
def criar_rede(user, tipo_rede, variablestochangecore1, vlan, active=1):

    tiporede = TipoRede()
    net_id = tiporede.get_by_name(tipo_rede)
    network_type = tiporede.get_by_pk(net_id.id)

    network_ip = NetworkIPv4()
    network_ip.oct1, network_ip.oct2, network_ip.oct3, network_ip.oct4 = str(variablestochangecore1.get("REDE_IP")).split('.')
    network_ip.block = variablestochangecore1.get("REDE_MASK")
    network_ip.mask_oct1, network_ip.mask_oct2, network_ip.mask_oct3, network_ip.mask_oct4 = str(variablestochangecore1.get("NETMASK")).split('.')
    network_ip.broadcast = variablestochangecore1.get("BROADCAST")
    network_ip.vlan = vlan
    network_ip.network_type = network_type
    network_ip.ambient_vip = None
    network_ip.active = active

    destroy_cache_function([vlan.id])
    network_ip.save()
 
    return network_ip
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:22,代码来源:RackAplicarConfigResource.py

示例4: criar_rede_ipv6

# 需要导入模块: from networkapi.vlan.models import TipoRede [as 别名]
# 或者: from networkapi.vlan.models.TipoRede import get_by_name [as 别名]
def criar_rede_ipv6(user, tipo_rede, variablestochangecore1, vlan, active=1):

    tiporede = TipoRede()
    net_id = tiporede.get_by_name(tipo_rede)
    network_type = tiporede.get_by_pk(net_id.id)

    network_ip = NetworkIPv6()
    network_ip.vlan = vlan
    network_ip.network_type = network_type
    network_ip.ambient_vip = None
    network_ip.active = active
    network_ip.block = variablestochangecore1.get("REDE_MASK")
    
    while str(variablestochangecore1.get("REDE_IP")).endswith(":"):
        variablestochangecore1['REDE_IP'] = variablestochangecore1['REDE_IP'][:-1]

    while str(variablestochangecore1.get("NETMASK")).endswith(":"):
        variablestochangecore1['NETMASK'] = variablestochangecore1['NETMASK'][:-1]

    len_ip_ipv6 = len(str(variablestochangecore1.get("REDE_IP")).split(':'))
    len_mask = len(str(variablestochangecore1.get("NETMASK")).split(':'))

    while(8-len_ip_ipv6>0):#8-6=2--8-7=1--8-8=0
        len_ip_ipv6 = len_ip_ipv6 + 1
        variablestochangecore1['REDE_IP'] = variablestochangecore1.get("REDE_IP")+":0"

    while(8-len_mask>0):
        len_mask = len_mask + 1
        variablestochangecore1['NETMASK'] = variablestochangecore1.get("NETMASK")+":0"

    network_ip.block1, network_ip.block2, network_ip.block3, network_ip.block4, network_ip.block5, network_ip.block6, network_ip.block7, network_ip.block8 = str(variablestochangecore1.get("REDE_IP")).split(':')
    network_ip.mask1, network_ip.mask2, network_ip.mask3, network_ip.mask4, network_ip.mask5, network_ip.mask6, network_ip.mask7, network_ip.mask8 = str(variablestochangecore1.get("NETMASK")).split(':')

    destroy_cache_function([vlan.id])
    network_ip.save()
 
    return network_ip
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:39,代码来源:RackAplicarConfigResource.py

示例5: handle_put

# 需要导入模块: from networkapi.vlan.models import TipoRede [as 别名]
# 或者: from networkapi.vlan.models.TipoRede import get_by_name [as 别名]
    def handle_put(self, request, user, *args, **kwargs):
        """Treat PUT requests to edit network types.

        URL: /net_type/<id_net_type>/ 

        """

        try:
            # Check permission
            if not has_perm(user, AdminPermission.NETWORK_TYPE_MANAGEMENT, AdminPermission.WRITE_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                return self.not_authorized()

            # Get URL args
            id_net_type = kwargs.get('id_net_type')

            if not is_valid_int_greater_zero_param(id_net_type):
                self.log.error(
                    u'Parameter %s is invalid. Value: %s.', 'id_net_type', id_net_type)
                raise InvalidValueError(None, 'id_net_type', id_net_type)

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

            # Get networkapi tag map
            networkapi_map = xml_map.get('networkapi')
            if networkapi_map is None:
                return self.response_error(3, u'There is no networkapi tag from request XML.')

            # Get net_type tag map
            net_type_map = networkapi_map.get('net_type')
            if net_type_map is None:
                return self.response_error(3, u'There is no net_type tag from request XML.')

            # Valid name attribute
            name = net_type_map.get('name')
            if not is_valid_string_minsize(name, 3) or not is_valid_string_maxsize(name, 100):
                self.log.error(
                    u'Parameter %s is invalid. Value: %s.', 'name', name)
                raise InvalidValueError(None, 'name', name)

            net_type = TipoRede.get_by_pk(id_net_type)

            with distributedlock(LOCK_TYPE_NETWORK % id_net_type):

                try:
                    if name.lower() != net_type.tipo_rede.lower():
                        TipoRede.get_by_name(name)
                        raise NetworkTypeNameDuplicatedError(
                            None, u'Network type with name %s already exists' % name)
                except NetworkTypeNotFoundError:
                    pass

                net_type.tipo_rede = name
                try:
                    net_type.save(user)
                except Exception, e:
                    self.log.error(u'Failed to edit network type.')
                    raise VlanError(e, u'Failed to edit network type.')

            # Return empty response
            return self.response(dumps_networkapi({}))
开发者ID:andrewsmedina,项目名称:GloboNetworkAPI,代码行数:65,代码来源:NetworkTypeResource.py


注:本文中的networkapi.vlan.models.TipoRede.get_by_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。