text_prompt
stringlengths
157
13.1k
code_prompt
stringlengths
7
19.8k
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def collapse_spaces(text): """Remove newlines, tabs and multiple spaces with single spaces."""
if not isinstance(text, six.string_types): return text return COLLAPSE_RE.sub(WS, text).strip(WS)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def normalize(text, lowercase=True, collapse=True, latinize=False, ascii=False, encoding_default='utf-8', encoding=None, replace_categories=UNICODE_CATEGORIES): ...
text = stringify(text, encoding_default=encoding_default, encoding=encoding) if text is None: return if lowercase: # Yeah I made a Python package for this. text = text.lower() if ascii: # A stricter form of transliteration that leaves only ASCII ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def slugify(text, sep='-'): """A simple slug generator."""
text = stringify(text) if text is None: return None text = text.replace(sep, WS) text = normalize(text, ascii=True) if text is None: return None return text.replace(WS, sep)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def latinize_text(text, ascii=False): """Transliterate the given text to the latin script. This attempts to convert a given text to latin script using the closes...
if text is None or not isinstance(text, six.string_types) or not len(text): return text if ascii: if not hasattr(latinize_text, '_ascii'): # Transform to latin, separate accents, decompose, remove # symbols, compose, push to ASCII latinize_text._ascii = Tran...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def ascii_text(text): """Transliterate the given text and make sure it ends up as ASCII."""
text = latinize_text(text, ascii=True) if isinstance(text, six.text_type): text = text.encode('ascii', 'ignore').decode('ascii') return text
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def message(self): """Return default message for this element """
if self.code != 200: for code in self.response_codes: if code.code == self.code: return code.message raise ValueError("Unknown response code \"%s\" in \"%s\"." % (self.code, self.name)) return "OK"
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_default_sample(self): """Return default value for the element """
if self.type not in Object.Types or self.type is Object.Types.type: return self.type_object.get_sample() else: return self.get_object().get_sample()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def main(): """Main function to run command """
configParser = FileParser() logging.config.dictConfig( configParser.load_from_file(os.path.join(os.path.dirname(os.path.dirname(__file__)), 'settings', 'logging.yml')) ) ApiDoc().main()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _init_config(self): """return command's configuration from call's arguments """
options = self.parser.parse_args() if options.config is None and options.input is None: self.parser.print_help() sys.exit(2) if options.config is not None: configFactory = ConfigFactory() config = configFactory.load_from_file(options.config) ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _watch_refresh_source(self, event): """Refresh sources then templates """
self.logger.info("Sources changed...") try: self.sources = self._get_sources() self._render_template(self.sources) except: pass
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _watch_refresh_template(self, event): """Refresh template's contents """
self.logger.info("Template changed...") try: self._render_template(self.sources) except: pass
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def add_property(attribute, type): """Add a property to a class """
def decorator(cls): """Decorator """ private = "_" + attribute def getAttr(self): """Property getter """ if getattr(self, private) is None: setattr(self, private, type()) return getattr(self, private) def setA...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _merge_files(self, input_files, output_file): """Combine the input files to a big output file"""
# we assume that all the input files have the same charset with open(output_file, mode='wb') as out: for input_file in input_files: out.write(open(input_file, mode='rb').read())
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def merge_extends(self, target, extends, inherit_key="inherit", inherit=False): """Merge extended dicts """
if isinstance(target, dict): if inherit and inherit_key in target and not to_boolean(target[inherit_key]): return if not isinstance(extends, dict): raise ValueError("Unable to merge: Dictionnary expected") for key in extends: i...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def merge_sources(self, datas): """Merge sources files """
datas = [data for data in datas if data is not None] if len(datas) == 0: raise ValueError("Data missing") if len(datas) == 1: return datas[0] if isinstance(datas[0], list): if len([x for x in datas if not isinstance(x, list)]) > 0: ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def merge_configs(self, config, datas): """Merge configs files """
if not isinstance(config, dict) or len([x for x in datas if not isinstance(x, dict)]) > 0: raise TypeError("Unable to merge: Dictionnary expected") for key, value in config.items(): others = [x[key] for x in datas if key in x] if len(others) > 0: if ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create_from_dictionary(self, datas): """Return a populated object Configuration from dictionnary datas """
configuration = ObjectConfiguration() if "uri" in datas: configuration.uri = str(datas["uri"]) if "title" in datas: configuration.title = str(datas["title"]) if "description" in datas: configuration.description = str(datas["description"]) re...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create_from_name_and_dictionary(self, name, datas): """Return a populated object Parameter from dictionary datas """
parameter = ObjectParameter() self.set_common_datas(parameter, name, datas) if "optional" in datas: parameter.optional = to_boolean(datas["optional"]) if "type" in datas: parameter.type = str(datas["type"]) if "generic" in datas: parameter.ge...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def validate(self, sources): """Validate the format of sources """
if not isinstance(sources, Root): raise Exception("Source object expected") parameters = self.get_uri_with_missing_parameters(sources) for parameter in parameters: logging.getLogger().warn('Missing parameter "%s" in uri of method "%s" in versions "%s"' % (parameter["nam...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def validate(self, config): """Validate that the source file is ok """
if not isinstance(config, ConfigObject): raise Exception("Config object expected") if config["output"]["componants"] not in ("local", "remote", "embedded", "without"): raise ValueError("Unknown componant \"%s\"." % config["output"]["componants"]) if config["output"]["l...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_template_from_config(self, config): """Retrieve a template path from the config object """
if config["output"]["template"] == "default": return os.path.join( os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'template', 'default.html' ) else: return os.path.abspath(config["output"]["template"])
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create_from_dictionary(self, datas): """Return a populated object ResponseCode from dictionary datas """
if "code" not in datas: raise ValueError("A response code must contain a code in \"%s\"." % repr(datas)) code = ObjectResponseCode() self.set_common_datas(code, str(datas["code"]), datas) code.code = int(datas["code"]) if "message" in datas: code.messag...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def add_handler(self, path, handler): """Add a path in watch queue """
self.signatures[path] = self.get_path_signature(path) self.handlers[path] = handler
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_path_signature(self, path): """generate a unique signature for file contained in path """
if not os.path.exists(path): return None if os.path.isdir(path): merge = {} for root, dirs, files in os.walk(path): for name in files: full_name = os.path.join(root, name) merge[full_name] = os.stat(full_name) ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def check(self): """Check if a file is changed """
for (path, handler) in self.handlers.items(): current_signature = self.signatures[path] new_signature = self.get_path_signature(path) if new_signature != current_signature: self.signatures[path] = new_signature handler.on_change(Event(path))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create_from_name_and_dictionary(self, name, datas): """Return a populated object Category from dictionary datas """
category = ObjectCategory(name) self.set_common_datas(category, name, datas) if "order" in datas: category.order = int(datas["order"]) return category
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def load_from_file(self, file_path, format=None): """Return dict from a file config """
if format is None: base_name, file_extension = os.path.splitext(file_path) if file_extension in (".yaml", ".yml"): format = "yaml" elif file_extension in (".json"): format = "json" else: raise ValueError("Config fil...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def load_all_from_directory(self, directory_path): """Return a list of dict from a directory containing files """
datas = [] for root, folders, files in os.walk(directory_path): for f in files: datas.append(self.load_from_file(os.path.join(root, f))) return datas
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def json_repr(obj): """Represent instance of a class as JSON. """
def serialize(obj): """Recursively walk object's hierarchy. """ if obj is None: return None if isinstance(obj, Enum): return str(obj) if isinstance(obj, (bool, int, float, str)): return obj if isinstance(obj, dict): ob...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create_from_root(self, root_source): """Return a populated Object Root from dictionnary datas """
root_dto = ObjectRoot() root_dto.configuration = root_source.configuration root_dto.versions = [Version(x) for x in root_source.versions.values()] for version in sorted(root_source.versions.values()): hydrator = Hydrator(version, root_source.versions, root_source.versions...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_common_datas(self, element, name, datas): """Populated common data for an element from dictionnary datas """
element.name = str(name) if "description" in datas: element.description = str(datas["description"]).strip() if isinstance(element, Sampleable) and element.sample is None and "sample" in datas: element.sample = str(datas["sample"]).strip() if isinstance(element,...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create_dictionary_of_element_from_dictionary(self, property_name, datas): """Populate a dictionary of elements """
response = {} if property_name in datas and datas[property_name] is not None and isinstance(datas[property_name], collections.Iterable): for key, value in datas[property_name].items(): response[key] = self.create_from_name_and_dictionary(key, value) return response
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create_list_of_element_from_dictionary(self, property_name, datas): """Populate a list of elements """
response = [] if property_name in datas and datas[property_name] is not None and isinstance(datas[property_name], list): for value in datas[property_name]: response.append(self.create_from_dictionary(value)) return response
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_enum(self, property, enum, datas): """Factory enum type """
str_property = str(datas[property]).lower() if str_property not in enum: raise ValueError("Unknow enum \"%s\" for \"%s\"." % (str_property, property)) return enum(str_property)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create_from_config(self, config): """Create a template object file defined in the config object """
configService = ConfigService() template = TemplateService() template.output = config["output"]["location"] template_file = configService.get_template_from_config(config) template.input = os.path.basename(template_file) template.env = Environment(loader=FileSystemLoad...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def deploy(self, id_networkv4): """Deploy network in equipments and set column 'active = 1' in tables redeipv4 :param id_networkv4: ID for NetworkIPv4 :return: E...
data = dict() uri = 'api/networkv4/%s/equipments/' % id_networkv4 return super(ApiNetworkIPv4, self).post(uri, data=data)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_by_id(self, id_networkv4): """Get IPv4 network :param id_networkv4: ID for NetworkIPv4 :return: IPv4 Network """
uri = 'api/networkv4/%s/' % id_networkv4 return super(ApiNetworkIPv4, self).get(uri)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def list(self, environment_vip=None): """List IPv4 networks :param environment_vip: environment vip to filter :return: IPv4 Networks """
uri = 'api/networkv4/?' if environment_vip: uri += 'environment_vip=%s' % environment_vip return super(ApiNetworkIPv4, self).get(uri)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def undeploy(self, id_networkv4): """Remove deployment of network in equipments and set column 'active = 0' in tables redeipv4 ] :param id_networkv4: ID for Netw...
uri = 'api/networkv4/%s/equipments/' % id_networkv4 return super(ApiNetworkIPv4, self).delete(uri)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def check_vip_ip(self, ip, environment_vip): """ Check available ip in environment vip """
uri = 'api/ipv4/ip/%s/environment-vip/%s/' % (ip, environment_vip) return super(ApiNetworkIPv4, self).get(uri)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def delete(self, ids): """ Method to delete network-ipv4's by their ids :param ids: Identifiers of network-ipv4's :return: None """
url = build_uri_with_ids('api/v3/networkv4/%s/', ids) return super(ApiNetworkIPv4, self).delete(url)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def update(self, networkipv4s): """ Method to update network-ipv4's :param networkipv4s: List containing network-ipv4's desired to updated :return: None """
data = {'networks': networkipv4s} networkipv4s_ids = [str(networkipv4.get('id')) for networkipv4 in networkipv4s] return super(ApiNetworkIPv4, self).put('api/v3/networkv4/%s/' % ';'.join(networkipv4s_ids), data)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create(self, networkipv4s): """ Method to create network-ipv4's :param networkipv4s: List containing networkipv4's desired to be created on database :return:...
data = {'networks': networkipv4s} return super(ApiNetworkIPv4, self).post('api/v3/networkv4/', data)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def inserir(self, name): """Inserts a new Division Dc and returns its identifier. :param name: Division Dc name. String with a minimum 2 and maximum of 80 charac...
division_dc_map = dict() division_dc_map['name'] = name code, xml = self.submit( {'division_dc': division_dc_map}, 'POST', 'divisiondc/') return self.response(code, xml)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def alterar(self, id_divisiondc, name): """Change Division Dc from by the identifier. :param id_divisiondc: Identifier of the Division Dc. Integer value and grea...
if not is_valid_int_param(id_divisiondc): raise InvalidParameterError( u'The identifier of Division Dc is invalid or was not informed.') url = 'divisiondc/' + str(id_divisiondc) + '/' division_dc_map = dict() division_dc_map['name'] = name code, x...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def remover(self, id_divisiondc): """Remove Division Dc from by the identifier. :param id_divisiondc: Identifier of the Division Dc. Integer value and greater th...
if not is_valid_int_param(id_divisiondc): raise InvalidParameterError( u'The identifier of Division Dc is invalid or was not informed.') url = 'divisiondc/' + str(id_divisiondc) + '/' code, xml = self.submit(None, 'DELETE', url) return self.response(code,...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def search(self, **kwargs): """ Method to search object types based on extends search. :param search: Dict containing QuerySets to find object types. :param incl...
return super(ApiObjectType, self).get(self.prepare_url('api/v3/object-type/', kwargs))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def insert_vlan( self, environment_id, name, number, description, acl_file, acl_file_v6, network_ipv4, network_ipv6, vrf=None): """Create new VLAN :param environ...
if not is_valid_int_param(environment_id): raise InvalidParameterError(u'Environment id is none or invalid.') if not is_valid_int_param(number): raise InvalidParameterError(u'Vlan number is none or invalid') vlan_map = dict() vlan_map['environment_id'] = envir...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def edit_vlan( self, environment_id, name, number, description, acl_file, acl_file_v6, id_vlan): """Edit a VLAN :param id_vlan: ID for Vlan :param environment_id...
if not is_valid_int_param(id_vlan): raise InvalidParameterError( u'Vlan id is invalid or was not informed.') if not is_valid_int_param(environment_id): raise InvalidParameterError(u'Environment id is none or invalid.') if not is_valid_int_param(number)...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create_vlan(self, id_vlan): """ Set column 'ativada = 1'. :param id_vlan: VLAN identifier. :return: None """
vlan_map = dict() vlan_map['vlan_id'] = id_vlan code, xml = self.submit({'vlan': vlan_map}, 'PUT', 'vlan/create/') return self.response(code, xml)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def allocate_without_network(self, environment_id, name, description, vrf=None): """Create new VLAN without add NetworkIPv4. :param environment_id: ID for Enviro...
vlan_map = dict() vlan_map['environment_id'] = environment_id vlan_map['name'] = name vlan_map['description'] = description vlan_map['vrf'] = vrf code, xml = self.submit({'vlan': vlan_map}, 'POST', 'vlan/no-network/') return self.response(code, xml)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def verificar_permissao(self, id_vlan, nome_equipamento, nome_interface): """Check if there is communication permission for VLAN to trunk. Run script 'configurad...
if not is_valid_int_param(id_vlan): raise InvalidParameterError( u'Vlan id is invalid or was not informed.') url = 'vlan/' + str(id_vlan) + '/check/' vlan_map = dict() vlan_map['nome'] = nome_equipamento vlan_map['nome_interface'] = nome_interface ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def buscar(self, id_vlan): """Get VLAN by its identifier. :param id_vlan: VLAN identifier. :return: Following dictionary: :: {'vlan': {'id': < id_vlan >, 'nome':...
if not is_valid_int_param(id_vlan): raise InvalidParameterError( u'Vlan id is invalid or was not informed.') url = 'vlan/' + str(id_vlan) + '/' code, xml = self.submit(None, 'GET', url) return self.response(code, xml)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def listar_permissao(self, nome_equipamento, nome_interface): """List all VLANS having communication permission to trunk from a port in switch. Run script 'confi...
vlan_map = dict() vlan_map['nome'] = nome_equipamento vlan_map['nome_interface'] = nome_interface code, xml = self.submit({'equipamento': vlan_map}, 'PUT', 'vlan/list/') return self.response(code, xml)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def apply_acl(self, equipments, vlan, environment, network): '''Apply the file acl in equipments :param equipments: list of equipments :param vlan: Vvlan :param environment: Environment :param network: v4 or v6 :raise Exception: Failed to apply acl :return: Tru...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def confirm_vlan(self, number_net, id_environment_vlan, ip_version=None): """Checking if the vlan insert need to be confirmed :param number_net: Filter by vlan n...
url = 'vlan/confirm/' + \ str(number_net) + '/' + id_environment_vlan + '/' + str(ip_version) code, xml = self.submit(None, 'GET', url) return self.response(code, xml)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def check_number_available(self, id_environment, num_vlan, id_vlan): """Checking if environment has a number vlan available :param id_environment: Identifier of ...
url = 'vlan/check_number_available/' + \ str(id_environment) + '/' + str(num_vlan) + '/' + str(id_vlan) code, xml = self.submit(None, 'GET', url) return self.response(code, xml)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def validar(self, id_vlan): """Validates ACL - IPv4 of VLAN from its identifier. Assigns 1 to 'acl_valida'. :param id_vlan: Identifier of the Vlan. Integer value...
if not is_valid_int_param(id_vlan): raise InvalidParameterError( u'The identifier of Vlan is invalid or was not informed.') url = 'vlan/' + str(id_vlan) + '/validate/' + IP_VERSION.IPv4[0] + '/' code, xml = self.submit(None, 'PUT', url) return self.respon...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def validate_ipv6(self, id_vlan): """Validates ACL - IPv6 of VLAN from its identifier. Assigns 1 to 'acl_valida_v6'. :param id_vlan: Identifier of the Vlan. Inte...
if not is_valid_int_param(id_vlan): raise InvalidParameterError( u'The identifier of Vlan is invalid or was not informed.') url = 'vlan/' + str(id_vlan) + '/validate/' + IP_VERSION.IPv6[0] + '/' code, xml = self.submit(None, 'PUT', url) return self.respon...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def remove(self, id_vlan): """Remove a VLAN by your primary key. Execute script to remove VLAN :param id_vlan: ID for VLAN. :return: Following dictionary: :: {‘s...
if not is_valid_int_param(id_vlan): raise InvalidParameterError( u'Parameter id_vlan is invalid. Value: ' + id_vlan) url = 'vlan/' + str(id_vlan) + '/remove/' code, xml = self.submit(None, 'DELETE', url) return self.response(code, xml)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def deallocate(self, id_vlan): """Deallocate all relationships between Vlan. :param id_vlan: Identifier of the VLAN. Integer value and greater than zero. :return...
if not is_valid_int_param(id_vlan): raise InvalidParameterError( u'The identifier of Vlan is invalid or was not informed.') url = 'vlan/' + str(id_vlan) + '/deallocate/' code, xml = self.submit(None, 'DELETE', url) return self.response(code, xml)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def create_script_acl(self, id_vlan, network_type): '''Generate the script acl :param id_vlan: Vlan Id :param network_type: v4 or v6 :raise InvalidValueError: Attrs invalids. :raise XMLError: Networkapi failed to generate the XML response. :raise VlanACLDuplicatedError:...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def inserir(self, id_user, id_group): """Create a relationship between User and Group. :param id_user: Identifier of the User. Integer value and greater than zer...
if not is_valid_int_param(id_user): raise InvalidParameterError( u'The identifier of User is invalid or was not informed.') if not is_valid_int_param(id_group): raise InvalidParameterError( u'The identifier of Group is invalid or was not informed...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def search(self, **kwargs): """ Method to search neighbors based on extends search. :param search: Dict containing QuerySets to find neighbors. :param include: A...
return super(ApiV4Neighbor, self).get(self.prepare_url( 'api/v4/neighbor/', kwargs))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def delete(self, ids): """ Method to delete neighbors by their id's :param ids: Identifiers of neighbors :return: None """
url = build_uri_with_ids('api/v4/neighbor/%s/', ids) return super(ApiV4Neighbor, self).delete(url)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def update(self, neighbors): """ Method to update neighbors :param neighbors: List containing neighbors desired to updated :return: None """
data = {'neighbors': neighbors} neighbors_ids = [str(env.get('id')) for env in neighbors] return super(ApiV4Neighbor, self).put('api/v4/neighbor/%s/' % ';'.join(neighbors_ids), data)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create(self, neighbors): """ Method to create neighbors :param neighbors: List containing neighbors desired to be created on database :return: None """
data = {'neighbors': neighbors} return super(ApiV4Neighbor, self).post('api/v4/neighbor/', data)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_access(self, id_access): """Get Equipment Access by id. :return: Dictionary with following: :: {'equipamento_acesso': {'id_equipamento': < id_equipamento...
if not is_valid_int_param(id_access): raise InvalidParameterError(u'Equipment Access ID is invalid.') url = 'equipamentoacesso/id/' + str(id_access) + '/' code, xml = self.submit(None, 'GET', url) return self.response(code, xml)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def list_by_equip(self, name): """ List all equipment access by equipment name :return: Dictionary with the following structure: :: {‘equipamento_acesso’:[ {'id'...
equip_access_map = dict() equip_access_map['name'] = name code, xml = self.submit( {"equipamento_acesso": equip_access_map}, 'POST', 'equipamentoacesso/name/') key = 'equipamento_acesso' return get_list_map(self.response(code, xml, [key]), key)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def inserir( self, id_equipamento, fqdn, user, password, id_tipo_acesso, enable_pass): """Add new relationship between equipment and access type and returns its ...
equipamento_acesso_map = dict() equipamento_acesso_map['id_equipamento'] = id_equipamento equipamento_acesso_map['fqdn'] = fqdn equipamento_acesso_map['user'] = user equipamento_acesso_map['pass'] = password equipamento_acesso_map['id_tipo_acesso'] = id_tipo_acesso ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def edit_by_id( self, id_equip_acesso, id_tipo_acesso, fqdn, user, password, enable_pass): """Edit access type, fqdn, user, password and enable_pass of the relat...
if not is_valid_int_param(id_tipo_acesso): raise InvalidParameterError( u'Access type id is invalid or not informed.') equipamento_acesso_map = dict() equipamento_acesso_map['fqdn'] = fqdn equipamento_acesso_map['user'] = user equipamento_acesso_map...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def remover(self, id_tipo_acesso, id_equipamento): """Removes relationship between equipment and access type. :param id_equipamento: Equipment identifier. :param...
if not is_valid_int_param(id_tipo_acesso): raise InvalidParameterError(u'Access type id is invalid.') if not is_valid_int_param(id_equipamento): raise InvalidParameterError(u'Equipment id is invalid.') url = 'equipamentoacesso/' + \ str(id_equipamento) + '...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def remove(self, pools): """ Remove Pools Running Script And Update to Not Created :param ids: List of ids :return: None on success :raise ScriptRemovePoolExcept...
data = dict() data["pools"] = pools uri = "api/pools/v2/" return self.delete(uri, data)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create(self, pools): """ Create Pools Running Script And Update to Created :param pools: List of pools :return: None on success :raise PoolDoesNotExistExcept...
data = dict() data["pools"] = pools uri = "api/pools/v2/" return self.put(uri, data)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def enable(self, ids): """ Enable Pool Members Running Script :param ids: List of ids :return: None on success :raise PoolMemberDoesNotExistException :raise Inva...
data = dict() data["ids"] = ids uri = "api/pools/enable/" return self.post(uri, data)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def disable(self, ids): """ Disable Pool Members Running Script :param ids: List of ids :return: None on success :raise PoolMemberDoesNotExistException :raise In...
data = dict() data["ids"] = ids uri = "api/pools/disable/" return self.post(uri, data)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def search(self, **kwargs): """ Method to search object group permissions based on extends search. :param search: Dict containing QuerySets to find object group ...
return super(ApiObjectGroupPermission, self).get(self.prepare_url('api/v3/object-group-perm/', kwargs))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def delete(self, ids): """ Method to delete object group permissions by their ids :param ids: Identifiers of object group permissions :return: None """
url = build_uri_with_ids('api/v3/object-group-perm/%s/', ids) return super(ApiObjectGroupPermission, self).delete(url)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def update(self, ogps): """ Method to update object group permissions :param ogps: List containing object group permissions desired to updated :return: None """
data = {'ogps': ogps} ogps_ids = [str(ogp.get('id')) for ogp in ogps] return super(ApiObjectGroupPermission, self).put('api/v3/object-group-perm/%s/' % ';'.join(ogps_ids), data)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create(self, ogps): """ Method to create object group permissions :param ogps: List containing vrf desired to be created on database :return: None """
data = {'ogps': ogps} return super(ApiObjectGroupPermission, self).post('api/v3/object-group-perm/', data)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def inserir(self, id_equipment, id_script): """Inserts a new Related Equipment with Script and returns its identifier :param id_equipment: Identifier of the Equi...
equipment_script_map = dict() equipment_script_map['id_equipment'] = id_equipment equipment_script_map['id_script'] = id_script code, xml = self.submit( {'equipment_script': equipment_script_map}, 'POST', 'equipmentscript/') return self.response(code, xml)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def search(self, **kwargs): """ Method to search vrf's based on extends search. :param search: Dict containing QuerySets to find vrf's. :param include: Array con...
return super(ApiVrf, self).get(self.prepare_url('api/v3/vrf/', kwargs))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def delete(self, ids): """ Method to delete vrf's by their id's :param ids: Identifiers of vrf's :return: None """
url = build_uri_with_ids('api/v3/vrf/%s/', ids) return super(ApiVrf, self).delete(url)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def update(self, vrfs): """ Method to update vrf's :param vrfs: List containing vrf's desired to updated :return: None """
data = {'vrfs': vrfs} vrfs_ids = [str(vrf.get('id')) for vrf in vrfs] return super(ApiVrf, self).put('api/v3/vrf/%s/' % ';'.join(vrfs_ids), data)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create(self, vrfs): """ Method to create vrf's :param vrfs: List containing vrf's desired to be created on database :return: None """
data = {'vrfs': vrfs} return super(ApiVrf, self).post('api/v3/vrf/', data)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def inserir(self, name): """Inserts a new Equipment Type and returns its identifier :param name: Equipment Type name. String with a minimum 3 and maximum of 100 ...
equipment_type_map = dict() equipment_type_map['name'] = name url = 'equipmenttype/' code, xml = self.submit( {'equipment_type': equipment_type_map}, 'POST', url) return self.response(code, xml)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def inserir(self, id_equipment, id_environment, is_router=0): """Inserts a new Related Equipment with Environment and returns its identifier :param id_equipment:...
equipment_environment_map = dict() equipment_environment_map['id_equipamento'] = id_equipment equipment_environment_map['id_ambiente'] = id_environment equipment_environment_map['is_router'] = is_router code, xml = self.submit( {'equipamento_ambiente': equipment_env...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def inserir(self, name): """Inserts a new Group L3 and returns its identifier. :param name: Group L3 name. String with a minimum 2 and maximum of 80 characters :...
group_l3_map = dict() group_l3_map['name'] = name code, xml = self.submit({'group_l3': group_l3_map}, 'POST', 'groupl3/') return self.response(code, xml)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def alterar(self, id_groupl3, name): """Change Group L3 from by the identifier. :param id_groupl3: Identifier of the Group L3. Integer value and greater than zer...
if not is_valid_int_param(id_groupl3): raise InvalidParameterError( u'The identifier of Group L3 is invalid or was not informed.') url = 'groupl3/' + str(id_groupl3) + '/' group_l3_map = dict() group_l3_map['name'] = name code, xml = self.submit({...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def remover(self, id_groupl3): """Remove Group L3 from by the identifier. :param id_groupl3: Identifier of the Group L3. Integer value and greater than zero. :re...
if not is_valid_int_param(id_groupl3): raise InvalidParameterError( u'The identifier of Group L3 is invalid or was not informed.') url = 'groupl3/' + str(id_groupl3) + '/' code, xml = self.submit(None, 'DELETE', url) return self.response(code, xml)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_full_url(self, parsed_url): """ Returns url path with querystring """
full_path = parsed_url.path if parsed_url.query: full_path = '%s?%s' % (full_path, parsed_url.query) return full_path
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def search(self, **kwargs): """ Method to search Virtual Interfaces based on extends search. :param search: Dict containing QuerySets to find Virtual Interfaces....
return super(ApiV4VirtualInterface, self).get(self.prepare_url( 'api/v4/virtual-interface/', kwargs))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def delete(self, ids): """ Method to delete Virtual Interfaces by their id's :param ids: Identifiers of Virtual Interfaces :return: None """
url = build_uri_with_ids('api/v4/virtual-interface/%s/', ids) return super(ApiV4VirtualInterface, self).delete(url)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def update(self, virtual_interfaces): """ Method to update Virtual Interfaces :param Virtual Interfaces: List containing Virtual Interfaces desired to updated :r...
data = {'virtual_interfaces': virtual_interfaces} virtual_interfaces_ids = [str(env.get('id')) for env in virtual_interfaces] return super(ApiV4VirtualInterface, self).put\ ('api/v4/virtual-interface/%s/' % ';'.join(virtual_interfaces_ids), data)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create(self, virtual_interfaces): """ Method to create Virtual Interfaces :param Virtual Interfaces: List containing Virtual Interfaces desired to be created...
data = {'virtual_interfaces': virtual_interfaces} return super(ApiV4VirtualInterface, self).post\ ('api/v4/virtual-interface/', data)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def search(self, id_ugroup): """Search Group User by its identifier. :param id_ugroup: Identifier of the Group User. Integer value and greater than zero. :return...
if not is_valid_int_param(id_ugroup): raise InvalidParameterError( u'The identifier of Group User is invalid or was not informed.') url = 'ugroup/get/' + str(id_ugroup) + '/' code, xml = self.submit(None, 'GET', url) return self.response(code, xml)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def inserir(self, name, read, write, edit, remove): """Insert new user group and returns its identifier. :param name: User group's name. :param read: If user gro...
ugroup_map = dict() ugroup_map['nome'] = name ugroup_map['leitura'] = read ugroup_map['escrita'] = write ugroup_map['edicao'] = edit ugroup_map['exclusao'] = remove code, xml = self.submit({'user_group': ugroup_map}, 'POST', 'ugroup/') return self.respo...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def alterar(self, id_user_group, name, read, write, edit, remove): """Edit user group data from its identifier. :param id_user_group: User group id. :param name:...
if not is_valid_int_param(id_user_group): raise InvalidParameterError( u'Invalid or inexistent user group id.') url = 'ugroup/' + str(id_user_group) + '/' ugroup_map = dict() ugroup_map['nome'] = name ugroup_map['leitura'] = read ugroup_map[...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def remover(self, id_user_group): """Removes a user group by its id. :param id_user_group: User Group's identifier. Valid integer greater than zero. :return: Non...
if not is_valid_int_param(id_user_group): raise InvalidParameterError( u'Invalid or inexistent user group id.') url = 'ugroup/' + str(id_user_group) + '/' code, xml = self.submit(None, 'DELETE', url) return self.response(code, xml)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_environment(self, environment_ids): """ Method to get environment """
uri = 'api/v3/environment/%s/' % environment_ids return super(ApiEnvironment, self).get(uri)