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


Python Interface.get_by_interface_equipment方法代码示例

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


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

示例1: search_interface_by_name_and_equipment

# 需要导入模块: from networkapi.interface.models import Interface [as 别名]
# 或者: from networkapi.interface.models.Interface import get_by_interface_equipment [as 别名]
    def search_interface_by_name_and_equipment(self, equipment_id, interface_name, is_new):
        """Obtém a interface do equipamento e retorna todas as interfaces ligadas no front e no back. """

        interface = Interface.get_by_interface_equipment(interface_name, equipment_id)
        interfaces = interface.search_front_back_interfaces()

        map_list = []
        for interface in interfaces:
            if is_new:
                map_list.append(self.get_new_interface_map(interface))
            else:
                map_list.append(self.get_interface_map(interface))

        if is_new:
            return self.response(dumps_networkapi({"interfaces": map_list}))
        else:
            return self.response(dumps_networkapi({"interface": map_list}))
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:19,代码来源:InterfaceResource.py

示例2: add_remove_check_list_vlan_trunk

# 需要导入模块: from networkapi.interface.models import Interface [as 别名]
# 或者: from networkapi.interface.models.Interface import get_by_interface_equipment [as 别名]
    def add_remove_check_list_vlan_trunk(self, user, networkapi_map, vlan_id, operation):

        equipment_map = networkapi_map.get('equipamento')
        if equipment_map is None:
            return self.response_error(105)

        try:
            name = equipment_map.get('nome')
            if name is None or name == '':
                self.log.error(u'Parameter nome is invalid. Value: %s.', name)
                raise InvalidValueError(None, 'nome', name)

            interface_name = equipment_map.get('nome_interface')
            if interface_name is None or interface_name == '':
                self.log.error(
                    u'Parameter nome_interface is invalid. Value: %s.', interface_name)
                raise InvalidValueError(None, 'nome_interface', interface_name)

            if operation != 'list':
                vlan = Vlan().get_by_pk(vlan_id)

            # Check existence
            equipment = Equipamento().get_by_name(name)

            equip_permission = AdminPermission.EQUIP_UPDATE_CONFIG_OPERATION
            admin_permission = AdminPermission.WRITE_OPERATION
            if operation in ['check', 'list']:
                equip_permission = AdminPermission.EQUIP_READ_OPERATION
                admin_permission = AdminPermission.READ_OPERATION

            if not has_perm(user,
                            AdminPermission.VLAN_ALTER_SCRIPT,
                            admin_permission,
                            None,
                            equipment.id,
                            equip_permission):
                return self.not_authorized()

            interface = Interface.get_by_interface_equipment(
                interface_name, equipment.id)

            if interface.ligacao_front is None:
                return self.response_error(139)

            protected = None
            if operation not in ['check', 'list']:
                protected = 0

            try:
                switch_interface = interface.get_switch_interface_from_host_interface(
                    protected)
            except InterfaceNotFoundError:
                return self.response_error(144)

            if not has_perm(user,
                            AdminPermission.VLAN_ALTER_SCRIPT,
                            admin_permission,
                            None,
                            switch_interface.equipamento_id,
                            equip_permission):
                return self.not_authorized()

            # configurador -T snmp_vlans_trunk -i <nomequip> -A “'int=<interface> add=<numvlan>'”
            # configurador -T snmp_vlans_trunk -i <nomequip> -A “'int=<interface> del=<numvlan>'”
            # configurador -T snmp_vlans_trunk -i <nomequip> -A “'int=<interface> check=<numvlan>'"
            # configurador -T snmp_vlans_trunk -i <nomequip> -A
            # “'int=<interface> list'"
            command = 'configurador -T snmp_vlans_trunk -i %s -A "\'int=%s %s' % (switch_interface.equipamento.nome,
                                                                                  switch_interface.interface,
                                                                                  operation)
            if operation != 'list':
                command = command + '=%d' % vlan.num_vlan

            command = command + '\'"'

            code, stdout, stderr = exec_script(command)
            if code == 0:
                map = dict()
                success_map = dict()
                success_map['codigo'] = '%04d' % code
                success_map['descricao'] = {'stdout': stdout, 'stderr': stderr}
                map['sucesso'] = success_map

                return self.response(dumps_networkapi(map))
            else:
                return self.response_error(2, stdout + stderr)

        except EquipamentoNotFoundError:
            return self.response_error(117, name)
        except InvalidValueError, e:
            return self.response_error(269, e.param, e.value)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:93,代码来源:VlanResource.py


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