output stringlengths 1 928k | instruction stringlengths 7 928k | system stringlengths 0 104k |
|---|---|---|
def _allocate_segment(self, session, net_id, source):
"""Allocate segment from pool.
Return allocated db object or None.
"""
with session.begin(subtransactions=True):
hour_lapse = utils.utc_time_lapse(self.seg_timeout)
count = (session.query(self.model).filter(
... | Implement a function in Python 3 to
allocate a segment from pool. MimeType. | As a Python code translator, you convert algorithms and pseudocode into Python. |
def allocate_subnet(self, subnet_lst, net_id=None):
"""Allocate subnet from pool.
Return allocated db object or None.
"""
session = db.get_session()
query_str = None
for sub in subnet_lst:
sub_que = (self.model.subnet_address != sub)
if query_str... | Implement a function in Python 3 to
allocate subnet from pool. Return allocated db object or None. | You are a Python code generator, capable of creating scripts from specifications. |
def add_update_topology_db(self, **params):
"""Add or update an entry to the topology DB. """
topo_dict = params.get('columns')
session = db.get_session()
host = topo_dict.get('host')
protocol_interface = topo_dict.get('protocol_interface')
with session.begin(subtransacti... | Create a Python 3 function to
add or update an entry to the topology DB. | You are a Python code architect, reviewing and designing scalable and efficient code |
def _convert_topo_obj_dict(self, topology_objs):
"""Convert topology object to dict. """
topo_lst = []
for topo_obj in topology_objs:
topo_dct = {
'host': topo_obj.host,
'protocol_interface': topo_obj.protocol_interface,
'phy_interface'... | Implement a function in Python 3 to
convert a list of topology objects to a list of dict. | As a Python code translator, you convert algorithms and pseudocode into Python. |
def query_topology_db(self, dict_convert=False, **req):
"""Query an entry to the topology DB. """
session = db.get_session()
with session.begin(subtransactions=True):
try:
# Check if entry exists.
topo_disc = session.query(DfaTopologyDb).filter_by(**re... | Write a Python 3 script for
querying an entry to the topology DB. | As a Python code translator, you convert algorithms and pseudocode into Python. |
Delete the entries from the topology DB. | Can you tell what is the following Python 3 function doing
def delete_topology_entry(self, **req):
session = db.get_session()
with session.begin(subtransactions=True):
try:
rows = session.query(DfaTopologyDb).filter_by(**req).all()
except orm_exc.NoResultFound:
... | As a Python code composer, you craft elegant and concise scripts. |
def enable_lldp(self, port_name, is_ncb=True, is_nb=False):
"""Function to enable LLDP on the interface. """
reply = None
if is_ncb:
reply = self.run_lldptool(["-L", "-i", port_name, "-g", "ncb",
"adminStatus=rxtx"])
elif is_nb:
... | Write a Python 3 function for
functioning to enable LLDP on the interface. | As a Python code composer, you craft elegant and concise scripts. |
Function to Query LLDP TLV on the interface. | Make a summary of the following Python 3 code
def get_lldp_tlv(self, port_name, is_ncb=True, is_nb=False):
reply = None
if is_ncb:
reply = self.run_lldptool(["get-tlv", "-n", "-i", port_name,
"-g", "ncb"])
elif is_nb:
reply = self.ru... | You are a Python code generator, capable of creating scripts from specifications. |
def run_lldptool(self, args):
"""Function for invoking the lldptool utility. """
full_args = ['lldptool'] + args
try:
return utils.execute(full_args, root_helper=self.root_helper)
except Exception as exc:
LOG.error("Unable to execute %(cmd)s. "
... | Implement a Python 3 function for
functioning for invoking the lldptool utility. | You are a Python code generator, capable of creating scripts from specifications. |
def _check_common_tlv_format(self, tlv_complete_data, tlv_data_pattern,
tlv_string):
"""Check for the common TLV format. """
if tlv_complete_data is None:
return False, None
tlv_string_split = tlv_complete_data.split(tlv_string)
if len(tlv_str... | Write a Python 3 script for
checking if the common TLV format is valid. | You are a Python code generator, capable of creating scripts from specifications. |
Returns the EVB mode in the TLV. | Make a summary of the following Python 3 code
def get_remote_evb_mode(self, tlv_data):
ret, parsed_val = self._check_common_tlv_format(
tlv_data, "mode:", "EVB Configuration TLV")
if not ret:
return None
mode_val = parsed_val[1].split()[0].strip()
return mode_val | As a python code expert, you are capable of creating scripts from specifications. |
Returns Remote Mgmt Addr from the TLV. | Can you generate the documentation for the following Python 3 function
def get_remote_mgmt_addr(self, tlv_data):
ret, parsed_val = self._check_common_tlv_format(
tlv_data, "IPv4:", "Management Address TLV")
if not ret:
return None
addr_fam = 'IPv4:'
addr = parsed_... | You are a Python code generator, capable of creating scripts from specifications. |
def get_remote_sys_desc(self, tlv_data):
"""Returns Remote Sys Desc from the TLV. """
ret, parsed_val = self._check_common_tlv_format(
tlv_data, "\n", "System Description TLV")
if not ret:
return None
return parsed_val[1].strip() | Write a Python 3 script for
returning Remote Sys Desc from the TLV. | You are a Python code analyst, evaluating scripts for potential improvements. |
Returns Remote Sys Name from the TLV. | Can you tell what is the following Python 3 function doing
def get_remote_sys_name(self, tlv_data):
ret, parsed_val = self._check_common_tlv_format(
tlv_data, "\n", "System Name TLV")
if not ret:
return None
return parsed_val[1].strip() | As a Python code composer, you craft elegant and concise scripts. |
Returns Remote Port from the TLV. | How would you explain what the following Python 3 function does
def get_remote_port(self, tlv_data):
ret, parsed_val = self._check_common_tlv_format(
tlv_data, "\n", "Port Description TLV")
if not ret:
return None
return parsed_val[1].strip() | As a Python code translator, you convert algorithms and pseudocode into Python. |
def get_remote_chassis_id_mac(self, tlv_data):
"""Returns Remote Chassis ID MAC from the TLV. """
ret, parsed_val = self._check_common_tlv_format(
tlv_data, "MAC:", "Chassis ID TLV")
if not ret:
return None
mac = parsed_val[1].split('\n')
return mac[0].str... | Write a Python 3 script for
returning Remote Chassis ID MAC from the TLV. | As a Python code analyst, you investigate and solve complex coding mysteries |
Returns Remote Port ID Local from the TLV. | Make a summary of the following Python 3 code
def get_remote_port_id_local(self, tlv_data):
ret, parsed_val = self._check_common_tlv_format(
tlv_data, "Local:", "Port ID TLV")
if not ret:
return None
local = parsed_val[1].split('\n')
return local[0].strip() | As a python code expert, you are capable of creating scripts from specifications. |
Method to format an interface name given type port and channel - group. | Given the following Python 3 function, write the documentation
def format_interface_name(intf_type, port, ch_grp=0):
if ch_grp > 0:
return 'port-channel:%s' % str(ch_grp)
return '%s:%s' % (intf_type.lower(), port) | You are a Python code architect, reviewing and designing scalable and efficient code |
Method to split interface name into type and id. | Explain what the following Python 3 code does
def split_interface_name(interface, ch_grp=0):
interface = interface.lower()
if ch_grp != 0:
intf_type = 'port-channel'
port = str(ch_grp)
elif ':' in interface:
intf_type, port = interface.split(':')
elif interface.startswith('ether... | You are a Python code architect, reviewing and designing scalable and efficient code |
def _host_notification(self, context, method, payload, host):
"""Notify the cfg agent that is handling the hosting device."""
LOG.debug('Notify Cisco cfg agent at %(host)s the message '
'%(method)s', {'host': host, 'method': method})
cctxt = self.client.prepare(server=host)
... | Can you write a function in Python 3 where it
notifies the cfg agent that the hosting device is handling the hosting device. | As a Python code composer, you craft elegant and concise scripts. |
Notify all cfg agents that have been approved. | Can you tell what is the following Python 3 function doing
def _agent_notification(self, context, method, hosting_devices, operation):
admin_context = context.is_admin and context or context.elevated()
for hosting_device in hosting_devices:
agents = self._dmplugin.get_cfg_agents_for_hosting_... | You are a Python code analyst, evaluating scripts for potential improvements. |
def agent_updated(self, context, admin_state_up, host):
"""Updates cfg agent on <host> to enable or disable it."""
self._host_notification(context, 'agent_updated',
{'admin_state_up': admin_state_up}, host) | Can you write a function in Python 3 where it
updates cfg agent on <host > to enable or disable it. | As a Python code translator, you convert algorithms and pseudocode into Python. |
def hosting_devices_unassigned_from_cfg_agent(self, context, ids, host):
"""Notify cfg agent to no longer handle some hosting devices.
This notification relieves the cfg agent in <host> of responsibility
to monitor and configure hosting devices with id specified in <ids>.
"""
se... | Create a Python 3 function to
notify cfg agent that some hosting devices are unassigned from the cfg agent. | As a Python code analyst, you investigate and solve complex coding mysteries |
Notify cfg agent that some hosting devices have been assigned to a cfg agent. | Can you tell what is the following Python 3 function doing
def hosting_devices_assigned_to_cfg_agent(self, context, ids, host):
self._host_notification(context,
'hosting_devices_assigned_to_cfg_agent',
{'hosting_device_ids': ids}, host) | You are a Python code architect, reviewing and designing scalable and efficient code |
def hosting_devices_removed(self, context, hosting_data, deconfigure,
host):
"""Notify cfg agent that some hosting devices have been removed.
This notification informs the cfg agent in <host> that the
hosting devices in the <hosting_data> dictionary have been rem... | Can you implement a function in Python 3 that
notifies cfg agent that some hosting devices have been removed from the hosting device pool. | You are a Python code analyst, evaluating scripts for potential improvements. |
Fetch configuration of hosting device with id. | Can you generate a brief explanation for the following Python 3 code
def get_hosting_device_configuration(self, context, id):
admin_context = context.is_admin and context or context.elevated()
agents = self._dmplugin.get_cfg_agents_for_hosting_devices(
admin_context, [id], admin_state_up=Tru... | As a Python code translator, you convert algorithms and pseudocode into Python. |
def store_policy(self, pol_id, policy):
"""Store the policy.
Policy is maintained as a dictionary of pol ID.
"""
if pol_id not in self.policies:
self.policies[pol_id] = policy
self.policy_cnt += 1 | Can you write a function in Python 3 where it
stores the policy. Policy is maintained as a dictionary of pol ID. | You are a Python code analyst, evaluating scripts for potential improvements. |
def store_rule(self, rule_id, rule):
"""Store the rules.
Policy is maintained as a dictionary of Rule ID.
"""
if rule_id not in self.rules:
self.rules[rule_id] = rule
self.rule_cnt += 1 | Implement a Python 3 function for
storing the rules. Policy is maintained as a dictionary of Rule ID. | You are a Python code generator, capable of creating scripts from specifications. |
Delete the specific Rule from the dictionary indexed by rule id. | Can you generate a brief explanation for the following Python 3 code
def delete_rule(self, rule_id):
if rule_id not in self.rules:
LOG.error("No Rule id present for deleting %s", rule_id)
return
del self.rules[rule_id]
self.rule_cnt -= 1 | As a Python code translator, you convert algorithms and pseudocode into Python. |
def is_fw_present(self, fw_id):
"""Returns if firewall index by ID is present in dictionary. """
if self.fw_id is None or self.fw_id != fw_id:
return False
else:
return True | Write a Python 3 function that can
return if firewall index by ID is present in dictionary. | As a Python code analyst, you investigate and solve complex coding mysteries |
Fills up the local attributes when FW is created. | Can you generate a brief explanation for the following Python 3 code
def create_fw(self, proj_name, pol_id, fw_id, fw_name, fw_type, rtr_id):
self.tenant_name = proj_name
self.fw_id = fw_id
self.fw_name = fw_name
self.fw_created = True
self.active_pol_id = pol_id
self.fw_... | As a python code expert, you are capable of creating scripts from specifications. |
def delete_fw(self, fw_id):
"""Deletes the FW local attributes. """
self.fw_id = None
self.fw_name = None
self.fw_created = False
self.active_pol_id = None | Can you implement a function in Python 3 that
deletes the FW local attributes. | As a Python code translator, you convert algorithms and pseudocode into Python. |
Deletes the policy from the local dictionary. | Can you generate the documentation for the following Python 3 function
def delete_policy(self, pol_id):
if pol_id not in self.policies:
LOG.error("Invalid policy %s", pol_id)
return
del self.policies[pol_id]
self.policy_cnt -= 1 | As a Python code translator, you convert algorithms and pseudocode into Python. |
Returns if at least one rule is present in the policy. | Here you have a function in Python 3, explain what it does
def one_rule_present(self, pol_id):
pol_dict = self.policies[pol_id]
for rule in pol_dict['rule_dict']:
if self.is_rule_present(rule):
return True
return False | You are a Python code generator, capable of creating scripts from specifications. |
Updates the FW parameters. | Make a summary of the following Python 3 code
def update_fw_params(self, rtr_id=-1, fw_type=-1):
if rtr_id != -1:
self.router_id = rtr_id
if fw_type != -1:
self.fw_type = fw_type | As a Python code analyst, you investigate and solve complex coding mysteries |
This routine stores the DCNM object and populates the cfg with the object. | Explain what the following Python 3 code does
def populate_cfg_dcnm(self, cfg, dcnm_obj):
if not self.fw_init:
return
self.dcnm_obj = dcnm_obj
self.fabric.store_dcnm(dcnm_obj)
self.populate_dcnm_obj(dcnm_obj) | As a Python code composer, you craft elegant and concise scripts. |
Prepares the Fabric and creates the device and updates the database with the final result. | Explain what the following Python 3 code does
def _create_fw_fab_dev_te(self, tenant_id, drvr_name, fw_dict):
is_fw_virt = self.is_device_virtual()
ret = self.fabric.prepare_fabric_fw(tenant_id, fw_dict, is_fw_virt,
fw_constants.RESULT_FW_CREATE_INIT)
... | You are a Python code generator, capable of creating scripts from specifications. |
def _check_create_fw(self, tenant_id, drvr_name):
"""Creates the Firewall, if all conditions are met.
This function first checks if all the configuration are done
for a FW to be launched. After that it creates the FW entry in the
DB. After that, it calls the routine to prepare the fabri... | Write a Python 3 function that can
create the Firewall and creates the fabric and device. | You are a Python code generator, capable of creating scripts from specifications. |
Deletes the Firewall.
This routine calls the fabric class to delete the fabric when
a firewall is deleted. It also calls the device manager to
unconfigure the device. It updates the database with the final
result. | Can you generate a brief explanation for the following Python 3 code
def _delete_fw_fab_dev(self, tenant_id, drvr_name, fw_dict):
is_fw_virt = self.is_device_virtual()
if self.fwid_attr[tenant_id].is_fw_drvr_created():
ret = self.delete_fw_device(tenant_id, fw_dict.get('fw_id'),
... | As a Python code analyst, you investigate and solve complex coding mysteries |
Deletes the Firewall if all conditioms are met. | Given the following Python 3 function, write the documentation
def _check_delete_fw(self, tenant_id, drvr_name):
fw_dict = self.fwid_attr[tenant_id].get_fw_dict()
ret = False
try:
with self.fwid_attr[tenant_id].mutex_lock:
self.update_fw_db_final_result(fw_dict.get('f... | As a Python code translator, you convert algorithms and pseudocode into Python. |
Update the Firewall cfg by calling the driver. | Make a summary of the following Python 3 code
def _check_update_fw(self, tenant_id, drvr_name):
if self.fwid_attr[tenant_id].is_fw_complete():
fw_dict = self.fwid_attr[tenant_id].get_fw_dict()
self.modify_fw_device(tenant_id, fw_dict.get('fw_id'), fw_dict) | You are a Python code generator, capable of creating scripts from specifications. |
def fw_create(self, data, fw_name=None, cache=False):
"""Top level FW create function. """
LOG.debug("FW create %s", data)
try:
self._fw_create(fw_name, data, cache)
except Exception as exc:
LOG.error("Exception in fw_create %s", str(exc)) | Can you write a function in Python 3 where it
tops level FW create function. | As a python code expert, you are capable of creating scripts from specifications. |
def _fw_update(self, drvr_name, data):
"""Update routine for the Firewall.
Check if FW is already cfgd using the below function
if self.fwid_attr[tenant_id].is_fw_complete() or
is_fw_drvr_create_needed():
The above two functions will take care of whether FW is already
cf... | How would you implement a function in Python 3 that
updates routine for the Firewall. | You are a Python code generator, capable of creating scripts from specifications. |
Top level FW update function. | Make a summary of the following Python 3 code
def fw_update(self, data, fw_name=None):
LOG.debug("FW Update %s", data)
self._fw_update(fw_name, data) | You are a Python code analyst, evaluating scripts for potential improvements. |
Misc function to decode the firewall rule from Openstack. | Can you generate a brief explanation for the following Python 3 code
def _fw_rule_decode_store(self, data):
fw_rule = data.get('firewall_rule')
rule = {'protocol': fw_rule.get('protocol'),
'source_ip_address': fw_rule.get('source_ip_address'),
'destination_ip_address': fw... | As a Python code analyst, you investigate and solve complex coding mysteries |
Top level rule creation routine. | Can you tell what is the following Python 3 function doing
def fw_rule_create(self, data, fw_name=None, cache=False):
LOG.debug("FW Rule create %s", data)
self._fw_rule_create(fw_name, data, cache) | You are a Python code generator, capable of creating scripts from specifications. |
Function that deletes the firewall rule from the local cache. | Can you generate the documentation for the following Python 3 function
def _fw_rule_delete(self, drvr_name, data):
rule_id = data.get('firewall_rule_id')
tenant_id = self.tenant_db.get_rule_tenant(rule_id)
if tenant_id not in self.fwid_attr:
LOG.error("Invalid tenant id for FW delet... | As a Python code analyst, you investigate and solve complex coding mysteries |
Top level rule delete function. | Can you generate the documentation for the following Python 3 function
def fw_rule_delete(self, data, fw_name=None):
LOG.debug("FW Rule delete %s", data)
self._fw_rule_delete(fw_name, data) | You are a Python code generator, capable of creating scripts from specifications. |
def _fw_rule_update(self, drvr_name, data):
"""Firewall Rule update routine.
Function to decode the updated rules and call routines that
in turn calls the device routines to update rules.
"""
LOG.debug("FW Update %s", data)
tenant_id = data.get('firewall_rule').get('tena... | Can you implement a function in Python 3 that
functions to update the firewall rules. | As a Python code translator, you convert algorithms and pseudocode into Python. |
Top level rule update routine. | Make a summary of the following Python 3 code
def fw_rule_update(self, data, fw_name=None):
LOG.debug("FW Update Debug")
self._fw_rule_update(fw_name, data) | As a python code expert, you are capable of creating scripts from specifications. |
Routine to delete the firewall policy from local cache. | Can you generate a brief explanation for the following Python 3 code
def _fw_policy_delete(self, drvr_name, data):
policy_id = data.get('firewall_policy_id')
tenant_id = self.tenant_db.get_policy_tenant(policy_id)
if tenant_id not in self.fwid_attr:
LOG.error("Invalid tenant id for ... | You are a Python code architect, reviewing and designing scalable and efficient code |
def fw_policy_delete(self, data, fw_name=None):
"""Top level policy delete routine. """
LOG.debug("FW Policy Debug")
self._fw_policy_delete(fw_name, data) | Write a Python 3 script for
topping level policy delete routine. | You are a Python code generator, capable of creating scripts from specifications. |
This routine creates the firewall policy and rule objects. | Here you have a function in Python 3, explain what it does
def _fw_policy_create(self, drvr_name, data, cache):
policy = {}
fw_policy = data.get('firewall_policy')
tenant_id = fw_policy.get('tenant_id')
LOG.info("Creating policy for tenant %s", tenant_id)
policy_id = fw_policy.ge... | You are a Python code analyst, evaluating scripts for potential improvements. |
def fw_policy_create(self, data, fw_name=None, cache=False):
"""Top level policy create routine. """
LOG.debug("FW Policy Debug")
self._fw_policy_create(fw_name, data, cache) | Create a Python 3 function to
top level policy create routine. | As a Python code analyst, you investigate and solve complex coding mysteries |
def convert_fwdb_event_msg(self, rule, tenant_id, rule_id, policy_id):
"""Convert the Firewall DB to a event message format.
From inputs from DB, this will create a FW rule dictionary that
resembles the actual data from Openstack when a rule is created.
This is usually called after rest... | Write a Python 3 function for
converting the Firewall DB to an event message format. | You are a Python code generator, capable of creating scripts from specifications. |
Convert the Firewall DB to a query response. | How would you explain what the following Python 3 function does
def convert_fwdb(self, tenant_id, name, policy_id, fw_id):
fw_dict = {'tenant_id': tenant_id, 'name': name, 'id': fw_id,
'firewall_policy_id': policy_id,
'admin_state_up': True}
fw_data = {'firewall': f... | As a Python code analyst, you investigate and solve complex coding mysteries |
This method populates the local cache with the data from the database. | Can you tell what is the following Python 3 function doing
def populate_local_cache(self):
fw_dict = self.get_all_fw_db()
LOG.info("Populating FW Mgr Local Cache")
for fw_id in fw_dict:
fw_data = fw_dict.get(fw_id)
tenant_id = fw_data.get('tenant_id')
rule_dic... | You are a Python code analyst, evaluating scripts for potential improvements. |
This routine retries the failure of fabric device create. | Can you generate a brief explanation for the following Python 3 code
def retry_failure_fab_dev_create(self, tenant_id, fw_data, fw_dict):
result = fw_data.get('result').split('(')[0]
is_fw_virt = self.is_device_virtual()
# Fabric portion
if result == fw_constants.RESULT_FW_CREATE_INIT:
... | You are a Python code generator, capable of creating scripts from specifications. |
This routine retries the failure cases for delete. | Can you tell what is the following Python 3 function doing
def retry_failure_fab_dev_delete(self, tenant_id, fw_data, fw_dict):
result = fw_data.get('result').split('(')[0]
name = dfa_dbm.DfaDBMixin.get_project_name(self, tenant_id)
fw_dict['tenant_name'] = name
is_fw_virt = self.is_devi... | You are a Python code generator, capable of creating scripts from specifications. |
This module is called when the create attempt fails. | Explain what the following Python 3 code does
def fw_retry_failures_create(self):
for tenant_id in self.fwid_attr:
try:
with self.fwid_attr[tenant_id].mutex_lock:
if self.fwid_attr[tenant_id].is_fw_drvr_create_needed():
fw_dict = self.fwid_... | As a Python code analyst, you investigate and solve complex coding mysteries |
This routine fills a local fw_dict with data from DB. | Can you tell what is the following Python 3 function doing
def fill_fw_dict_from_db(self, fw_data):
rule_dict = fw_data.get('rules').get('rules')
fw_dict = {'fw_id': fw_data.get('fw_id'),
'fw_name': fw_data.get('name'),
'firewall_policy_id': fw_data.get('firewall_po... | You are a Python code generator, capable of creating scripts from specifications. |
Top level retry routine called. | How would you explain what the following Python 3 function does
def fw_retry_failures(self):
if not self.fw_init:
return
try:
self.fw_retry_failures_create()
self.fw_retry_failures_delete()
except Exception as exc:
LOG.error("Exception in retry fai... | As a python code expert, you are capable of creating scripts from specifications. |
def _find_starts(self, linespec):
"""
Finds the start points.
Start points matching the linespec regex are returned as list in the
following format:
[(item, index), (item, index).....
"""
linespec += ".*"
start_points = []
for item in self._inden... | Can you implement a function in Python 3 that
finds the start points matching the linespec regex | You are a Python code generator, capable of creating scripts from specifications. |
def find_lines(self, linespec):
"""Find lines that match the linespec regex."""
res = []
linespec += ".*"
for line in self.cfg:
match = re.search(linespec, line)
if match:
res.append(match.group(0))
return res | Create a Python 3 function to
find lines that match the linespec regex. | As a Python code translator, you convert algorithms and pseudocode into Python. |
Find lines that match the linespec regex. | Given the following Python 3 function, write the documentation
def find_objects(self, linespec):
# Note(asr1kteam): In this code we are only adding children one-level
# deep to a given parent (linespec), as that satisfies the IOS conf
# parsing.
# Note(asr1kteam): Not tested with tabs in... | You are a Python code generator, capable of creating scripts from specifications. |
Find lines and immediate children that match the linespec regex. | Here you have a function in Python 3, explain what it does
def find_children(self, linespec):
res = []
for parent in self.find_objects(linespec):
res.append(parent.line)
res.extend([child.line for child in parent.children])
return res | As a python code expert, you are capable of creating scripts from specifications. |
def enable_lldp(self, port_name, is_ncb=True, is_nb=False):
"""Function to enable LLDP on the interface. """
if is_ncb:
self.run_lldptool(["-L", "-i", port_name, "-g", "ncb",
"adminStatus=rxtx"])
if is_nb:
self.run_lldptool(["-L", "-i", port_name, "-g", "nb",
... | Implement a function in Python 3 to
function to enable LLDP on the interface. | As a Python code translator, you convert algorithms and pseudocode into Python. |
def enable_lldp(self):
"""Function to enable LLDP on the interface. """
if self.is_ncb:
self.run_lldptool(["-L", "-i", self.port_name, "-g", "ncb",
"adminStatus=rxtx"])
if self.is_nb:
self.run_lldptool(["-L", "-i", self.port_name, "-g", "nb"... | Can you write a function in Python 3 where it
functions to enable LLDP on the interface. | You are a Python code architect, reviewing and designing scalable and efficient code |
def enable_evb(self):
"""Function to enable EVB on the interface. """
if self.is_ncb:
self.run_lldptool(["-T", "-i", self.port_name, "-g", "ncb",
"-V", "evb", "enableTx=yes"])
ret = self.enable_gpid()
return ret
else:
... | Can you write a function in Python 3 where it
functions to enable EVB on the interface. | As a python code expert, you are capable of creating scripts from specifications. |
def enable_gpid(self):
"""Function to enable Group ID on the interface.
This is needed to use the MAC, GID, VID Filter.
"""
if self.is_ncb:
self.run_lldptool(["-T", "-i", self.port_name, "-g", "ncb",
"-V", "evb", "-c", "evbgpid=yes"])
... | Can you implement a function in Python 3 that
functions to enable Group ID on the interface. | You are a Python code generator, capable of creating scripts from specifications. |
Periodic refresh of vNIC events to VDP. | Explain what the following Python 3 code does
def _vdp_refrsh_hndlr(self):
LOG.debug("Refresh handler")
try:
if not self.vdp_vif_map:
LOG.debug("vdp_vif_map not created, returning")
return
vdp_vif_map = dict.copy(self.vdp_vif_map)
oui_v... | As a Python code composer, you craft elegant and concise scripts. |
Function for invoking the lldptool utility. | Can you tell what is the following Python 3 function doing
def run_lldptool(self, args):
full_args = ['lldptool'] + args
try:
utils.execute(full_args, root_helper=self.root_helper)
except Exception as e:
LOG.error("Unable to execute %(cmd)s. "
"Excep... | As a python code expert, you are capable of creating scripts from specifications. |
Function for storing the OUI ID and Opaque Data for a given port | Can you tell what is the following Python 3 function doing
def store_oui(self, port_uuid, oui_type, oui_data):
self.oui_vif_map[port_uuid] = {'oui_id': oui_type,
'oui_data': oui_data} | As a Python code translator, you convert algorithms and pseudocode into Python. |
def store_vdp_vsi(self, port_uuid, mgrid, typeid, typeid_ver,
vsiid_frmt, vsiid, filter_frmt, gid, mac, vlan,
new_network, reply, oui_id, oui_data, vsw_cb_fn,
vsw_cb_data, reason):
"""Stores the vNIC specific info for VDP Refresh.
:param... | Can you write a function in Python 3 where it
stores the VDP VSI information for the given port in the VDP VSI store. | As a python code expert, you are capable of creating scripts from specifications. |
Clears the OUI specific info. | Explain what the following Python 3 code does
def clear_oui(self, port_uuid):
if port_uuid in self.oui_vif_map:
del self.oui_vif_map[port_uuid]
else:
LOG.debug("OUI does not exist") | You are a Python code architect, reviewing and designing scalable and efficient code |
def clear_vdp_vsi(self, port_uuid):
"""Stores the vNIC specific info for VDP Refresh.
:param uuid: vNIC UUID
"""
try:
LOG.debug("Clearing VDP VSI MAC %(mac)s UUID %(uuid)s",
{'mac': self.vdp_vif_map[port_uuid].get('mac'),
'uuid': ... | Write a Python 3 function that can
clear the VDP VSI information for the given port. | You are a Python code analyst, evaluating scripts for potential improvements. |
def gen_cisco_vdp_oui(self, oui_id, oui_data):
"""Cisco specific handler for constructing OUI arguments. """
oui_list = []
vm_name = oui_data.get('vm_name')
if vm_name is not None:
oui_str = "oui=%s," % oui_id
oui_name_str = oui_str + "vm_name=" + vm_name
... | Write a Python 3 script to
generate a list of OUI arguments for a Cisco VDP VM. | As a python code expert, you are capable of creating scripts from specifications. |
Generate the OUI string for vdptool. | Can you generate a brief explanation for the following Python 3 code
def gen_oui_str(self, oui_list):
oui_str = []
for oui in oui_list:
oui_str.append('-c')
oui_str.append(oui)
return oui_str | As a Python code translator, you convert algorithms and pseudocode into Python. |
Constructs the VDP Message. | Explain what the following Python 3 code does
def construct_vdp_dict(self, mode, mgrid, typeid, typeid_ver, vsiid_frmt,
vsiid, filter_frmt, gid, mac, vlan, oui_id,
oui_data):
"""Constructs the VDP Message.
Please refer http://www.ieee802.org/1/pages... | As a Python code translator, you convert algorithms and pseudocode into Python. |
def send_vdp_query_msg(self, mode, mgrid, typeid, typeid_ver, vsiid_frmt,
vsiid, filter_frmt, gid, mac, vlan, oui_id,
oui_data):
"""Constructs and Sends the VDP Query Message.
Please refer http://www.ieee802.org/1/pages/802.1bg.html VDP
Sect... | Write a Python 3 function that can
construct and sends a VDP Query Message. | As a python code expert, you are capable of creating scripts from specifications. |
def send_vdp_msg(self, mode, mgrid, typeid, typeid_ver, vsiid_frmt,
vsiid, filter_frmt, gid, mac, vlan, oui_id, oui_data,
sw_resp):
"""Constructs and Sends the VDP Message.
Please refer http://www.ieee802.org/1/pages/802.1bg.html VDP
Section for more de... | Write a Python 3 function that can
construct and sends a VDP Message. | You are a Python code analyst, evaluating scripts for potential improvements. |
def crosscheck_query_vsiid_mac(self, reply, vsiid, mac):
"""Cross Check the reply against the input vsiid,mac for get query. """
vsiid_reply = reply.partition("uuid")[2].split()[0][4:]
if vsiid != vsiid_reply:
fail_reason = vdp_const.vsi_mismatch_failure_reason % (
vs... | Implement a Python 3 function for
crossing Check the reply against the input vsiid and mac for get query. | As a Python code translator, you convert algorithms and pseudocode into Python. |
def get_vdp_failure_reason(self, reply):
"""Parse the failure reason from VDP. """
try:
fail_reason = reply.partition(
"filter")[0].replace('\t', '').split('\n')[-2]
if len(fail_reason) == 0:
fail_reason = vdp_const.retrieve_failure_reason % (reply... | Write a Python 3 function for
parsing the failure reason from VDP. | You are a Python code generator, capable of creating scripts from specifications. |
def check_filter_validity(self, reply, filter_str):
"""Check for the validify of the filter. """
try:
f_ind = reply.index(filter_str)
l_ind = reply.rindex(filter_str)
except Exception:
fail_reason = vdp_const.filter_failure_reason % (reply)
LOG.err... | How would you implement a function in Python 3 that
checks if the filter is valid. | As a Python code analyst, you investigate and solve complex coding mysteries |
Parse the associate reply from VDP daemon to get the VLAN value. | Can you generate a brief explanation for the following Python 3 code
def get_vlan_from_associate_reply(self, reply, vsiid, mac):
try:
verify_flag, fail_reason = self.crosscheck_reply_vsiid_mac(
reply, vsiid, mac)
if not verify_flag:
return constants.INVALI... | As a Python code translator, you convert algorithms and pseudocode into Python. |
Parse the hints to check for errors. | How would you explain what the following Python 3 function does
def check_hints(self, reply):
try:
f_ind = reply.index("hints")
l_ind = reply.rindex("hints")
except Exception:
fail_reason = vdp_const.hints_failure_reason % (reply)
LOG.error("%s", fail_reas... | You are a Python code architect, reviewing and designing scalable and efficient code |
def get_vlan_from_query_reply(self, reply, vsiid, mac):
"""Parse the query reply from VDP daemon to get the VLAN value. """
hints_ret, fail_reason = self.check_hints(reply)
if not hints_ret:
LOG.error("Incorrect hints found %s", reply)
return constants.INVALID_VLAN, fail_... | Can you write a function in Python 3 where it
parses the query reply from VDP daemon to get the VLAN value. | As a Python code translator, you convert algorithms and pseudocode into Python. |
def send_vdp_assoc(self, vsiid=None, mgrid=None, typeid=None,
typeid_ver=None, vsiid_frmt=vdp_const.VDP_VSIFRMT_UUID,
filter_frmt=vdp_const.VDP_FILTER_GIDMACVID, gid=0,
mac="", vlan=0, oui_id="", oui_data="", sw_resp=False):
"""Sends the VDP A... | Write a Python 3 script to
send the VDP Associate Message. | As a Python code translator, you convert algorithms and pseudocode into Python. |
This interface is called for a vNIC UP message. This interface is called by apps when a vNIC is up and is ready to send a VDP association message. | Here you have a function in Python 3, explain what it does
def send_vdp_vnic_up(self, port_uuid=None, vsiid=None,
mgrid=None, typeid=None, typeid_ver=None,
vsiid_frmt=vdp_const.VDP_VSIFRMT_UUID,
filter_frmt=vdp_const.VDP_FILTER_GIDMACVID,
... | You are a Python code analyst, evaluating scripts for potential improvements. |
This function is called by apps when a vNIC Down is received. This function is called by apps when a vNIC is down. | Can you tell what is the following Python 3 function doing
def send_vdp_vnic_down(self, port_uuid=None, vsiid=None, mgrid=None,
typeid=None, typeid_ver=None,
vsiid_frmt=vdp_const.VDP_VSIFRMT_UUID,
filter_frmt=vdp_const.VDP_FILTER_GIDMACVID... | As a Python code analyst, you investigate and solve complex coding mysteries |
Function that runs the vdptool utility. | Can you tell what is the following Python 3 function doing
def run_vdptool(self, args, oui_args=None):
if oui_args is None:
oui_args = []
full_args = ['vdptool'] + args + oui_args
try:
return utils.execute(full_args, root_helper=self.root_helper)
except Exception ... | As a python code expert, you are capable of creating scripts from specifications. |
def get_routers(self, context, router_ids=None, hd_ids=None):
"""Make a remote process call to retrieve the sync data for routers.
:param context: session context
:param router_ids: list of routers to fetch
:param hd_ids: hosting device ids, only routers assigned to these
... | Can you implement a function in Python 3 that
gets the routers for a specific context. | As a python code expert, you are capable of creating scripts from specifications. |
def update_floatingip_statuses(self, context, router_id, fip_statuses):
"""Make a remote process call to update operational status for one or
several floating IPs.
@param context: contains user information
@param router_id: id of router associated with the floatingips
@param fip... | Can you implement a function in Python 3 that
updates the operational status for one or several floating IPs. | As a Python code translator, you convert algorithms and pseudocode into Python. |
def send_update_port_statuses(self, context, port_ids, status):
"""Call the pluging to update the port status which updates the DB.
:param context: contains user information
:param port_ids: list of ids of the ports associated with the status
:param status: value of the status for the g... | How would you code a function in Python 3 to
send the status update to the DB | As a Python code translator, you convert algorithms and pseudocode into Python. |
def router_deleted(self, context, routers):
"""Deal with router deletion RPC message."""
LOG.debug('Got router deleted notification for %s', routers)
self._update_removed_routers_cache(routers) | Write a Python 3 function for
dealing with router deletion RPC message. | As a Python code composer, you craft elegant and concise scripts. |
def routers_updated(self, context, routers):
"""Deal with routers modification and creation RPC message."""
LOG.debug('Got routers updated notification :%s', routers)
if routers:
# This is needed for backward compatibility
if isinstance(routers[0], dict):
... | How would you code a function in Python 3 to
deal with routers modification and creation RPC message. | As a Python code analyst, you investigate and solve complex coding mysteries |
Collect state from this helper. | Make a summary of the following Python 3 code
def collect_state(self, configurations):
num_ex_gw_ports = 0
num_interfaces = 0
num_floating_ips = 0
router_infos = self.router_info.values()
num_routers = len(router_infos)
num_hd_routers = collections.defaultdict(int)
... | You are a Python code analyst, evaluating scripts for potential improvements. |
def _fetch_router_info(self, router_ids=None, device_ids=None,
all_routers=False):
"""Fetch router dict from the routing plugin.
:param router_ids: List of router_ids of routers to fetch
:param device_ids: List of device_ids whose routers to fetch
:param all_r... | Can you implement a function in Python 3 that
fetches router dict from the routing plugin. | As a Python code composer, you craft elegant and concise scripts. |
def _fetch_router_chunk_data(self, router_ids=None):
"""Fetch router data from the routing plugin in chunks.
:param router_ids: List of router_ids of routers to fetch
:return: List of router dicts of format:
[ {router_dict1}, {router_dict2},.....]
... | Can you create a Python 3 function that
fetches router data from the routing plugin in chunks. | As a Python code composer, you craft elegant and concise scripts. |
This method handles the actual sync_devices operation. | How would you explain what the following Python 3 function does
def _handle_sync_devices(self, routers):
sync_devices_list = list(self.sync_devices)
LOG.debug("Fetching routers on:%s", sync_devices_list)
fetched_routers = self._fetch_router_info(device_ids=sync_devices_list)
if fetched_... | As a python code expert, you are capable of creating scripts from specifications. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.