當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。