output stringlengths 1 928k | instruction stringlengths 7 928k | system stringlengths 0 104k |
|---|---|---|
def delete_port_channel(self, nexus_host, vpc_nbr):
"""Deletes delete port channel on Nexus switch."""
starttime = time.time()
path_snip = snipp.PATH_ALL
body_snip = snipp.BODY_DEL_PORT_CH % (vpc_nbr)
self.send_edit_string(nexus_host, path_snip, body_snip)
self.captur... | Can you implement a function in Python 3 that
deletes the port channel on Nexus switch. | You are a Python code architect, reviewing and designing scalable and efficient code |
def _get_port_channel_group(self, nexus_host, intf_type, interface):
"""Look for 'channel-group x' config and return x.
:param nexus_host: IP address of Nexus switch
:param intf_type: String which specifies interface type.
example: ethernet
:param interface: ... | Write a Python 3 script to
get port channel group. | As a python code expert, you are capable of creating scripts from specifications. |
Initialize baremetal switch interfaces and for initial event. | Explain what the following Python 3 code does
def initialize_baremetal_switch_interfaces(self, interfaces):
if not interfaces:
return
max_ifs = len(interfaces)
starttime = time.time()
learned, nexus_ip_list = self._build_host_list_and_verify_chgrp(
interfaces)
... | You are a Python code generator, capable of creating scripts from specifications. |
def initialize_all_switch_interfaces(self, interfaces,
switch_ip=None, replay=True):
"""Configure Nexus interface and get port channel number.
Called during switch replay or just init if no replay
is configured. For latter case, only configured interfac... | Implement a function in Python 3 to
initialize all switch interfaces. | You are a Python code analyst, evaluating scripts for potential improvements. |
Given the nexus host get the type of Nexus switch. | How would you explain what the following Python 3 function does
def get_nexus_type(self, nexus_host):
starttime = time.time()
response = self.client.rest_get(
snipp.PATH_GET_NEXUS_TYPE, nexus_host)
self.capture_and_print_timeshot(
starttime, "gettype",
switch... | As a Python code composer, you craft elegant and concise scripts. |
Returns an XML snippet for create VLAN on a Nexus Switch. | Can you generate the documentation for the following Python 3 function
def get_create_vlan(self, nexus_host, vlanid, vni, conf_str):
starttime = time.time()
if vni:
body_snip = snipp.BODY_VXLAN_ALL_INCR % (vlanid, vni)
else:
body_snip = snipp.BODY_VLAN_ALL_INCR % vlanid... | You are a Python code architect, reviewing and designing scalable and efficient code |
def set_all_vlan_states(self, nexus_host, vlanid_range):
"""Set the VLAN states to active."""
starttime = time.time()
if not vlanid_range:
LOG.warning("Exiting set_all_vlan_states: "
"No vlans to configure")
return
# Eliminate possible w... | Create a Python 3 function for
setting the VLAN states to active. | As a Python code composer, you craft elegant and concise scripts. |
def create_vlan(self, nexus_host, vlanid, vni):
"""Given switch, vlanid, vni, Create a VLAN on Switch."""
starttime = time.time()
path_snip, body_snip = self.start_create_vlan()
body_snip = self.get_create_vlan(nexus_host, vlanid, vni, body_snip)
body_snip = self.end_create_vlan... | Can you implement a function in Python 3 that
gives switch vlanid vni create a VLAN on Switch. | You are a Python code analyst, evaluating scripts for potential improvements. |
Delete a VLAN on Nexus Switch given the VLAN ID. | Here you have a function in Python 3, explain what it does
def delete_vlan(self, nexus_host, vlanid):
starttime = time.time()
path_snip = snipp.PATH_VLAN % vlanid
self.client.rest_delete(path_snip, nexus_host)
self.capture_and_print_timeshot(
starttime, "del_vlan",
... | You are a Python code architect, reviewing and designing scalable and efficient code |
def _get_vlan_body_on_trunk_int(self, nexus_host, vlanid, intf_type,
interface, is_native, is_delete,
add_mode):
"""Prepares an XML snippet for VLAN on a trunk interface.
:param nexus_host: IP address of Nexus switch
:param... | Write a Python 3 script for
preparing an XML snippet for VLAN on a trunk interface. | As a Python code translator, you convert algorithms and pseudocode into Python. |
Disable a VLAN on a trunk interface. | Here you have a function in Python 3, explain what it does
def disable_vlan_on_trunk_int(self, nexus_host, vlanid, intf_type,
interface, is_native):
"""Disable a VLAN on a trunk interface."""
starttime = time.time()
path_snip, body_snip = self._get_vlan_body_o... | You are a Python code analyst, evaluating scripts for potential improvements. |
Sends rest Post request to Nexus switch. | Can you generate the documentation for the following Python 3 function
def send_edit_string(self, nexus_host, path_snip, body_snip,
check_to_close_session=True):
"""Sends rest Post request to Nexus switch."""
starttime = time.time()
LOG.debug("NexusDriver edit config fo... | As a Python code composer, you craft elegant and concise scripts. |
def _send_cli_conf_string(self, nexus_host, cli_str):
"""Sends CLI Config commands to Nexus switch using NXAPI."""
starttime = time.time()
path_snip = snipp.PATH_USER_CMDS
body_snip = snipp.BODY_USER_CONF_CMDS % ('1', cli_str)
LOG.debug("NexusDriver CLI config for host %s: path:... | Can you implement a function in Python 3 that
sends CLI Config commands to Nexus switch using NXAPI. | As a python code expert, you are capable of creating scripts from specifications. |
Sends an interface trunk XML snippet. | Make a summary of the following Python 3 code
def send_enable_vlan_on_trunk_int(self, nexus_host, vlanid, intf_type,
interface, is_native, add_mode=False):
"""Gathers and sends an interface trunk XML snippet."""
path_snip, body_snip = self._get_vlan_body_on_trunk_i... | You are a Python code generator, capable of creating scripts from specifications. |
def create_and_trunk_vlan(self, nexus_host, vlan_id, intf_type,
nexus_port, vni, is_native):
"""Create VLAN and trunk it on the specified ports."""
starttime = time.time()
self.create_vlan(nexus_host, vlan_id, vni)
LOG.debug("NexusDriver created VLAN: %s",... | Write a Python 3 function that can
create VLAN and trunk it on the specified ports. | As a python code expert, you are capable of creating scripts from specifications. |
def enable_vxlan_feature(self, nexus_host, nve_int_num, src_intf):
"""Enable VXLAN on the switch."""
# Configure the "feature" commands and NVE interface
# (without "member" subcommand configuration).
# The Nexus 9K will not allow the "interface nve" configuration
# until the "f... | Implement a Python 3 function for
enabling VXLAN on the switch. | As a Python code analyst, you investigate and solve complex coding mysteries |
def disable_vxlan_feature(self, nexus_host):
"""Disable VXLAN on the switch."""
# Removing the "feature nv overlay" configuration also
# removes the "interface nve" configuration.
starttime = time.time()
# Do CLI 'no feature nv overlay'
self.send_edit_string(nexus_host... | Implement a function in Python 3 to
disable VXLAN on the switch. | As a Python code analyst, you investigate and solve complex coding mysteries |
Add a member configuration to the NVE interface. | Can you generate the documentation for the following Python 3 function
def create_nve_member(self, nexus_host, nve_int_num, vni, mcast_group):
# Do CLI [no] member vni %s mcast-group %s
# beneath int nve1
starttime = time.time()
path = snipp.PATH_VNI_UPDATE % (nve_int_num, vni)
... | You are a Python code generator, capable of creating scripts from specifications. |
Delete a member configuration on the NVE interface. | Here you have a function in Python 3, explain what it does
def delete_nve_member(self, nexus_host, nve_int_num, vni):
starttime = time.time()
path_snip = snipp.PATH_VNI_UPDATE % (nve_int_num, vni)
self.client.rest_delete(path_snip, nexus_host)
self.capture_and_print_timeshot(
... | As a Python code composer, you craft elegant and concise scripts. |
def _get_vrf_name(self, ri):
"""
overloaded method for generating a vrf_name that supports
region_id
"""
router_id = ri.router_name()[:self.DEV_NAME_LEN]
is_multi_region_enabled = cfg.CONF.multi_region.enable_multi_region
if is_multi_region_enabled:
r... | Write a Python 3 script for
generating a VRF name that supports the current resource and the region. | As a Python code translator, you convert algorithms and pseudocode into Python. |
def _get_interface_name_from_hosting_port(self, port):
"""
Extract the underlying subinterface name for a port
e.g. Port-channel10.200 or GigabitEthernet0/0/0.500
"""
try:
vlan = port['hosting_info']['segmentation_id']
int_prefix = port['hosting_info']['ph... | Create a Python 3 function to
extract the underlying subinterface name for a port. | You are a Python code analyst, evaluating scripts for potential improvements. |
Searches a list of dicts and returns the first matching entry
| Can you tell what is the following Python 3 function doing
def _get_item(list_containing_dicts_entries, attribute_value,
attribute_name='subnet_id'):
"""Searches a list of dicts and returns the first matching entry
The dict entry returned contains the attribute 'attribute_name' whose
... | As a python code expert, you are capable of creating scripts from specifications. |
def _nat_rules_for_internet_access(self, acl_no, network, netmask,
inner_itfc, outer_itfc, vrf_name):
"""Configure the NAT rules for an internal network.
Configuring NAT rules in the ASR1k is a three step process. First
create an ACL for the IP range of th... | Write a Python 3 script to
configure the NAT rules for an internal network. | You are a Python code architect, reviewing and designing scalable and efficient code |
Internal function to remove internal network nat rules from the running config. | Explain what the following Python 3 code does
def _remove_internal_nw_nat_rules(self, ri, ports, ext_port,
intf_deleted=False):
"""
Removes the NAT rules already configured when an internal network is
removed.
:param ri -- router-info objec... | You are a Python code generator, capable of creating scripts from specifications. |
Add a floating ip to the running config file. | Explain what the following Python 3 code does
def _do_add_floating_ip_asr1k(self, floating_ip, fixed_ip, vrf,
ex_gw_port):
"""
To implement a floating ip, an ip static nat is configured in the
underlying router ex_gw_port contains data to derive the vlan
... | You are a Python code architect, reviewing and designing scalable and efficient code |
Report that a hosting device is determined to be dead. | Can you tell what is the following Python 3 function doing
def report_non_responding_hosting_devices(self, context, host,
hosting_device_ids):
"""Report that a hosting device is determined to be dead.
:param context: contains user information
:param... | You are a Python code architect, reviewing and designing scalable and efficient code |
def update_hosting_device_status(self, context, host, status_info):
"""Report status changes for hosting devices.
:param context: contains user information
:param host: originator of callback
:param status_info: Dictionary with list of hosting device ids for
each type of hos... | Implement a Python 3 function for
reporting status changes for hosting devices. | You are a Python code analyst, evaluating scripts for potential improvements. |
def get_hosting_devices_for_agent(self, context, host):
"""Fetches routers that a Cisco cfg agent is managing.
This function is supposed to be called when the agent has started,
is ready to take on assignments and before any callbacks to fetch
logical resources are issued.
:par... | Can you create a Python 3 function that
fetches routers that a cfg agent is managing. | As a Python code analyst, you investigate and solve complex coding mysteries |
def add_router_to_hosting_device(self, context, hosting_device_id,
router_id):
"""Add a (non-hosted) router to a hosting device."""
e_context = context.elevated()
r_hd_binding_db = self._get_router_binding_info(e_context, router_id)
if r_hd_binding_db... | Implement a Python 3 function for
adding a router to a hosting device. | As a python code expert, you are capable of creating scripts from specifications. |
Remove the router from hosting device. | How would you explain what the following Python 3 function does
def remove_router_from_hosting_device(self, context, hosting_device_id,
router_id):
"""Remove the router from hosting device.
After removal, the router will be non-hosted until there is update
... | You are a Python code generator, capable of creating scripts from specifications. |
def get_number_of_agents_for_scheduling(self, context):
"""Return number of agents on which the router will be scheduled."""
num_agents = len(self.get_l3_agents(context, active=True,
filters={'agent_modes': [bc.constants.L3_AGENT_MODE_LEGACY,
bc.constant... | Implement a Python 3 function for
returning number of agents on which the router will be scheduled. | As a python code expert, you are capable of creating scripts from specifications. |
def _notify_subnet_create(resource, event, trigger, **kwargs):
"""Called when a new subnet is created in the external network"""
context = kwargs['context']
subnet = kwargs['subnet']
l3plugin = bc.get_plugin(L3_ROUTER_NAT)
for router in l3plugin.get_routers(context):
if (router['external_gat... | Can you implement a function in Python 3 that
calls when a new subnet is created in the external network | You are a Python code analyst, evaluating scripts for potential improvements. |
Called when router port or interface is enabled or disabled | Given the following Python 3 function, write the documentation
def _notify_cfg_agent_port_update(resource, event, trigger, **kwargs):
original_port = kwargs.get('original_port')
updated_port = kwargs.get('port')
if (updated_port is not None and original_port is not None and (
updated_port.get('admin_... | As a Python code analyst, you investigate and solve complex coding mysteries |
def is_port_profile_created(self, vlan_id, device_id):
"""Indicates if port profile has been created on UCS Manager."""
entry = self.session.query(ucsm_model.PortProfile).filter_by(
vlan_id=vlan_id, device_id=device_id).first()
return entry and entry.created_on_ucs | Implement a Python 3 function for
indicating if port profile has been created on UCS Manager. | You are a Python code analyst, evaluating scripts for potential improvements. |
def get_port_profile_for_vlan(self, vlan_id, device_id):
"""Returns Vlan id associated with the port profile."""
entry = self.session.query(ucsm_model.PortProfile).filter_by(
vlan_id=vlan_id, device_id=device_id).first()
return entry.profile_id if entry else None | Write a Python 3 script to
return Vlan id associated with the port profile. | You are a Python code analyst, evaluating scripts for potential improvements. |
Adds a port profile and its vlan_id to the table. | Can you generate a brief explanation for the following Python 3 code
def add_port_profile(self, profile_name, vlan_id, device_id):
if not self.get_port_profile_for_vlan(vlan_id, device_id):
port_profile = ucsm_model.PortProfile(profile_id=profile_name,
... | You are a Python code architect, reviewing and designing scalable and efficient code |
def set_port_profile_created(self, vlan_id, profile_name, device_id):
"""Sets created_on_ucs flag to True."""
with self.session.begin(subtransactions=True):
port_profile = self.session.query(
ucsm_model.PortProfile).filter_by(
vlan_id=vlan_id, profile_id=p... | Can you create a Python 3 function that
sets created_on_ucs flag to True. | As a Python code composer, you craft elegant and concise scripts. |
def delete_vlan_entry(self, vlan_id):
"""Deletes entry for a vlan_id if it exists."""
with self.session.begin(subtransactions=True):
try:
self.session.query(ucsm_model.PortProfile).filter_by(
vlan_id=vlan_id).delete()
except orm.exc.NoResultFou... | How would you implement a function in Python 3 that
deletes an entry for a vlan_id. | You are a Python code architect, reviewing and designing scalable and efficient code |
Adds an entry for a vlan_id on a SP template to the table. | Given the following Python 3 function, write the documentation
def add_service_profile_template(self, vlan_id, sp_template, ucsm_ip):
if not self.get_sp_template_vlan_entry(vlan_id, sp_template, ucsm_ip):
entry = ucsm_model.ServiceProfileTemplate(vlan_id=vlan_id,
... | You are a Python code architect, reviewing and designing scalable and efficient code |
Sets update_on_ucs flag to True. | How would you explain what the following Python 3 function does
def set_sp_template_updated(self, vlan_id, sp_template, device_id):
entry = self.get_sp_template_vlan_entry(vlan_id,
sp_template,
device_id)
if ... | As a Python code analyst, you investigate and solve complex coding mysteries |
def delete_sp_template_for_vlan(self, vlan_id):
"""Deletes SP Template for a vlan_id if it exists."""
with self.session.begin(subtransactions=True):
try:
self.session.query(
ucsm_model.ServiceProfileTemplate).filter_by(
vlan_id=vlan_id)... | How would you implement a function in Python 3 that
deletes the SP Template for a vlan_id. | You are a Python code analyst, evaluating scripts for potential improvements. |
Adds an entry for a vlan_id on a SP template to the table. | Can you tell what is the following Python 3 function doing
def add_vnic_template(self, vlan_id, ucsm_ip, vnic_template, physnet):
if not self.get_vnic_template_vlan_entry(vlan_id, vnic_template,
ucsm_ip, physnet):
vnic_t = ucsm_model.VnicTemplate(vlan_id=vlan_id,
... | As a python code expert, you are capable of creating scripts from specifications. |
def set_vnic_template_updated(self, vlan_id, ucsm_ip, vnic_template,
physnet):
"""Sets update_on_ucs flag to True for a Vnic Template entry."""
with self.session.begin(subtransactions=True):
entry = self.get_vnic_template_vlan_entry(vlan_id, vnic_template,
... | Can you write a function in Python 3 where it
sets update_on_ucs flag to True for a Vnic Template entry. | As a python code expert, you are capable of creating scripts from specifications. |
def delete_vnic_template_for_vlan(self, vlan_id):
"""Deletes VNIC Template for a vlan_id and physnet if it exists."""
with self.session.begin(subtransactions=True):
try:
self.session.query(ucsm_model.VnicTemplate).filter_by(
vlan_id=vlan_id).delete()
... | Create a Python 3 function for
deleting VNIC Template for a vlan_id and physnet if it exists. | As a python code expert, you are capable of creating scripts from specifications. |
def has_port_profile_to_delete(self, profile_name, device_id):
"""Returns True if port profile delete table containes PP."""
count = self.session.query(ucsm_model.PortProfileDelete).filter_by(
profile_id=profile_name, device_id=device_id).count()
return count != 0 | Write a Python 3 function that can
return True if port profile delete table containses PP. | As a Python code analyst, you investigate and solve complex coding mysteries |
Adds a port profile to the delete table. | Can you tell what is the following Python 3 function doing
def add_port_profile_to_delete_table(self, profile_name, device_id):
if not self.has_port_profile_to_delete(profile_name, device_id):
port_profile = ucsm_model.PortProfileDelete(
profile_id=profile_name, device_id=device_id)
... | You are a Python code architect, reviewing and designing scalable and efficient code |
def remove_port_profile_to_delete(self, profile_name, device_id):
"""Removes port profile to be deleted from table."""
with self.session.begin(subtransactions=True):
self.session.query(ucsm_model.PortProfileDelete).filter_by(
profile_id=profile_name, device_id=device_id).dele... | Write a Python 3 script to
remove port profile to be deleted from table. | As a Python code translator, you convert algorithms and pseudocode into Python. |
def parse(cls, buf):
"""Parse DHCP Packet.
1. To get client IP Address(ciaddr).
2. To get relaying gateway IP Address(giaddr).
3. To get DHCP Relay Agent Information Option Suboption
such as Link Selection, VSS, Server Identifier override.
"""
pkt = DhcpPack... | Create a Python 3 function for
parsing DHCP Packet. 1. To get client IP Address(ciaddr). 2. To get relaying gateway IP Address(giaddr). 3. To get DHCP Relay Agent Information Option Suboption such as Link Selection, VSS, Server Identifier override. | As a python code expert, you are capable of creating scripts from specifications. |
Report that a hosting device cannot be contacted. | Given the following Python 3 function, write the documentation
def report_dead_hosting_devices(self, context, hd_ids=None):
cctxt = self.client.prepare()
cctxt.cast(context, 'report_non_responding_hosting_devices',
host=self.host, hosting_device_ids=hd_ids) | As a Python code translator, you convert algorithms and pseudocode into Python. |
Report that a config agent is ready for duty. | Given the following Python 3 function, write the documentation
def register_for_duty(self, context):
cctxt = self.client.prepare()
return cctxt.call(context, 'register_for_duty', host=self.host) | As a Python code translator, you convert algorithms and pseudocode into Python. |
def get_hosting_devices_for_agent(self, context):
"""Get a list of hosting devices assigned to this agent."""
cctxt = self.client.prepare()
return cctxt.call(context,
'get_hosting_devices_for_agent',
host=self.host) | Write a Python 3 script to
get a list of hosting devices assigned to this agent. | You are a Python code generator, capable of creating scripts from specifications. |
def process_services(self, device_ids=None, removed_devices_info=None):
"""Process services managed by this config agent.
This method is invoked by any of three scenarios.
1. Invoked by a periodic task running every `RPC_LOOP_INTERVAL`
seconds. This is the most common scenario.
... | Implement a Python 3 function for
processing services managed by this config agent. This method is invoked by any of three scenarios. 1. Invoked by a periodic task running every `RPC_LOOP_INTERVAL` seconds. This is the most common scenario. In this mode, the method is called without any arguments. 2. Called by the `_pr... | You are a Python code analyst, evaluating scripts for potential improvements. |
def _process_backlogged_hosting_devices(self, context):
"""Process currently backlogged devices.
Go through the currently backlogged devices and process them.
For devices which are now reachable (compared to last time), we call
`process_services()` passing the now reachable device's id.... | Implement a function in Python 3 to
process the currently reachable hosting devices and process them. | As a python code expert, you are capable of creating scripts from specifications. |
def agent_updated(self, context, payload):
"""Deal with agent updated RPC message."""
try:
if payload['admin_state_up']:
#TODO(hareeshp): implement agent updated handling
pass
except KeyError as e:
LOG.error("Invalid payload format for rece... | How would you implement a function in Python 3 that
deals with agent updated RPC message. | As a Python code composer, you craft elegant and concise scripts. |
Deal with hosting devices assigned to this config agent. | How would you explain what the following Python 3 function does
def hosting_devices_assigned_to_cfg_agent(self, context, payload):
LOG.debug("Got hosting device assigned, payload: %s" % payload)
try:
if payload['hosting_device_ids']:
#TODO(hareeshp): implement assignment of h... | As a Python code translator, you convert algorithms and pseudocode into Python. |
def hosting_devices_unassigned_from_cfg_agent(self, context, payload):
"""Deal with hosting devices unassigned from this config agent."""
try:
if payload['hosting_device_ids']:
#TODO(hareeshp): implement unassignment of hosting devices
pass
except KeyE... | How would you implement a function in Python 3 that
deals with hosting devices unassigned from this config agent. | You are a Python code analyst, evaluating scripts for potential improvements. |
Deal with hosting devices removed RPC message. | Can you generate the documentation for the following Python 3 function
def hosting_devices_removed(self, context, payload):
try:
if payload['hosting_data']:
if payload['hosting_data'].keys():
self.process_services(removed_devices_info=payload)
except KeyEr... | You are a Python code generator, capable of creating scripts from specifications. |
def _agent_registration(self):
"""Register this agent with the server.
This method registers the cfg agent with the neutron server so hosting
devices can be assigned to it. In case the server is not ready to
accept registration (it sends a False) then we retry registration
for `... | Create a Python 3 function for
registering this agent with the neutron server. | You are a Python code architect, reviewing and designing scalable and efficient code |
Report state to the plugin. | Can you generate the documentation for the following Python 3 function
def _report_state(self):
LOG.debug("Report state task started")
self.keepalive_iteration += 1
if self.keepalive_iteration == self.report_iteration:
self._prepare_full_report_data()
self.keepalive_itera... | As a Python code composer, you craft elegant and concise scripts. |
Send the agent report via RPC. | Explain what the following Python 3 code does
def send_agent_report(self, report, context):
try:
self.state_rpc.report_state(context, report, self.use_call)
report.pop('start_flag', None)
self.use_call = False
LOG.debug("Send agent report successfully completed")
... | As a Python code composer, you craft elegant and concise scripts. |
Returns the vlan_id associated with a bound VLAN segment. | Can you tell what is the following Python 3 function doing
def _get_vlanid(self, context):
segment = context.bottom_bound_segment
if segment and self.check_segment(segment):
return segment.get(api.SEGMENTATION_ID) | As a Python code composer, you craft elegant and concise scripts. |
def _get_physnet(self, context):
"""Returns physnet associated with a bound VLAN segment."""
segment = context.bottom_bound_segment
if segment and self.check_segment(segment):
return segment.get(api.PHYSICAL_NETWORK) | Implement a Python 3 function for
returning the physnet associated with a bound VLAN segment. | As a Python code composer, you craft elegant and concise scripts. |
def update_port_precommit(self, context):
"""Adds port profile and vlan information to the DB.
Assign a port profile to this port. To do that:
1. Get the vlan_id associated with the bound segment
2. Check if a port profile already exists for this vlan_id
3. If yes, associate tha... | Implement a Python 3 function for
updating the port s pre - commit status to reflect the changes made to the DB. | You are a Python code generator, capable of creating scripts from specifications. |
Updates the port profile on UCS Manager if it does not already exist. | Can you generate the documentation for the following Python 3 function
def update_port_postcommit(self, context):
vlan_id = self._get_vlanid(context)
if not vlan_id:
LOG.warning('Vlan_id is None. Ignoring this port.')
return
if (not self._is_supported_deviceowner(contex... | As a Python code composer, you craft elegant and concise scripts. |
Delete entry corresponding to Network s VLAN in the DB. | Given the following Python 3 function, write the documentation
def delete_network_precommit(self, context):
segments = context.network_segments
for segment in segments:
if not self.check_segment(segment):
return # Not a vlan network
vlan_id = segment.get(api.SEGM... | You are a Python code architect, reviewing and designing scalable and efficient code |
Delete all configuration added to UCS Manager for the vlan_id. | Make a summary of the following Python 3 code
def delete_network_postcommit(self, context):
segments = context.network_segments
network_name = context.current['name']
for segment in segments:
if not self.check_segment(segment):
return # Not a vlan network
... | As a Python code analyst, you investigate and solve complex coding mysteries |
Binds a port to the current network segment. | Make a summary of the following Python 3 code
def bind_port(self, context):
vnic_type = context.current.get(bc.portbindings.VNIC_TYPE,
bc.portbindings.VNIC_NORMAL)
LOG.debug('Attempting to bind port %(port)s with vnic_type '
'%(vnic_type)s on ne... | As a Python code analyst, you investigate and solve complex coding mysteries |
def update_rule_entry(self, rule_info):
"""Update the rule_info list."""
if rule_info.get('status') == 'up':
self.add_rule_entry(rule_info)
if rule_info.get('status') == 'down':
self.remove_rule_entry(rule_info) | Create a Python 3 function to
update the rule_info list. | You are a Python code analyst, evaluating scripts for potential improvements. |
Add a rule entry to the rule_info list. | Given the following Python 3 function, write the documentation
def add_rule_entry(self, rule_info):
new_rule = IpMacPort(rule_info.get('ip'), rule_info.get('mac'),
rule_info.get('port'))
LOG.debug('Added rule info %s to the list', rule_info)
self.rule_info.append(ne... | As a python code expert, you are capable of creating scripts from specifications. |
Remove rule entry from rule_info list. | How would you explain what the following Python 3 function does
def remove_rule_entry(self, rule_info):
temp_list = list(self.rule_info)
for rule in temp_list:
if (rule.ip == rule_info.get('ip') and
rule.mac == rule_info.get('mac') and
rule.port == rule_i... | You are a Python code analyst, evaluating scripts for potential improvements. |
def _find_chain_name(self, mac):
"""Find a rule associated with a given mac."""
ipt_cmd = ['iptables', '-t', 'filter', '-S']
cmdo = dsl.execute(ipt_cmd, root_helper=self._root_helper,
log_output=False)
for o in cmdo.split('\n'):
if mac in o.lower()... | Implement a Python 3 function for
finding a rule associated with a given mac. | As a Python code translator, you convert algorithms and pseudocode into Python. |
Find rule number associated with a given mac. | Explain what the following Python 3 code does
def _find_rule_no(self, mac):
ipt_cmd = ['iptables', '-L', '--line-numbers']
cmdo = dsl.execute(ipt_cmd, self._root_helper, log_output=False)
for o in cmdo.split('\n'):
if mac in o.lower():
rule_no = o.split()[0]
... | You are a Python code architect, reviewing and designing scalable and efficient code |
Update a rule associated with given ip and mac. | Can you tell what is the following Python 3 function doing
def update_ip_rule(self, ip, mac):
rule_no = self._find_rule_no(mac)
chain = self._find_chain_name(mac)
if not rule_no or not chain:
LOG.error('Failed to update ip rule for %(ip)s %(mac)s',
{'ip': ip, '... | You are a Python code generator, capable of creating scripts from specifications. |
Enqueue the given event. | Can you tell what is the following Python 3 function doing
def enqueue_event(self, event):
LOG.debug('Enqueue iptable event %s.', event)
if event.get('status') == 'up':
for rule in self.rule_info:
if (rule.mac == event.get('mac').lower() and
rule.port... | As a python code expert, you are capable of creating scripts from specifications. |
def update_iptables(self):
"""Update iptables based on information in the rule_info."""
# Read the iptables
iptables_cmds = ['iptables-save', '-c']
all_rules = dsl.execute(iptables_cmds, root_helper=self._root_helper,
log_output=False)
# For each... | Write a Python 3 function for
updating the iptables based on information in the rule_info. | You are a Python code analyst, evaluating scripts for potential improvements. |
def process_rule_info(self):
"""Task responsible for processing event queue."""
while True:
try:
event = self._iptq.get(block=False)
LOG.debug('Dequeue event: %s.', event)
self.update_rule_entry(event)
except queue.Empty:
... | How would you code a function in Python 3 to
process the event queue and update the rule table. | As a python code expert, you are capable of creating scripts from specifications. |
setup ASA context for an edge tenant pair. | Here you have a function in Python 3, explain what it does
def setup(self, **kwargs):
params = kwargs.get('params')
LOG.info("asa_setup: tenant %(tenant)s %(in_vlan)d %(out_vlan)d"
" %(in_ip)s %(in_mask)s %(out_ip)s %(out_mask)s",
{'tenant': params.get('tenant_name'),
... | As a python code expert, you are capable of creating scripts from specifications. |
cleanup ASA context for an edge tenant pair. | Can you generate a brief explanation for the following Python 3 code
def cleanup(self, **kwargs):
params = kwargs.get('params')
LOG.info("asa_cleanup: tenant %(tenant)s %(in_vlan)d %(out_vlan)d"
" %(in_ip)s %(in_mask)s %(out_ip)s %(out_mask)s",
{'tenant': params.get('te... | As a Python code analyst, you investigate and solve complex coding mysteries |
def build_acl_ip(self, network_obj):
"Build the acl for IP address. "
if str(network_obj) == '0.0.0.0/0':
acl = "any "
else:
acl = "%(ip)s %(mask)s " % {'ip': network_obj.network,
'mask': network_obj.netmask}
return acl | How would you implement a function in Python 3 that
builds the acl for IP address. | You are a Python code generator, capable of creating scripts from specifications. |
def build_acl_port(self, port, enabled=True):
"Build the acl for L4 Ports. "
if port is not None:
if ':' in port:
range = port.replace(':', ' ')
acl = "range %(range)s " % {'range': range}
else:
acl = "eq %(port)s " % {'port': port}... | Can you write a function in Python 3 where it
builds the acl for L4 Ports. | As a Python code composer, you craft elegant and concise scripts. |
def apply_policy(self, policy):
"""Apply a firewall policy. """
tenant_name = policy['tenant_name']
fw_id = policy['fw_id']
fw_name = policy['fw_name']
LOG.info("asa_apply_policy: tenant=%(tenant)s fw_id=%(fw_id)s "
"fw_name=%(fw_name)s",
{'tenan... | Implement a Python 3 function for
applying a firewall policy to the current ASA context. | As a Python code composer, you craft elegant and concise scripts. |
Top level routine to check OVS flow consistency. | How would you explain what the following Python 3 function does
def _flow_check_handler(self):
LOG.info("In _flow_check_handler")
try:
with self.ovs_vdp_lock:
self._flow_check_handler_internal()
except Exception as e:
LOG.error("Exception in _flow_check_ha... | As a Python code composer, you craft elegant and concise scripts. |
def gen_veth_str(self, const_str, intf_str):
"""Generate a veth string.
Concatenates the constant string with remaining available length
of interface string from trailing position.
"""
avl_len = constants.MAX_VETH_NAME - len(const_str)
if avl_len <= 0:
LOG.er... | Write a Python 3 function that can
generate a veth string. | As a python code expert, you are capable of creating scripts from specifications. |
def find_interconnect_ports(self):
"""Find the internal veth or patch ports. """
phy_port_list = self.ext_br_obj.get_port_name_list()
int_port_list = self.integ_br_obj.get_port_name_list()
for port in phy_port_list:
# Use get Interface xxx type
is_patch = ovs_li... | Create a Python 3 function to
find the internal veth or patch ports. | As a python code expert, you are capable of creating scripts from specifications. |
Send a VDP UP or DOWN event to the VDP. | Can you tell what is the following Python 3 function doing
def send_vdp_port_event_internal(self, port_uuid, mac, net_uuid,
segmentation_id, status, oui):
"""Send vNIC UP/Down event to VDP.
:param port_uuid: a ovslib.VifPort object.
:mac: MAC address of the ... | You are a Python code architect, reviewing and designing scalable and efficient code |
Send a vNIC UP or Down event to VDP. | How would you explain what the following Python 3 function does
def send_vdp_port_event(self, port_uuid, mac, net_uuid,
segmentation_id, status, oui):
"""Send vNIC UP/Down event to VDP.
:param port: a ovslib.VifPort object.
:param net_uuid: the net_uuid this port is ... | As a Python code composer, you craft elegant and concise scripts. |
Retrieve the Local Vlan ID and VDP VLAN. | Can you generate the documentation for the following Python 3 function
def get_lvid_vdp_vlan(self, net_uuid, port_uuid):
lvm = self.local_vlan_map.get(net_uuid)
if not lvm:
LOG.error("lvm not yet created, get_lvid_vdp_lan "
"return error")
return cconstants... | As a Python code composer, you craft elegant and concise scripts. |
Internal function to update the local vlan map. | Can you generate the documentation for the following Python 3 function
def vdp_vlan_change_internal(self, vsw_cb_data, vdp_vlan, fail_reason):
LOG.debug("In VDP VLAN change VLAN %s", vdp_vlan)
if not vsw_cb_data:
LOG.error("NULL vsw_cb_data Info received")
return
net_uuid... | As a python code expert, you are capable of creating scripts from specifications. |
Provisions a overlay type network for a given local vlan. | Can you generate a brief explanation for the following Python 3 code
def provision_vdp_overlay_networks(self, port_uuid, mac, net_uuid,
segmentation_id, lvid, oui):
"""Provisions a overlay type network configured using VDP.
:param port_uuid: the uuid of the VM por... | You are a Python code analyst, evaluating scripts for potential improvements. |
Populate the local cache after restart. | How would you explain what the following Python 3 function does
def pop_local_cache(self, port_uuid, mac, net_uuid, lvid, vdp_vlan,
segmentation_id):
"""Populate the local cache after restart. """
LOG.info("Populating the OVS VDP cache with port %(port_uuid)s, "
... | You are a Python code generator, capable of creating scripts from specifications. |
def store_dummy_router_net(self, net_id, subnet_id, rtr_id):
"""Storing the router attributes. """
self.dummy_net_id = net_id
self.dummy_subnet_id = subnet_id
self.dummy_router_id = rtr_id | How would you implement a function in Python 3 that
stores the dummy router attributes. | As a Python code translator, you convert algorithms and pseudocode into Python. |
Stores the DCNM net dict. | Can you generate the documentation for the following Python 3 function
def store_dcnm_net_dict(self, net_dict, direc):
if direc == 'in':
self.in_dcnm_net_dict = net_dict
else:
self.out_dcnm_net_dict = net_dict | You are a Python code analyst, evaluating scripts for potential improvements. |
Parse a subnet dictionary into a dict of start end gateway and sec_gateway. | Make a summary of the following Python 3 code
def _parse_subnet(self, subnet_dict):
if not subnet_dict:
return
alloc_pool = subnet_dict.get('allocation_pools')
cidr = subnet_dict.get('cidr')
subnet = cidr.split('/')[0]
start = alloc_pool[0].get('start')
end = ... | As a Python code composer, you craft elegant and concise scripts. |
Store the subnet attributes and dict. | Make a summary of the following Python 3 code
def store_dcnm_subnet_dict(self, subnet_dict, direc):
if direc == 'in':
self.in_dcnm_subnet_dict = subnet_dict
self.in_subnet_dict = self._parse_subnet(subnet_dict)
else:
self.out_dcnm_subnet_dict = subnet_dict
... | You are a Python code generator, capable of creating scripts from specifications. |
def destroy_local_fw_db(self):
"""Delete the FW dict and its attributes. """
del self.fw_dict
del self.in_dcnm_net_dict
del self.in_dcnm_subnet_dict
del self.out_dcnm_net_dict
del self.out_dcnm_subnet_dict | Write a Python 3 script to
delete the FW dict and its attributes. | As a Python code translator, you convert algorithms and pseudocode into Python. |
Update the local cache with Net ID and service IP. | Here you have a function in Python 3, explain what it does
def update_fw_local_cache(self, net, direc, start):
fw_dict = self.get_fw_dict()
if direc == 'in':
fw_dict.update({'in_network_id': net, 'in_service_ip': start})
else:
fw_dict.update({'out_network_id': net, 'out_s... | You are a Python code generator, capable of creating scripts from specifications. |
Update the FW result in the dict. | How would you explain what the following Python 3 function does
def update_fw_local_result_str(self, os_result=None, dcnm_result=None,
dev_result=None):
"""Update the FW result in the dict. """
fw_dict = self.get_fw_dict()
if os_result is not None:
... | You are a Python code architect, reviewing and designing scalable and efficient code |
def update_fw_local_result(self, os_result=None, dcnm_result=None,
dev_result=None):
"""Retrieve and update the FW result in the dict. """
self.update_fw_local_result_str(os_result=os_result,
dcnm_result=dcnm_result,
... | Write a Python 3 function for
retrieving and update the FW result in the dict. | As a Python code composer, you craft elegant and concise scripts. |
Update the FW with router attributes. | Here you have a function in Python 3, explain what it does
def update_fw_local_router(self, net_id, subnet_id, router_id, os_result):
fw_dict = self.get_fw_dict()
fw_dict.update({'router_id': router_id, 'router_net_id': net_id,
'router_subnet_id': subnet_id})
self.store_d... | You are a Python code analyst, evaluating scripts for potential improvements. |
Calls routine to update the FW DB. | Make a summary of the following Python 3 code
def commit_fw_db(self):
fw_dict = self.get_fw_dict()
self.update_fw_db(fw_dict.get('fw_id'), fw_dict) | As a Python code composer, you craft elegant and concise scripts. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.