text_prompt
stringlengths 100
17.7k
⌀ | code_prompt
stringlengths 7
9.86k
⌀ |
---|---|
<SYSTEM_TASK:>
Get an instance of Api Vlan services facade.
<END_TASK>
<USER_TASK:>
Description:
def create_api_vlan(self):
"""Get an instance of Api Vlan services facade.""" |
return ApiVlan(
self.networkapi_url,
self.user,
self.password,
self.user_ldap) |
<SYSTEM_TASK:>
Get an instance of Api Vrf services facade.
<END_TASK>
<USER_TASK:>
Description:
def create_api_vrf(self):
"""Get an instance of Api Vrf services facade.""" |
return ApiVrf(
self.networkapi_url,
self.user,
self.password,
self.user_ldap) |
<SYSTEM_TASK:>
Get an instance of block rule services facade.
<END_TASK>
<USER_TASK:>
Description:
def create_rule(self):
"""Get an instance of block rule services facade.""" |
return BlockRule(
self.networkapi_url,
self.user,
self.password,
self.user_ldap) |
<SYSTEM_TASK:>
Get an instance of environment_vip services facade.
<END_TASK>
<USER_TASK:>
Description:
def create_environment_vip(self):
"""Get an instance of environment_vip services facade.""" |
return EnvironmentVIP(
self.networkapi_url,
self.user,
self.password,
self.user_ldap) |
<SYSTEM_TASK:>
Get an instance of equipamento services facade.
<END_TASK>
<USER_TASK:>
Description:
def create_equipamento(self):
"""Get an instance of equipamento services facade.""" |
return Equipamento(
self.networkapi_url,
self.user,
self.password,
self.user_ldap) |
<SYSTEM_TASK:>
Get an instance of equipamento_acesso services facade.
<END_TASK>
<USER_TASK:>
Description:
def create_equipamento_acesso(self):
"""Get an instance of equipamento_acesso services facade.""" |
return EquipamentoAcesso(
self.networkapi_url,
self.user,
self.password,
self.user_ldap) |
<SYSTEM_TASK:>
Get an instance of log services facade.
<END_TASK>
<USER_TASK:>
Description:
def create_log(self):
"""Get an instance of log services facade.""" |
return EventLog(
self.networkapi_url,
self.user,
self.password,
self.user_ldap) |
<SYSTEM_TASK:>
Get an instance of filter services facade.
<END_TASK>
<USER_TASK:>
Description:
def create_filter(self):
"""Get an instance of filter services facade.""" |
return Filter(
self.networkapi_url,
self.user,
self.password,
self.user_ldap) |
<SYSTEM_TASK:>
Get an instance of grupo_l3 services facade.
<END_TASK>
<USER_TASK:>
Description:
def create_grupo_l3(self):
"""Get an instance of grupo_l3 services facade.""" |
return GrupoL3(
self.networkapi_url,
self.user,
self.password,
self.user_ldap) |
<SYSTEM_TASK:>
Get an instance of grupo_usuario services facade.
<END_TASK>
<USER_TASK:>
Description:
def create_grupo_usuario(self):
"""Get an instance of grupo_usuario services facade.""" |
return GrupoUsuario(
self.networkapi_url,
self.user,
self.password,
self.user_ldap) |
<SYSTEM_TASK:>
Get an instance of grupo_virtual services facade.
<END_TASK>
<USER_TASK:>
Description:
def create_grupo_virtual(self):
"""Get an instance of grupo_virtual services facade.""" |
return GrupoVirtual(
self.networkapi_url,
self.user,
self.password,
self.user_ldap) |
<SYSTEM_TASK:>
Get an instance of interface services facade.
<END_TASK>
<USER_TASK:>
Description:
def create_interface(self):
"""Get an instance of interface services facade.""" |
return Interface(
self.networkapi_url,
self.user,
self.password,
self.user_ldap) |
<SYSTEM_TASK:>
Get an instance of ip services facade.
<END_TASK>
<USER_TASK:>
Description:
def create_ip(self):
"""Get an instance of ip services facade.""" |
return Ip(
self.networkapi_url,
self.user,
self.password,
self.user_ldap) |
<SYSTEM_TASK:>
Get an instance of marca services facade.
<END_TASK>
<USER_TASK:>
Description:
def create_marca(self):
"""Get an instance of marca services facade.""" |
return Marca(
self.networkapi_url,
self.user,
self.password,
self.user_ldap) |
<SYSTEM_TASK:>
Get an instance of modelo services facade.
<END_TASK>
<USER_TASK:>
Description:
def create_modelo(self):
"""Get an instance of modelo services facade.""" |
return Modelo(
self.networkapi_url,
self.user,
self.password,
self.user_ldap) |
<SYSTEM_TASK:>
Get an instance of DHCPRelayIPv4 services facade.
<END_TASK>
<USER_TASK:>
Description:
def create_dhcprelay_ipv4(self):
"""Get an instance of DHCPRelayIPv4 services facade.""" |
return DHCPRelayIPv4(
self.networkapi_url,
self.user,
self.password,
self.user_ldap) |
<SYSTEM_TASK:>
Get an instance of DHCPRelayIPv6 services facade.
<END_TASK>
<USER_TASK:>
Description:
def create_dhcprelay_ipv6(self):
"""Get an instance of DHCPRelayIPv6 services facade.""" |
return DHCPRelayIPv6(
self.networkapi_url,
self.user,
self.password,
self.user_ldap) |
<SYSTEM_TASK:>
Get an instance of option_pool services facade.
<END_TASK>
<USER_TASK:>
Description:
def create_option_pool(self):
"""Get an instance of option_pool services facade.""" |
return OptionPool(
self.networkapi_url,
self.user,
self.password,
self.user_ldap) |
<SYSTEM_TASK:>
Get an instance of option_vip services facade.
<END_TASK>
<USER_TASK:>
Description:
def create_option_vip(self):
"""Get an instance of option_vip services facade.""" |
return OptionVIP(
self.networkapi_url,
self.user,
self.password,
self.user_ldap) |
<SYSTEM_TASK:>
Get an instance of permissao_administrativa services facade.
<END_TASK>
<USER_TASK:>
Description:
def create_permissao_administrativa(self):
"""Get an instance of permissao_administrativa services facade.""" |
return PermissaoAdministrativa(
self.networkapi_url,
self.user,
self.password,
self.user_ldap) |
<SYSTEM_TASK:>
Get an instance of permission services facade.
<END_TASK>
<USER_TASK:>
Description:
def create_permission(self):
"""Get an instance of permission services facade.""" |
return Permission(
self.networkapi_url,
self.user,
self.password,
self.user_ldap) |
<SYSTEM_TASK:>
Get an instance of rack services facade.
<END_TASK>
<USER_TASK:>
Description:
def create_rack(self):
"""Get an instance of rack services facade.""" |
return Rack(
self.networkapi_url,
self.user,
self.password,
self.user_ldap) |
<SYSTEM_TASK:>
Get an instance of rackservers services facade.
<END_TASK>
<USER_TASK:>
Description:
def create_rackservers(self):
"""Get an instance of rackservers services facade.""" |
return RackServers(
self.networkapi_url,
self.user,
self.password,
self.user_ldap) |
<SYSTEM_TASK:>
Get an instance of roteiro services facade.
<END_TASK>
<USER_TASK:>
Description:
def create_roteiro(self):
"""Get an instance of roteiro services facade.""" |
return Roteiro(
self.networkapi_url,
self.user,
self.password,
self.user_ldap) |
<SYSTEM_TASK:>
Get an instance of Api System Variables services facade.
<END_TASK>
<USER_TASK:>
Description:
def create_system(self):
"""Get an instance of Api System Variables services facade.""" |
return System(
self.networkapi_url,
self.user,
self.password,
self.user_ldap) |
<SYSTEM_TASK:>
Get an instance of tipo_acesso services facade.
<END_TASK>
<USER_TASK:>
Description:
def create_tipo_acesso(self):
"""Get an instance of tipo_acesso services facade.""" |
return TipoAcesso(
self.networkapi_url,
self.user,
self.password,
self.user_ldap) |
<SYSTEM_TASK:>
Get an instance of tipo_rede services facade.
<END_TASK>
<USER_TASK:>
Description:
def create_tipo_rede(self):
"""Get an instance of tipo_rede services facade.""" |
return TipoRede(
self.networkapi_url,
self.user,
self.password,
self.user_ldap) |
<SYSTEM_TASK:>
Get an instance of tipo_roteiro services facade.
<END_TASK>
<USER_TASK:>
Description:
def create_tipo_roteiro(self):
"""Get an instance of tipo_roteiro services facade.""" |
return TipoRoteiro(
self.networkapi_url,
self.user,
self.password,
self.user_ldap) |
<SYSTEM_TASK:>
Get an instance of usuario services facade.
<END_TASK>
<USER_TASK:>
Description:
def create_usuario(self):
"""Get an instance of usuario services facade.""" |
return Usuario(
self.networkapi_url,
self.user,
self.password,
self.user_ldap) |
<SYSTEM_TASK:>
Get an instance of usuario_grupo services facade.
<END_TASK>
<USER_TASK:>
Description:
def create_usuario_grupo(self):
"""Get an instance of usuario_grupo services facade.""" |
return UsuarioGrupo(
self.networkapi_url,
self.user,
self.password,
self.user_ldap) |
<SYSTEM_TASK:>
Get an instance of vip services facade.
<END_TASK>
<USER_TASK:>
Description:
def create_vip(self):
"""Get an instance of vip services facade.""" |
return Vip(
self.networkapi_url,
self.user,
self.password,
self.user_ldap) |
<SYSTEM_TASK:>
Deploy network in equipments and set column 'active = 1' in tables redeipv6 ]
<END_TASK>
<USER_TASK:>
Description:
def deploy(self, id_networkv6):
"""Deploy network in equipments and set column 'active = 1' in tables redeipv6 ]
:param id_networkv6: ID for NetworkIPv6
:return: Equipments configuration output
""" |
data = dict()
uri = 'api/networkv6/%s/equipments/' % id_networkv6
return super(ApiNetworkIPv6, self).post(uri, data=data) |
<SYSTEM_TASK:>
List networks redeipv6 ]
<END_TASK>
<USER_TASK:>
Description:
def list(self, environment_vip=None):
"""List networks redeipv6 ]
:param environment_vip: environment vip to filter
:return: IPv6 Networks
""" |
uri = 'api/networkv6/?'
if environment_vip:
uri += 'environment_vip=%s' % environment_vip
return super(ApiNetworkIPv6, self).get(uri) |
<SYSTEM_TASK:>
Remove deployment of network in equipments and set column 'active = 0' in tables redeipv6 ]
<END_TASK>
<USER_TASK:>
Description:
def undeploy(self, id_networkv6):
"""Remove deployment of network in equipments and set column 'active = 0' in tables redeipv6 ]
:param id_networkv6: ID for NetworkIPv6
:return: Equipments configuration output
""" |
uri = 'api/networkv6/%s/equipments/' % id_networkv6
return super(ApiNetworkIPv6, self).delete(uri) |
<SYSTEM_TASK:>
Check available ipv6 in environment vip
<END_TASK>
<USER_TASK:>
Description:
def check_vip_ip(self, ip, environment_vip):
"""
Check available ipv6 in environment vip
""" |
uri = 'api/ipv6/ip/%s/environment-vip/%s/' % (ip, environment_vip)
return super(ApiNetworkIPv6, self).get(uri) |
<SYSTEM_TASK:>
Method to delete network-ipv6's by their ids
<END_TASK>
<USER_TASK:>
Description:
def delete(self, ids):
"""
Method to delete network-ipv6's by their ids
:param ids: Identifiers of network-ipv6's
:return: None
""" |
url = build_uri_with_ids('api/v3/networkv6/%s/', ids)
return super(ApiNetworkIPv6, self).delete(url) |
<SYSTEM_TASK:>
Method to update network-ipv6's
<END_TASK>
<USER_TASK:>
Description:
def update(self, networkipv6s):
"""
Method to update network-ipv6's
:param networkipv6s: List containing network-ipv6's desired to updated
:return: None
""" |
data = {'networks': networkipv6s}
networkipv6s_ids = [str(networkipv6.get('id'))
for networkipv6 in networkipv6s]
return super(ApiNetworkIPv6, self).put('api/v3/networkv6/%s/' %
';'.join(networkipv6s_ids), data) |
<SYSTEM_TASK:>
Method to create network-ipv6's
<END_TASK>
<USER_TASK:>
Description:
def create(self, networkipv6s):
"""
Method to create network-ipv6's
:param networkipv6s: List containing networkipv6's desired to be created on database
:return: None
""" |
data = {'networks': networkipv6s}
return super(ApiNetworkIPv6, self).post('api/v3/networkv6/', data) |
<SYSTEM_TASK:>
List all environment vips availables
<END_TASK>
<USER_TASK:>
Description:
def list_all_available(self, id_vlan):
"""
List all environment vips availables
:return: Following dictionary:
::
{'environment_vip': [{'id': <id>,
'finalidade_txt': <finalidade_txt>,
'cliente_txt': <cliente_txt>,
'ambiente_p44_txt': <ambiente_p44_txt> }
{... other environments vip ...}]}
:raise DataBaseError: Networkapi failed to access the database.
:raise XMLError: Networkapi failed to generate the XML response.
""" |
url = 'environmentvip/search/' + str(id_vlan)
code, xml = self.submit(None, 'GET', url)
key = 'environment_vip'
return get_list_map(self.response(code, xml, [key]), key) |
<SYSTEM_TASK:>
Inserts a new Environment VIP and returns its identifier.
<END_TASK>
<USER_TASK:>
Description:
def add(self, finalidade_txt, cliente_txt, ambiente_p44_txt, description):
"""Inserts a new Environment VIP and returns its identifier.
:param finalidade_txt: Finality. String with a maximum of 50 characters and respect [a-zA-Z\_-]
:param cliente_txt: ID Client. String with a maximum of 50 characters and respect [a-zA-Z\_-]
:param ambiente_p44_txt: Environment P44. String with a maximum of 50 characters and respect [a-zA-Z\_-]
:return: Following dictionary:
::
{'environment_vip': {'id': < id >}}
:raise InvalidParameterError: The value of finalidade_txt, cliente_txt or ambiente_p44_txt is invalid.
:raise DataBaseError: Networkapi failed to access the database.
:raise XMLError: Networkapi failed to generate the XML response.
""" |
environmentvip_map = dict()
environmentvip_map['finalidade_txt'] = finalidade_txt
environmentvip_map['cliente_txt'] = cliente_txt
environmentvip_map['ambiente_p44_txt'] = ambiente_p44_txt
environmentvip_map['description'] = description
code, xml = self.submit(
{'environment_vip': environmentvip_map}, 'POST', 'environmentvip/')
return self.response(code, xml) |
<SYSTEM_TASK:>
Change Environment VIP from by the identifier.
<END_TASK>
<USER_TASK:>
Description:
def alter(
self,
id_environment_vip,
finalidade_txt,
cliente_txt,
ambiente_p44_txt,
description):
"""Change Environment VIP from by the identifier.
:param id_environment_vip: Identifier of the Environment VIP. Integer value and greater than zero.
:param finalidade_txt: Finality. String with a maximum of 50 characters and respect [a-zA-Z\_-]
:param cliente_txt: ID Client. String with a maximum of 50 characters and respect [a-zA-Z\_-]
:param ambiente_p44_txt: Environment P44. String with a maximum of 50 characters and respect [a-zA-Z\_-]
:return: None
:raise InvalidParameterError: Environment VIP identifier is null and invalid.
:raise InvalidParameterError: The value of finalidade_txt, cliente_txt or ambiente_p44_txt is invalid.
:raise EnvironmentVipNotFoundError: Environment VIP not registered.
:raise DataBaseError: Networkapi failed to access the database.
:raise XMLError: Networkapi failed to generate the XML response.
""" |
if not is_valid_int_param(id_environment_vip):
raise InvalidParameterError(
u'The identifier of Environment VIP is invalid or was not informed.')
environmentvip_map = dict()
environmentvip_map['finalidade_txt'] = finalidade_txt
environmentvip_map['cliente_txt'] = cliente_txt
environmentvip_map['ambiente_p44_txt'] = ambiente_p44_txt
environmentvip_map['description'] = description
url = 'environmentvip/' + str(id_environment_vip) + '/'
code, xml = self.submit(
{'environment_vip': environmentvip_map}, 'PUT', url)
return self.response(code, xml) |
<SYSTEM_TASK:>
Remove Environment VIP from by the identifier.
<END_TASK>
<USER_TASK:>
Description:
def remove(self, id_environment_vip):
"""Remove Environment VIP from by the identifier.
:param id_environment_vip: Identifier of the Environment VIP. Integer value and greater than zero.
:return: None
:raise InvalidParameterError: Environment VIP identifier is null and invalid.
:raise EnvironmentVipNotFoundError: Environment VIP not registered.
:raise EnvironmentVipError: There networkIPv4 or networkIPv6 associated with environment vip.
:raise DataBaseError: Networkapi failed to access the database.
:raise XMLError: Networkapi failed to generate the XML response.
""" |
if not is_valid_int_param(id_environment_vip):
raise InvalidParameterError(
u'The identifier of Environment VIP is invalid or was not informed.')
url = 'environmentvip/' + str(id_environment_vip) + '/'
code, xml = self.submit(None, 'DELETE', url)
return self.response(code, xml) |
<SYSTEM_TASK:>
Search Environment VIP from by parameters.
<END_TASK>
<USER_TASK:>
Description:
def search(
self,
id_environment_vip=None,
finalidade_txt=None,
cliente_txt=None,
ambiente_p44_txt=None):
"""Search Environment VIP from by parameters.
Case the id parameter has been passed, the same it has priority over the other parameters.
:param id_environment_vip: Identifier of the Environment VIP. Integer value and greater than zero.
:param finalidade_txt: Finality. String with a maximum of 50 characters and respect [a-zA-Z\_-]
:param cliente_txt: ID Client. String with a maximum of 50 characters and respect [a-zA-Z\_-]
:param ambiente_p44_txt: Environment P44. String with a maximum of 50 characters and respect [a-zA-Z\_-]
:return: Following dictionary:
::
{‘environment_vip’:
{‘id’: < id >,
‘finalidade_txt’: < finalidade_txt >,
‘finalidade’: < finalidade >,
‘cliente_txt’: < cliente_txt >,
‘ambiente_p44_txt’: < ambiente_p44_txt >}}
:raise InvalidParameterError: The value of id_environment_vip, finalidade_txt, cliente_txt or ambiente_p44_txt is invalid.
:raise EnvironmentVipNotFoundError: Environment VIP not registered.
:raise DataBaseError: Networkapi failed to access the database.
:raise XMLError: Networkapi failed to generate the XML response.
""" |
environmentvip_map = dict()
environmentvip_map['id_environment_vip'] = id_environment_vip
environmentvip_map['finalidade_txt'] = finalidade_txt
environmentvip_map['cliente_txt'] = cliente_txt
environmentvip_map['ambiente_p44_txt'] = ambiente_p44_txt
code, xml = self.submit(
{'environment_vip': environmentvip_map}, 'POST', 'environmentvip/search/')
return self.response(code, xml) |
<SYSTEM_TASK:>
Method to search environments vip based on extends search.
<END_TASK>
<USER_TASK:>
Description:
def search(self, **kwargs):
"""
Method to search environments vip based on extends search.
:param search: Dict containing QuerySets to find environments vip.
:param include: Array containing fields to include on response.
:param exclude: Array containing fields to exclude on response.
:param fields: Array containing fields to override default fields.
:param kind: Determine if result will be detailed ('detail')
or basic ('basic').
:return: Dict containing environments vip
""" |
return super(ApiEnvironmentVip, self).get(
self.prepare_url('api/v3/environment-vip/', kwargs)) |
<SYSTEM_TASK:>
Method to get environments vip by their ids
<END_TASK>
<USER_TASK:>
Description:
def get(self, ids, **kwargs):
"""
Method to get environments vip by their ids
:param ids: List containing identifiers of environments vip
:param include: Array containing fields to include on response.
:param exclude: Array containing fields to exclude on response.
:param fields: Array containing fields to override default fields.
:param kind: Determine if result will be detailed ('detail')
or basic ('basic').
:return: Dict containing environments vip
""" |
uri = build_uri_with_ids('api/v3/environment-vip/%s/', ids)
return super(ApiEnvironmentVip, self).get(
self.prepare_url(uri, kwargs)) |
<SYSTEM_TASK:>
Method to delete environments vip by their id's.
<END_TASK>
<USER_TASK:>
Description:
def delete(self, ids):
"""
Method to delete environments vip by their id's.
:param ids: Identifiers of environments vip
:return: None
""" |
url = build_uri_with_ids('api/v3/environment-vip/%s/', ids)
return super(ApiEnvironmentVip, self).delete(url) |
<SYSTEM_TASK:>
Method to update environments vip
<END_TASK>
<USER_TASK:>
Description:
def update(self, environments):
"""
Method to update environments vip
:param environments vip: List containing environments vip desired
to updated
:return: None
""" |
data = {'environments_vip': environments}
environments_ids = [str(env.get('id')) for env in environments]
uri = 'api/v3/environment-vip/%s/' % ';'.join(environments_ids)
return super(ApiEnvironmentVip, self).put(uri, data) |
<SYSTEM_TASK:>
Method to create environments vip
<END_TASK>
<USER_TASK:>
Description:
def create(self, environments):
"""
Method to create environments vip
:param environments vip: Dict containing environments vip desired
to be created on database
:return: None
""" |
data = {'environments_vip': environments}
uri = 'api/v3/environment-vip/'
return super(ApiEnvironmentVip, self).post(uri, data) |
<SYSTEM_TASK:>
Get IPv4 by id.
<END_TASK>
<USER_TASK:>
Description:
def get_ipv4(self, id_ip):
"""Get IPv4 by id.
:param id_ip: ID of IPv4.
:return: Dictionary with the following structure:
::
{'ip': {'id': < id >,
'networkipv4': < networkipv4 >,
'oct4': < oct4 >,
'oct3': < oct3 >,
'oct2': < oct2 >,
'oct1': < oct1 >,
'descricao': < descricao >,
'equipamentos': [ { all name of equipments related } ] , }}
:raise IpNaoExisteError: IP is not registered.
:raise InvalidParameterError: IP identifier is null or invalid.
:raise DataBaseError: Networkapi failed to access the database.
:raise XMLError: Networkapi failed to generate the XML response.
""" |
if not is_valid_int_param(id_ip):
raise InvalidParameterError(
u'The IPv4 identifier is invalid or was not informed.')
url = 'ip/get-ipv4/' + str(id_ip) + '/'
code, xml = self.submit(None, 'GET', url)
key = 'ipv4'
return get_list_map(self.response(code, xml, ["equipamentos"]), key) |
<SYSTEM_TASK:>
Get IPv6 by id.
<END_TASK>
<USER_TASK:>
Description:
def get_ipv6(self, id_ip):
"""Get IPv6 by id.
:param id_ip: ID of IPv6.
:return: Dictionary with the following structure:
::
{'ip': {'id': < id >,
'networkipv6': < networkipv6 >,
'block1': < block1 >,
'block2': < block2 >,
'block3': < block3 >,
'block4': < block4 >,
'block5': < block5 >,
'block6': < block6 >,
'block7': < block7 >,
'block8': < block8 >,
'description': < description >,
'equipamentos': [ { all name of equipments related } ] , }}
:raise IpNaoExisteError: IP is not registered.
:raise InvalidParameterError: IP identifier is null or invalid.
:raise DataBaseError: Networkapi failed to access the database.
:raise XMLError: Networkapi failed to generate the XML response.
""" |
if not is_valid_int_param(id_ip):
raise InvalidParameterError(
u'The IPv6 identifier is invalid or was not informed.')
url = 'ip/get-ipv6/' + str(id_ip) + '/'
code, xml = self.submit(None, 'GET', url)
key = 'ipv6'
return get_list_map(self.response(code, xml, ["equipamentos"]), key) |
<SYSTEM_TASK:>
Get IP with an associated environment.
<END_TASK>
<USER_TASK:>
Description:
def buscar_por_ip_ambiente(self, ip, id_environment):
"""Get IP with an associated environment.
:param ip: IP address in the format x1.x2.x3.x4.
:param id_environment: Identifier of the environment. Integer value and greater than zero.
:return: Dictionary with the following structure:
::
{'ip': {'id': < id >,
'id_vlan': < id_vlan >,
'oct4': < oct4 >,
'oct3': < oct3 >,
'oct2': < oct2 >,
'oct1': < oct1 >,
'descricao': < descricao > }}
:raise IpNaoExisteError: IP is not registered or not associated with environment.
:raise InvalidParameterError: The environment identifier and/or IP is/are null or invalid.
:raise DataBaseError: Networkapi failed to access the database.
""" |
if not is_valid_int_param(id_environment):
raise InvalidParameterError(
u'Environment identifier is invalid or was not informed.')
if not is_valid_ip(ip):
raise InvalidParameterError(u'IP is invalid or was not informed.')
url = 'ip/' + str(ip) + '/ambiente/' + str(id_environment) + '/'
code, xml = self.submit(None, 'GET', url)
return self.response(code, xml) |
<SYSTEM_TASK:>
Get a available IP in the network ipv4
<END_TASK>
<USER_TASK:>
Description:
def get_available_ip4(self, id_network):
"""
Get a available IP in the network ipv4
:param id_network: Network identifier. Integer value and greater than zero.
:return: Dictionary with the following structure:
::
{'ip': {'ip': < available_ip >}}
:raise IpNotAvailableError: Network dont have available IP for insert a new IP
:raise NetworkIPv4NotFoundError: Network is not found
:raise UserNotAuthorizedError: User dont have permission to get a available IP
:raise InvalidParameterError: Network identifier is null or invalid.
:raise XMLError: Networkapi failed to generate the XML response.
:raise DataBaseError: Networkapi failed to access the database.
""" |
if not is_valid_int_param(id_network):
raise InvalidParameterError(
u'Network identifier is invalid or was not informed.')
url = 'ip/availableip4/' + str(id_network) + "/"
code, xml = self.submit(None, 'GET', url)
return self.response(code, xml) |
<SYSTEM_TASK:>
Get a available IP in the Equipment related Environment VIP
<END_TASK>
<USER_TASK:>
Description:
def get_ip_by_equip_and_vip(self, equip_name, id_evip):
"""
Get a available IP in the Equipment related Environment VIP
:param equip_name: Equipment Name.
:param id_evip: Vip environment identifier. Integer value and greater than zero.
:return: Dictionary with the following structure:
::
{ 'ipv4': [ {'id': < id >, 'ip': < ip >, 'network': { 'id': < id >, 'network': < network >, 'mask': < mask >, }} ... ],
'ipv6': [ {'id': < id >, 'ip': < ip >, 'network': { 'id': < id >, 'network': < network >, 'mask': < mask >, }} ... ] }
:raise InvalidParameterError: Vip environment identifier or equipment name is none or invalid.
:raise EquipamentoNotFoundError: Equipment not registered.
:raise EnvironmentVipNotFoundError: Vip environment not registered.
:raise UserNotAuthorizedError: User dont have permission to perform operation.
:raise XMLError: Networkapi failed to generate the XML response.
:raise DataBaseError: Networkapi failed to access the database.
""" |
if not is_valid_int_param(id_evip):
raise InvalidParameterError(
u'Vip environment is invalid or was not informed.')
ip_map = dict()
ip_map['equip_name'] = equip_name
ip_map['id_evip'] = id_evip
url = "ip/getbyequipandevip/"
code, xml = self.submit({'ip_map': ip_map}, 'POST', url)
return self.response(code, xml) |
<SYSTEM_TASK:>
Get a Ipv4 or Ipv6 by IP
<END_TASK>
<USER_TASK:>
Description:
def get_ipv4_or_ipv6(self, ip):
"""
Get a Ipv4 or Ipv6 by IP
:param ip: IPv4 or Ipv6. 'xxx.xxx.xxx.xxx or xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx'
:return: Dictionary with the following structure:
::
{'ips': [{'oct4': < oct4 >, 'oct2': < oct2 >, 'oct3': < oct3 >,
'oct1': < oct1 >, 'version': < version >,
'networkipv4': < networkipv4 >, 'id': < id >, 'descricao': < descricao >}, ... ] }.
or
{'ips': [ {'block1': < block1 >, 'block2': < block2 >, 'block3': < block3 >, 'block4': < block4 >, 'block5': < block5 >, 'block6': < block6 >, 'block7': < block7 >, 'block8': < block8 >,
'version': < version >, 'networkipv6': < networkipv6 >, 'id': < id >, 'descricao': < descricao >}, ... ] }.
:raise IpNaoExisteError: Ipv4 or Ipv6 not found.
:raise UserNotAuthorizedError: User dont have permission to perform operation.
:raise InvalidParameterError: Ip string is none or invalid.
:raise XMLError: Networkapi failed to generate the XML response.
:raise DataBaseError: Networkapi failed to access the database.
""" |
ip_map = dict()
ip_map['ip'] = ip
url = "ip/getbyoctblock/"
code, xml = self.submit({'ip_map': ip_map}, 'POST', url)
return self.response(code, xml) |
<SYSTEM_TASK:>
Get a Ipv4 or Ipv6 for Vip request
<END_TASK>
<USER_TASK:>
Description:
def check_vip_ip(self, ip, id_evip):
"""
Get a Ipv4 or Ipv6 for Vip request
:param ip: IPv4 or Ipv6. 'xxx.xxx.xxx.xxx or xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx'
:return: Dictionary with the following structure:
::
{'ip': {'ip': < ip - octs for ipv4, blocks for ipv6 - >,
'id': <id>,
'network4 or network6'}}.
:raise IpNaoExisteError: Ipv4 or Ipv6 not found.
:raise EnvironemntVipNotFoundError: Vip environment not found.
:raise IPNaoDisponivelError: Ip not available for Vip Environment.
:raise UserNotAuthorizedError: User dont have permission to perform operation.
:raise InvalidParameterError: Ip string or vip environment is none or invalid.
:raise XMLError: Networkapi failed to generate the XML response.
:raise DataBaseError: Networkapi failed to access the database.
""" |
ip_map = dict()
ip_map['ip'] = ip
ip_map['id_evip'] = id_evip
url = "ip/checkvipip/"
code, xml = self.submit({'ip_map': ip_map}, 'POST', url)
return self.response(code, xml) |
<SYSTEM_TASK:>
Get a available IP in Network ipv6
<END_TASK>
<USER_TASK:>
Description:
def get_available_ip6(self, id_network6):
"""
Get a available IP in Network ipv6
:param id_network6: Network ipv6 identifier. Integer value and greater than zero.
:return: Dictionary with the following structure:
::
{'ip6': {'ip6': < available_ip6 >}}
:raise IpNotAvailableError: Network dont have available IP.
:raise NetworkIPv4NotFoundError: Network was not found.
:raise UserNotAuthorizedError: User dont have permission to get a available IP.
:raise InvalidParameterError: Network ipv6 identifier is none or invalid.
:raise XMLError: Networkapi failed to generate the XML response.
:raise DataBaseError: Networkapi failed to access the database.
""" |
if not is_valid_int_param(id_network6):
raise InvalidParameterError(
u'Network ipv6 identifier is invalid or was not informed.')
url = 'ip/availableip6/' + str(id_network6) + "/"
code, xml = self.submit(None, 'GET', url)
return self.response(code, xml) |
<SYSTEM_TASK:>
Get and save a available IP in the network ipv6 for vip request
<END_TASK>
<USER_TASK:>
Description:
def get_available_ip6_for_vip(self, id_evip, name):
"""
Get and save a available IP in the network ipv6 for vip request
:param id_evip: Vip environment identifier. Integer value and greater than zero.
:param name: Ip description
:return: Dictionary with the following structure:
::
{'ip': {'bloco1':<bloco1>,
'bloco2':<bloco2>,
'bloco3':<bloco3>,
'bloco4':<bloco4>,
'bloco5':<bloco5>,
'bloco6':<bloco6>,
'bloco7':<bloco7>,
'bloco8':<bloco8>,
'id':<id>,
'networkipv6':<networkipv6>,
'description':<description>}}
:raise IpNotAvailableError: Network dont have available IP for vip environment.
:raise EnvironmentVipNotFoundError: Vip environment not registered.
:raise UserNotAuthorizedError: User dont have permission to perform operation.
:raise InvalidParameterError: Vip environment identifier is none or invalid.
:raise XMLError: Networkapi failed to generate the XML response.
:raise DataBaseError: Networkapi failed to access the database.
""" |
if not is_valid_int_param(id_evip):
raise InvalidParameterError(
u'Vip environment identifier is invalid or was not informed.')
url = 'ip/availableip6/vip/' + str(id_evip) + "/"
ip_map = dict()
ip_map['id_evip'] = id_evip
ip_map['name'] = name
code, xml = self.submit({'ip_map': ip_map}, 'POST', url)
return self.response(code, xml) |
<SYSTEM_TASK:>
Edit a IP4
<END_TASK>
<USER_TASK:>
Description:
def edit_ipv4(self, ip4, descricao, id_ip):
"""
Edit a IP4
:param ip4: An IP4 available to save in format x.x.x.x.
:param id_ip: IP identifier. Integer value and greater than zero.
:param descricao: IP description.
:return: None
""" |
if not is_valid_int_param(id_ip):
raise InvalidParameterError(
u'Ip identifier is invalid or was not informed.')
if ip4 is None or ip4 == "":
raise InvalidParameterError(
u'The IP4 is invalid or was not informed.')
ip_map = dict()
ip_map['descricao'] = descricao
ip_map['ip4'] = ip4
ip_map['id_ip'] = id_ip
url = "ip4/edit/"
code, xml = self.submit({'ip_map': ip_map}, 'POST', url)
return self.response(code, xml) |
<SYSTEM_TASK:>
Save a IP4 and associate with equipment
<END_TASK>
<USER_TASK:>
Description:
def save_ipv4(self, ip4, id_equip, descricao, id_net):
"""
Save a IP4 and associate with equipment
:param ip4: An IP4 available to save in format x.x.x.x.
:param id_equip: Equipment identifier. Integer value and greater than zero.
:param descricao: IP description.
:param id_net: Network identifier. Integer value and greater than zero.
:return: Dictionary with the following structure:
::
{ ip: { id: <id_ip4>,
oct1: <oct1>,
oct2: <oct2>,
oct3: <oct3>,
oct4: <oct4>,
equipamento: [ { all equipamentos related } ] ,
descricao: <descricao> } }
""" |
if not is_valid_int_param(id_net):
raise InvalidParameterError(
u'Network identifier is invalid or was not informed.')
if not is_valid_int_param(id_equip):
raise InvalidParameterError(
u'Equipment identifier is invalid or was not informed.')
if ip4 is None or ip4 == "":
raise InvalidParameterError(u'IP4 is invalid or was not informed.')
ip_map = dict()
ip_map['id_net'] = id_net
ip_map['descricao'] = descricao
ip_map['ip4'] = ip4
ip_map['id_equip'] = id_equip
url = "ipv4/save/"
code, xml = self.submit({'ip_map': ip_map}, 'POST', url)
return self.response(code, xml) |
<SYSTEM_TASK:>
Edit a IP6
<END_TASK>
<USER_TASK:>
Description:
def edit_ipv6(self, ip6, descricao, id_ip):
"""
Edit a IP6
:param ip6: An IP6 available to save in format xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx.
:param descricao: IP description.
:param id_ip: Ipv6 identifier. Integer value and greater than zero.
:return: None
""" |
if not is_valid_int_param(id_ip):
raise InvalidParameterError(
u'Ipv6 identifier is invalid or was not informed.')
if ip6 is None or ip6 == "":
raise InvalidParameterError(u'IP6 is invalid or was not informed.')
ip_map = dict()
ip_map['descricao'] = descricao
ip_map['ip6'] = ip6
ip_map['id_ip'] = id_ip
url = "ipv6/edit/"
code, xml = self.submit({'ip_map': ip_map}, 'POST', url)
return self.response(code, xml) |
<SYSTEM_TASK:>
Get an IP by ID
<END_TASK>
<USER_TASK:>
Description:
def find_ip4_by_id(self, id_ip):
"""
Get an IP by ID
:param id_ip: IP identifier. Integer value and greater than zero.
:return: Dictionary with the following structure:
::
{ ips { id: <id_ip4>,
oct1: <oct1>,
oct2: <oct2>,
oct3: <oct3>,
oct4: <oct4>,
equipamento: [ {all equipamentos related} ] ,
descricao: <descricao>} }
:raise IpNotAvailableError: Network dont have available IP.
:raise NetworkIPv4NotFoundError: Network was not found.
:raise UserNotAuthorizedError: User dont have permission to perform operation.
:raise InvalidParameterError: Ip identifier is none or invalid.
:raise XMLError: Networkapi failed to generate the XML response.
:raise DataBaseError: Networkapi failed to access the database.
""" |
if not is_valid_int_param(id_ip):
raise InvalidParameterError(
u'Ip identifier is invalid or was not informed.')
url = 'ip/get/' + str(id_ip) + "/"
code, xml = self.submit(None, 'GET', url)
return self.response(code, xml) |
<SYSTEM_TASK:>
Get Ips related to equipment by its identifier
<END_TASK>
<USER_TASK:>
Description:
def find_ips_by_equip(self, id_equip):
"""
Get Ips related to equipment by its identifier
:param id_equip: Equipment identifier. Integer value and greater than zero.
:return: Dictionary with the following structure:
{ ips: { ipv4:[
id: <id_ip4>,
oct1: <oct1>,
oct2: <oct2>,
oct3: <oct3>,
oct4: <oct4>,
descricao: <descricao> ]
ipv6:[
id: <id_ip6>,
block1: <block1>,
block2: <block2>,
block3: <block3>,
block4: <block4>,
block5: <block5>,
block6: <block6>,
block7: <block7>,
block8: <block8>,
descricao: <descricao> ] } }
:raise UserNotAuthorizedError: User dont have permission to list ips.
:raise InvalidParameterError: Equipment identifier is none or invalid.
:raise XMLError: Networkapi failed to generate the XML response.
:raise DataBaseError: Networkapi failed to access the database.
""" |
url = 'ip/getbyequip/' + str(id_equip) + "/"
code, xml = self.submit(None, 'GET', url)
return self.response(code, xml, ['ipv4', 'ipv6']) |
<SYSTEM_TASK:>
Get an IP6 by ID
<END_TASK>
<USER_TASK:>
Description:
def find_ip6_by_id(self, id_ip):
"""
Get an IP6 by ID
:param id_ip: IP6 identifier. Integer value and greater than zero.
:return: Dictionary with the following structure:
::
{'ip': {'id': < id >,
'block1': <block1>,
'block2': <block2>,
'block3': <block3>,
'block4': <block4>,
'block5': <block5>,
'block6': <block6>,
'block7': <block7>,
'block8': <block8>,
'descricao': < description >,
'equipamento': [ { all name equipamentos related} ], }}
:raise IpNotAvailableError: Network dont have available IPv6.
:raise NetworkIPv4NotFoundError: Network was not found.
:raise UserNotAuthorizedError: User dont have permission to perform operation.
:raise InvalidParameterError: IPv6 identifier is none or invalid.
:raise XMLError: Networkapi failed to generate the XML response.
:raise DataBaseError: Networkapi failed to access the database.
""" |
if not is_valid_int_param(id_ip):
raise InvalidParameterError(
u'Ipv6 identifier is invalid or was not informed.')
url = 'ipv6/get/' + str(id_ip) + "/"
code, xml = self.submit(None, 'GET', url)
return self.response(code, xml) |
<SYSTEM_TASK:>
Save an IP6 and associate with equipment
<END_TASK>
<USER_TASK:>
Description:
def save_ipv6(self, ip6, id_equip, descricao, id_net):
"""
Save an IP6 and associate with equipment
:param ip6: An IP6 available to save in format xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx.
:param id_equip: Equipment identifier. Integer value and greater than zero.
:param descricao: IPv6 description.
:param id_net: Network identifier. Integer value and greater than zero.
:return: Dictionary with the following structure:
::
{'ipv6': {'id': < id >,
'block1': <block1>,
'block2': <block2>,
'block3': <block3>,
'block4': <block4>,
'block5': <block5>,
'block6': <block6>,
'block7': <block7>,
'block8': <block8>,
'descricao': < description >,
'equipamento': [ { all name equipamentos related } ], }}
""" |
if not is_valid_int_param(id_net):
raise InvalidParameterError(
u'Network identifier is invalid or was not informed.')
if not is_valid_int_param(id_equip):
raise InvalidParameterError(
u'Equipment identifier is invalid or was not informed.')
if ip6 is None or ip6 == "":
raise InvalidParameterError(
u'IPv6 is invalid or was not informed.')
ip_map = dict()
ip_map['id_net'] = id_net
ip_map['descricao'] = descricao
ip_map['ip6'] = ip6
ip_map['id_equip'] = id_equip
url = "ipv6/save/"
code, xml = self.submit({'ip_map': ip_map}, 'POST', url)
return self.response(code, xml) |
<SYSTEM_TASK:>
Delete an IP4
<END_TASK>
<USER_TASK:>
Description:
def delete_ip4(self, id_ip):
"""
Delete an IP4
:param id_ip: Ipv4 identifier. Integer value and greater than zero.
:return: None
:raise IpNotFoundError: IP is not registered.
:raise DataBaseError: Networkapi failed to access the database.
""" |
if not is_valid_int_param(id_ip):
raise InvalidParameterError(u'Ipv4 identifier is invalid or was not informed.')
url = 'ip4/delete/' + str(id_ip) + "/"
code, xml = self.submit(None, 'DELETE', url)
return self.response(code, xml) |
<SYSTEM_TASK:>
List IPv6 from network.
<END_TASK>
<USER_TASK:>
Description:
def find_ip6_by_network(self, id_network):
"""List IPv6 from network.
:param id_network: Network ipv6 identifier. Integer value and greater than zero.
:return: Dictionary with the following structure:
::
{'ip': {'id': < id >,
'id_vlan': < id_vlan >,
'block1': <block1>,
'block2': <block2>,
'block3': <block3>,
'block4': <block4>,
'block5': <block5>,
'block6': <block6>,
'block7': <block7>,
'block8': <block8>,
'descricao': < description >
'equipamento': [ { all name equipamentos related } ], }}
:raise IpNaoExisteError: Network does not have any ips.
:raise InvalidParameterError: Network identifier is none or invalid.
:raise DataBaseError: Networkapi failed to access the database.
""" |
if not is_valid_int_param(id_network):
raise InvalidParameterError(
u'Network identifier is invalid or was not informed.')
url = 'ip/id_network_ipv6/' + str(id_network) + "/"
code, xml = self.submit(None, 'GET', url)
key = "ips"
return get_list_map(self.response(code, xml, [key]), key) |
<SYSTEM_TASK:>
Get IPv6 with an associated environment.
<END_TASK>
<USER_TASK:>
Description:
def search_ipv6_environment(self, ipv6, id_environment):
"""Get IPv6 with an associated environment.
:param ipv6: IPv6 address in the format x1:x2:x3:x4:x5:x6:x7:x8.
:param id_environment: Environment identifier. Integer value and greater than zero.
:return: Dictionary with the following structure:
::
{'ipv6': {'id': < id >,
'id_vlan': < id_vlan >,
'bloco1': < bloco1 >,
'bloco2': < bloco2 >,
'bloco3': < bloco3 >,
'bloco4': < bloco4 >,
'bloco5': < bloco5 >,
'bloco6': < bloco6 >,
'bloco7': < bloco7 >,
'bloco8': < bloco8 >,
'descricao': < descricao > }}
:raise IpNaoExisteError: IPv6 is not registered or is not associated to the environment.
:raise AmbienteNaoExisteError: Environment not found.
:raise InvalidParameterError: Environment identifier and/or IPv6 string is/are none or invalid.
:raise DataBaseError: Networkapi failed to access the database.
:raise XMLError: Networkapi failed to generate the XML response.
""" |
if not is_valid_int_param(id_environment):
raise InvalidParameterError(
u'Environment identifier is invalid or was not informed.')
ipv6_map = dict()
ipv6_map['ipv6'] = ipv6
ipv6_map['id_environment'] = id_environment
code, xml = self.submit(
{'ipv6_map': ipv6_map}, 'POST', 'ipv6/environment/')
return self.response(code, xml) |
<SYSTEM_TASK:>
Associate an IP4 with equipment.
<END_TASK>
<USER_TASK:>
Description:
def assoc_ipv4(self, id_ip, id_equip, id_net):
"""
Associate an IP4 with equipment.
:param id_ip: IPv4 identifier.
:param id_equip: Equipment identifier. Integer value and greater than zero.
:param id_net: Network identifier. Integer value and greater than zero.
:return: None
:raise InvalidParameterError: IPv4, Equipment or Network identifier is none or invalid.
:raise DataBaseError: Networkapi failed to access the database.
:raise XMLError: Networkapi failed to generate the XML response.
""" |
if not is_valid_int_param(id_ip):
raise InvalidParameterError(
u'Ip identifier is invalid or was not informed.')
if not is_valid_int_param(id_net):
raise InvalidParameterError(
u'Network identifier is invalid or was not informed.')
if not is_valid_int_param(id_equip):
raise InvalidParameterError(
u'Equipment identifier is invalid or was not informed.')
ip_map = dict()
ip_map['id_ip'] = id_ip
ip_map['id_net'] = id_net
ip_map['id_equip'] = id_equip
url = "ipv4/assoc/"
code, xml = self.submit({'ip_map': ip_map}, 'POST', url)
return self.response(code, xml) |
<SYSTEM_TASK:>
Associate an IP6 with equipment.
<END_TASK>
<USER_TASK:>
Description:
def assoc_ipv6(self, id_ip, id_equip, id_net):
"""
Associate an IP6 with equipment.
:param id_ip: IPv6 identifier.
:param id_equip: Equipment identifier. Integer value and greater than zero.
:param id_net: Network identifier. Integer value and greater than zero.
:return: None
:raise InvalidParameterError: IPv6, Equipment or Network identifier is none or invalid.
:raise DataBaseError: Networkapi failed to access the database.
:raise XMLError: Networkapi failed to generate the XML response.
""" |
if not is_valid_int_param(id_ip):
raise InvalidParameterError(
u'Ipv6 identifier is invalid or was not informed.')
if not is_valid_int_param(id_net):
raise InvalidParameterError(
u'Network identifier is invalid or was not informed.')
if not is_valid_int_param(id_equip):
raise InvalidParameterError(
u'Equipment identifier is invalid or was not informed.')
ip_map = dict()
ip_map['id_ip'] = id_ip
ip_map['id_net'] = id_net
ip_map['id_equip'] = id_equip
url = "ipv6/assoc/"
code, xml = self.submit({'ip_map': ip_map}, 'POST', url)
return self.response(code, xml) |
<SYSTEM_TASK:>
List all network types.
<END_TASK>
<USER_TASK:>
Description:
def listar(self):
"""List all network types.
:return: Following dictionary:
::
{'net_type': [{'id': < id_tipo_rede >,
'name': < nome_tipo_rede >}, ... other network types ...]}
:raise DataBaseError: Networkapi failed to access the database.
:raise XMLError: Networkapi failed to generate the XML response.
""" |
code, xml = self.submit(None, 'GET', 'net_type/')
key = 'net_type'
return get_list_map(self.response(code, xml, [key]), key) |
<SYSTEM_TASK:>
Insert new network type and return its identifier.
<END_TASK>
<USER_TASK:>
Description:
def inserir(self, name):
"""Insert new network type and return its identifier.
:param name: Network type name.
:return: Following dictionary: {'net_type': {'id': < id >}}
:raise InvalidParameterError: Network type is none or invalid.
:raise NomeTipoRedeDuplicadoError: A network type with this name already exists.
:raise DataBaseError: Networkapi failed to access the database.
:raise XMLError: Networkapi failed to generate the XML response.
""" |
net_type_map = dict()
net_type_map['name'] = name
code, xml = self.submit(
{'net_type': net_type_map}, 'POST', 'net_type/')
return self.response(code, xml) |
<SYSTEM_TASK:>
Edit network type by its identifier.
<END_TASK>
<USER_TASK:>
Description:
def alterar(self, id_net_type, name):
"""Edit network type by its identifier.
:param id_net_type: Network type identifier.
:param name: Network type name.
:return: None
:raise InvalidParameterError: Network type identifier and/or name is(are) none or invalid.
:raise TipoRedeNaoExisteError: Network type does not exist.
:raise NomeTipoRedeDuplicadoError: Network type name already exists.
:raise DataBaseError: Networkapi failed to access the database.
:raise XMLError: Networkapi failed to generate the XML response.
""" |
if not is_valid_int_param(id_net_type):
raise InvalidParameterError(
u'Network type is invalid or was not informed.')
url = 'net_type/' + str(id_net_type) + '/'
net_type_map = dict()
net_type_map['name'] = name
code, xml = self.submit({'net_type': net_type_map}, 'PUT', url)
return self.response(code, xml) |
<SYSTEM_TASK:>
Remove network type by its identifier.
<END_TASK>
<USER_TASK:>
Description:
def remover(self, id_net_type):
"""Remove network type by its identifier.
:param id_net_type: Network type identifier.
:return: None
:raise TipoRedeNaoExisteError: Network type does not exist.
:raise TipoRedeError: Network type is associated with network.
:raise InvalidParameterError: Network type is none or invalid.
:raise DataBaseError: Networkapi failed to access the database.
:raise XMLError: Networkapi failed to generate the XML response.
""" |
if not is_valid_int_param(id_net_type):
raise InvalidParameterError(
u'Network type is invalid or was not informed.')
url = 'net_type/' + str(id_net_type) + '/'
code, xml = self.submit(None, 'DELETE', url)
return self.response(code, xml) |
<SYSTEM_TASK:>
process automatic context variable capturing.
<END_TASK>
<USER_TASK:>
Description:
def process(fn, bound_names):
"""
process automatic context variable capturing.
return the transformed function and its ast.
""" |
if isinstance(fn, _AutoContext):
fn = fn.fn
# noinspection PyArgumentList,PyArgumentList
if isinstance(fn, _FnCodeStr):
if bound_names:
assign_code_str = '{syms} = map(state.ctx.get, {names})'.format(
syms=', '.join(bound_names) + ',', names=repr(bound_names))
else:
assign_code_str = ''
code = "def {0}({1}):\n{2}".format(
fn.fn_name, ", ".join(fn.fn_args),
textwrap.indent(assign_code_str + '\n' + fn.code, " "))
module_ast = ast.parse(code, fn.filename)
bound_name_line_inc = int(bool(bound_names)) + 1
module_ast: ast.Module = ast.increment_lineno(
module_ast, fn.lineno - bound_name_line_inc)
fn_ast = module_ast.body[0]
if isinstance(fn_ast.body[-1], ast.Expr):
# auto addition of tail expr return
# in rbnf you don't need to write return if the last statement in the end is an expression.
it: ast.Expr = fn_ast.body[-1]
fn_ast.body[-1] = ast.Return(
lineno=it.lineno, col_offset=it.col_offset, value=it.value)
filename = fn.filename
name = fn.fn_name
code_object = compile(module_ast, filename, "exec")
local = {}
# TODO: using types.MethodType here to create the function object leads to various problems.
# Actually I don't really known why util now.
exec(code_object, fn.namespace, local)
ret = local[name]
else:
if not bound_names:
return fn, get_ast(fn)
code = fn.__code__
assigns = ast.parse("ctx = state.ctx\n" + "\n".join(
"{0} = ctx.get({0!r})".format(name) for name in bound_names))
module_ast = get_ast(fn)
fn_ast: ast.FunctionDef = module_ast.body[0]
fn_ast.body = assigns.body + fn_ast.body
module_ast = ast.Module([fn_ast])
filename = code.co_filename
name = code.co_name
__defaults__ = fn.__defaults__
__closure__ = fn.__closure__
__globals__ = fn.__globals__
code_object = compile(module_ast, filename, "exec")
code_object = next(
each for each in code_object.co_consts
if isinstance(each, types.CodeType) and each.co_name == name)
# noinspection PyArgumentList,PyUnboundLocalVariable
ret = types.FunctionType(code_object, __globals__, name, __defaults__,
__closure__)
return ret, module_ast |
<SYSTEM_TASK:>
ignore a set of tokens with specific names
<END_TASK>
<USER_TASK:>
Description:
def ignore(self, *ignore_lst: str):
"""
ignore a set of tokens with specific names
""" |
def stream():
for each in ignore_lst:
each = ConstStrPool.cast_to_const(each)
yield id(each), each
self.ignore_lst.update(stream()) |
<SYSTEM_TASK:>
Helper to decode a request field into unicode based on charsets encoding.
<END_TASK>
<USER_TASK:>
Description:
def _decode_POST_value(request, field_name, default=None):
"""Helper to decode a request field into unicode based on charsets encoding.
Args:
request: the HttpRequest object.
field_name: the field expected in the request.POST
Kwargs:
default: if passed in then field is optional and default is used if not
found; if None, then assume field exists, which will raise an error
if it does not.
Returns: the contents of the string encoded using the related charset from
the requests.POST['charsets'] dictionary (or 'utf-8' if none specified).
""" |
if default is None:
value = request.POST[field_name]
else:
value = request.POST.get(field_name, default)
# it's inefficient to load this each time it gets called, but we're
# not anticipating incoming email being a performance bottleneck right now!
charsets = json.loads(request.POST.get('charsets', "{}"))
charset = charsets.get(field_name, 'utf-8')
if charset.lower() != 'utf-8':
logger.debug("Incoming email field '%s' has %s encoding.", field_name, charset)
return smart_text(value, encoding=charset) |
<SYSTEM_TASK:>
Returns an iterator of objects
<END_TASK>
<USER_TASK:>
Description:
def _get_recipients(self, array):
"""Returns an iterator of objects
in the form ["Name <[email protected]", ...]
from the array [["[email protected]", "Name"]]
""" |
for address, name in array:
if not name:
yield address
else:
yield "\"%s\" <%s>" % (name, address) |
<SYSTEM_TASK:>
Helper function to dump out debug info.
<END_TASK>
<USER_TASK:>
Description:
def _log_request(request):
"""Helper function to dump out debug info.""" |
logger.debug("Inbound email received")
for k, v in list(request.POST.items()):
logger.debug("- POST['%s']='%s'" % (k, v))
for n, f in list(request.FILES.items()):
logger.debug("- FILES['%s']: '%s', %sB", n, f.content_type, f.size) |
<SYSTEM_TASK:>
Receives inbound email from SendGrid.
<END_TASK>
<USER_TASK:>
Description:
def receive_inbound_email(request):
"""Receives inbound email from SendGrid.
This view receives the email from SendGrid, parses the contents, logs
the message and the fires the inbound_email signal.
""" |
# log the request.POST and request.FILES contents
if log_requests is True:
_log_request(request)
# HEAD requests are used by some backends to validate the route
if request.method == 'HEAD':
return HttpResponse('OK')
try:
# clean up encodings and extract relevant fields from request.POST
backend = get_backend_instance()
emails = backend.parse(request)
# backend.parse can return either an EmailMultiAlternatives
# or a list of those
if emails:
if isinstance(emails, EmailMultiAlternatives):
emails = [emails]
for email in emails:
# fire the signal for each email
email_received.send(sender=backend.__class__, email=email, request=request)
except AttachmentTooLargeError as ex:
logger.exception(ex)
email_received_unacceptable.send(
sender=backend.__class__,
email=ex.email,
request=request,
exception=ex
)
except AuthenticationError as ex:
logger.exception(ex)
email_received_unacceptable.send(
sender=backend.__class__,
email=None,
request=request,
exception=ex
)
except RequestParseError as ex:
logger.exception(ex)
if getattr(settings, 'INBOUND_EMAIL_RESPONSE_200', True):
# NB even if we have a problem, always use HTTP_STATUS=200, as
# otherwise the email service will continue polling us with the email.
# This is the default behaviour.
status_code = 200
else:
status_code = 400
return HttpResponse(
"Unable to parse inbound email: %s" % ex,
status=status_code
)
return HttpResponse("Successfully parsed inbound email.", status=200) |
<SYSTEM_TASK:>
Return reference to the configured backed class.
<END_TASK>
<USER_TASK:>
Description:
def get_backend_class():
"""Return reference to the configured backed class.""" |
# this will (intentionally) blow up if the setting does not exist
assert hasattr(settings, 'INBOUND_EMAIL_PARSER')
assert getattr(settings, 'INBOUND_EMAIL_PARSER') is not None
package, klass = settings.INBOUND_EMAIL_PARSER.rsplit('.', 1)
module = import_module(package)
return getattr(module, klass) |
<SYSTEM_TASK:>
For list, values, returns the insert position for item x and whether the item already exists in the list. This
<END_TASK>
<USER_TASK:>
Description:
def sorted_exists(values, x):
"""
For list, values, returns the insert position for item x and whether the item already exists in the list. This
allows one function call to return either the index to overwrite an existing value in the list, or the index to
insert a new item in the list and keep the list in sorted order.
:param values: list
:param x: item
:return: (exists, index) tuple
""" |
i = bisect_left(values, x)
j = bisect_right(values, x)
exists = x in values[i:j]
return exists, i |
<SYSTEM_TASK:>
For list, values, returns the index location of element x. If x does not exist will raise an error.
<END_TASK>
<USER_TASK:>
Description:
def sorted_index(values, x):
"""
For list, values, returns the index location of element x. If x does not exist will raise an error.
:param values: list
:param x: item
:return: integer index
""" |
i = bisect_left(values, x)
j = bisect_right(values, x)
return values[i:j].index(x) + i |
<SYSTEM_TASK:>
Link the worker to the given next worker object,
<END_TASK>
<USER_TASK:>
Description:
def _link(self, next_worker, next_is_first=False):
"""Link the worker to the given next worker object,
connecting the two workers with communication tubes.""" |
lock = multiprocessing.Lock()
next_worker._lock_prev_input = lock
self._lock_next_input = lock
lock.acquire()
lock = multiprocessing.Lock()
next_worker._lock_prev_output = lock
self._lock_next_output = lock
lock.acquire()
# If the next worker is the first one, trigger it now.
if next_is_first:
self._lock_next_input.release()
self._lock_next_output.release() |
<SYSTEM_TASK:>
Print the contents of the Series. This method uses the tabulate function from the tabulate package. Use the
<END_TASK>
<USER_TASK:>
Description:
def show(self, index=True, **kwargs):
"""
Print the contents of the Series. This method uses the tabulate function from the tabulate package. Use the
kwargs to pass along any arguments to the tabulate function.
:param index: If True then include the indexes as a column in the output, if False ignore the index
:param kwargs: Parameters to pass along to the tabulate function
:return: output of the tabulate function
""" |
print(self._make_table(index=index, **kwargs)) |
<SYSTEM_TASK:>
Given indexes will return a sub-set of the Series. This method will direct to the specific methods
<END_TASK>
<USER_TASK:>
Description:
def get(self, indexes, as_list=False):
"""
Given indexes will return a sub-set of the Series. This method will direct to the specific methods
based on what types are passed in for the indexes. The type of the return is determined by the
types of the parameters.
:param indexes: index value, list of index values, or a list of booleans.
:param as_list: if True then return the values as a list, if False return a Series.
:return: either Series, list, or single value. The return is a shallow copy
""" |
if isinstance(indexes, (list, blist)):
return self.get_rows(indexes, as_list)
else:
return self.get_cell(indexes) |
<SYSTEM_TASK:>
For a single index and return the value
<END_TASK>
<USER_TASK:>
Description:
def get_cell(self, index):
"""
For a single index and return the value
:param index: index value
:return: value
""" |
i = sorted_index(self._index, index) if self._sort else self._index.index(index)
return self._data[i] |
<SYSTEM_TASK:>
For a list of indexes return the values of the indexes in that column.
<END_TASK>
<USER_TASK:>
Description:
def get_rows(self, indexes, as_list=False):
"""
For a list of indexes return the values of the indexes in that column.
:param indexes: either a list of index values or a list of booleans with same length as all indexes
:param as_list: if True return a list, if False return Series
:return: Series if as_list if False, a list if as_list is True
""" |
if all([isinstance(i, bool) for i in indexes]): # boolean list
if len(indexes) != len(self._index):
raise ValueError('boolean index list must be same size of existing index')
if all(indexes): # the entire column
data = self._data
index = self._index
else:
data = list(compress(self._data, indexes))
index = list(compress(self._index, indexes))
else: # index values list
locations = [sorted_index(self._index, x) for x in indexes] if self._sort \
else [self._index.index(x) for x in indexes]
data = [self._data[i] for i in locations]
index = [self._index[i] for i in locations]
return data if as_list else Series(data=data, index=index, data_name=self._data_name,
index_name=self._index_name, sort=self._sort) |
<SYSTEM_TASK:>
For list of locations return a Series or list of the values.
<END_TASK>
<USER_TASK:>
Description:
def get_locations(self, locations, as_list=False):
"""
For list of locations return a Series or list of the values.
:param locations: list of index locations
:param as_list: True to return a list of values
:return: Series or list
""" |
indexes = [self._index[x] for x in locations]
return self.get(indexes, as_list) |
<SYSTEM_TASK:>
Returns a dict where the keys are the data and index names and the values are list of the data and index.
<END_TASK>
<USER_TASK:>
Description:
def to_dict(self, index=True, ordered=False):
"""
Returns a dict where the keys are the data and index names and the values are list of the data and index.
:param index: If True then include the index in the dict with the index_name as the key
:param ordered: If True then return an OrderedDict() to preserve the order of the columns in the Series
:return: dict or OrderedDict()
""" |
result = OrderedDict() if ordered else dict()
if index:
result.update({self._index_name: self._index})
if ordered:
data_dict = [(self._data_name, self._data)]
else:
data_dict = {self._data_name: self._data}
result.update(data_dict)
return result |
<SYSTEM_TASK:>
Return a Series of the first N rows
<END_TASK>
<USER_TASK:>
Description:
def head(self, rows):
"""
Return a Series of the first N rows
:param rows: number of rows
:return: Series
""" |
rows_bool = [True] * min(rows, len(self._index))
rows_bool.extend([False] * max(0, len(self._index) - rows))
return self.get(indexes=rows_bool) |
<SYSTEM_TASK:>
Math helper method. Given a column and optional indexes will return a list of booleans on the equality of the
<END_TASK>
<USER_TASK:>
Description:
def equality(self, indexes=None, value=None):
"""
Math helper method. Given a column and optional indexes will return a list of booleans on the equality of the
value for that index in the DataFrame to the value parameter.
:param indexes: list of index values or list of booleans. If a list of booleans then the list must be the same\
length as the DataFrame
:param value: value to compare
:return: list of booleans
""" |
indexes = [True] * len(self._index) if indexes is None else indexes
compare_list = self.get_rows(indexes, as_list=True)
return [x == value for x in compare_list] |
<SYSTEM_TASK:>
Sort the Series by the index. The sort modifies the Series inplace
<END_TASK>
<USER_TASK:>
Description:
def sort_index(self):
"""
Sort the Series by the index. The sort modifies the Series inplace
:return: nothing
""" |
sort = sorted_list_indexes(self._index)
# sort index
self._index = blist([self._index[x] for x in sort]) if self._blist else [self._index[x] for x in sort]
# sort data
self._data = blist([self._data[x] for x in sort]) if self._blist else [self._data[x] for x in sort] |
<SYSTEM_TASK:>
Given indexes will set a sub-set of the Series to the values provided. This method will direct to the below
<END_TASK>
<USER_TASK:>
Description:
def set(self, indexes, values=None):
"""
Given indexes will set a sub-set of the Series to the values provided. This method will direct to the below
methods based on what types are passed in for the indexes. If the indexes contains values not in the Series
then new rows or columns will be added.
:param indexes: indexes value, list of indexes values, or a list of booleans.
:param values: value or list of values to set. If a list then must be the same length as the indexes parameter.
:return: nothing
""" |
if isinstance(indexes, (list, blist)):
self.set_rows(indexes, values)
else:
self.set_cell(indexes, values) |
<SYSTEM_TASK:>
Add a new row to the Series
<END_TASK>
<USER_TASK:>
Description:
def _add_row(self, index):
"""
Add a new row to the Series
:param index: index of the new row
:return: nothing
""" |
self._index.append(index)
self._data.append(None) |
<SYSTEM_TASK:>
Insert a new row in the Series.
<END_TASK>
<USER_TASK:>
Description:
def _insert_row(self, i, index):
"""
Insert a new row in the Series.
:param i: index location to insert
:param index: index value to insert into the index list
:return: nothing
""" |
if i == len(self._index):
self._add_row(index)
else:
self._index.insert(i, index)
self._data.insert(i, None) |
<SYSTEM_TASK:>
Given a list of indexes, find all the indexes that are not currently in the Series and make a new row for
<END_TASK>
<USER_TASK:>
Description:
def _add_missing_rows(self, indexes):
"""
Given a list of indexes, find all the indexes that are not currently in the Series and make a new row for
that index by appending to the Series. This does not maintain sorted order for the index.
:param indexes: list of indexes
:return: nothing
""" |
new_indexes = [x for x in indexes if x not in self._index]
for x in new_indexes:
self._add_row(x) |
<SYSTEM_TASK:>
Given a list of indexes, find all the indexes that are not currently in the Series and make a new row for
<END_TASK>
<USER_TASK:>
Description:
def _insert_missing_rows(self, indexes):
"""
Given a list of indexes, find all the indexes that are not currently in the Series and make a new row for
that index, inserting into the index. This requires the Series to be sorted=True
:param indexes: list of indexes
:return: nothing
""" |
new_indexes = [x for x in indexes if x not in self._index]
for x in new_indexes:
self._insert_row(bisect_left(self._index, x), x) |
<SYSTEM_TASK:>
Sets the value of a single cell. If the index is not in the current index then a new index will be created.
<END_TASK>
<USER_TASK:>
Description:
def set_cell(self, index, value):
"""
Sets the value of a single cell. If the index is not in the current index then a new index will be created.
:param index: index value
:param value: value to set
:return: nothing
""" |
if self._sort:
exists, i = sorted_exists(self._index, index)
if not exists:
self._insert_row(i, index)
else:
try:
i = self._index.index(index)
except ValueError:
i = len(self._index)
self._add_row(index)
self._data[i] = value |
<SYSTEM_TASK:>
Set rows to a single value or list of values. If any of the index values are not in the current indexes
<END_TASK>
<USER_TASK:>
Description:
def set_rows(self, index, values=None):
"""
Set rows to a single value or list of values. If any of the index values are not in the current indexes
then a new row will be created.
:param index: list of index values or list of booleans. If a list of booleans then the list must be the same\
length as the Series
:param values: either a single value or a list. The list must be the same length as the index list if the index\
list is values, or the length of the True values in the index list if the index list is booleans
:return: nothing
""" |
if all([isinstance(i, bool) for i in index]): # boolean list
if not isinstance(values, (list, blist)): # single value provided, not a list, so turn values into list
values = [values for x in index if x]
if len(index) != len(self._index):
raise ValueError('boolean index list must be same size of existing index')
if len(values) != index.count(True):
raise ValueError('length of values list must equal number of True entries in index list')
indexes = [i for i, x in enumerate(index) if x]
for x, i in enumerate(indexes):
self._data[i] = values[x]
else: # list of index
if not isinstance(values, (list, blist)): # single value provided, not a list, so turn values into list
values = [values for _ in index]
if len(values) != len(index):
raise ValueError('length of values and index must be the same.')
# insert or append indexes as needed
if self._sort:
exists_tuples = list(zip(*[sorted_exists(self._index, x) for x in index]))
exists = exists_tuples[0]
indexes = exists_tuples[1]
if not all(exists):
self._insert_missing_rows(index)
indexes = [sorted_index(self._index, x) for x in index]
else:
try: # all index in current index
indexes = [self._index.index(x) for x in index]
except ValueError: # new rows need to be added
self._add_missing_rows(index)
indexes = [self._index.index(x) for x in index]
for x, i in enumerate(indexes):
self._data[i] = values[x] |
<SYSTEM_TASK:>
For a list of locations set the values.
<END_TASK>
<USER_TASK:>
Description:
def set_locations(self, locations, values):
"""
For a list of locations set the values.
:param locations: list of index locations
:param values: list of values or a single value
:return: nothing
""" |
indexes = [self._index[x] for x in locations]
self.set(indexes, values) |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.