repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
listlengths
20
707
docstring
stringlengths
3
17.3k
docstring_tokens
listlengths
3
222
sha
stringlengths
40
40
url
stringlengths
87
242
partition
stringclasses
1 value
idx
int64
0
252k
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMapAttr.store_rule
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
python
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
[ "def", "store_rule", "(", "self", ",", "rule_id", ",", "rule", ")", ":", "if", "rule_id", "not", "in", "self", ".", "rules", ":", "self", ".", "rules", "[", "rule_id", "]", "=", "rule", "self", ".", "rule_cnt", "+=", "1" ]
Store the rules. Policy is maintained as a dictionary of Rule ID.
[ "Store", "the", "rules", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L115-L122
train
37,800
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMapAttr.delete_rule
def delete_rule(self, rule_id): """Delete the specific Rule from dictionary indexed by 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
python
def delete_rule(self, rule_id): """Delete the specific Rule from dictionary indexed by 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
[ "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...
Delete the specific Rule from dictionary indexed by rule id.
[ "Delete", "the", "specific", "Rule", "from", "dictionary", "indexed", "by", "rule", "id", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L124-L130
train
37,801
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMapAttr.rule_update
def rule_update(self, rule_id, rule): """Update the rule. """ if rule_id not in self.rules: LOG.error("Rule ID not present %s", rule_id) return self.rules[rule_id].update(rule)
python
def rule_update(self, rule_id, rule): """Update the rule. """ if rule_id not in self.rules: LOG.error("Rule ID not present %s", rule_id) return self.rules[rule_id].update(rule)
[ "def", "rule_update", "(", "self", ",", "rule_id", ",", "rule", ")", ":", "if", "rule_id", "not", "in", "self", ".", "rules", ":", "LOG", ".", "error", "(", "\"Rule ID not present %s\"", ",", "rule_id", ")", "return", "self", ".", "rules", "[", "rule_id"...
Update the rule.
[ "Update", "the", "rule", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L142-L147
train
37,802
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMapAttr.is_fw_present
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
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
[ "def", "is_fw_present", "(", "self", ",", "fw_id", ")", ":", "if", "self", ".", "fw_id", "is", "None", "or", "self", ".", "fw_id", "!=", "fw_id", ":", "return", "False", "else", ":", "return", "True" ]
Returns if firewall index by ID is present in dictionary.
[ "Returns", "if", "firewall", "index", "by", "ID", "is", "present", "in", "dictionary", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L153-L158
train
37,803
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMapAttr.create_fw
def create_fw(self, proj_name, pol_id, fw_id, fw_name, fw_type, rtr_id): """Fills up the local attributes when FW is created. """ 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_type = fw_type self.router_id = rtr_id
python
def create_fw(self, proj_name, pol_id, fw_id, fw_name, fw_type, rtr_id): """Fills up the local attributes when FW is created. """ 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_type = fw_type self.router_id = rtr_id
[ "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_...
Fills up the local attributes when FW is created.
[ "Fills", "up", "the", "local", "attributes", "when", "FW", "is", "created", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L160-L168
train
37,804
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMapAttr.delete_fw
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
python
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
[ "def", "delete_fw", "(", "self", ",", "fw_id", ")", ":", "self", ".", "fw_id", "=", "None", "self", ".", "fw_name", "=", "None", "self", ".", "fw_created", "=", "False", "self", ".", "active_pol_id", "=", "None" ]
Deletes the FW local attributes.
[ "Deletes", "the", "FW", "local", "attributes", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L170-L175
train
37,805
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMapAttr.delete_policy
def delete_policy(self, pol_id): """Deletes the policy from the local dictionary. """ if pol_id not in self.policies: LOG.error("Invalid policy %s", pol_id) return del self.policies[pol_id] self.policy_cnt -= 1
python
def delete_policy(self, pol_id): """Deletes the policy from the local dictionary. """ if pol_id not in self.policies: LOG.error("Invalid policy %s", pol_id) return del self.policies[pol_id] self.policy_cnt -= 1
[ "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", "]", ...
Deletes the policy from the local dictionary.
[ "Deletes", "the", "policy", "from", "the", "local", "dictionary", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L177-L183
train
37,806
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMapAttr.is_fw_complete
def is_fw_complete(self): """This API returns the completion status of FW. This returns True if a FW is created with a active policy that has more than one rule associated with it and if a driver init is done successfully. """ LOG.info("In fw_complete needed %(fw_created)s " "%(active_policy_id)s %(is_fw_drvr_created)s " "%(pol_present)s %(fw_type)s", {'fw_created': self.fw_created, 'active_policy_id': self.active_pol_id, 'is_fw_drvr_created': self.is_fw_drvr_created(), 'pol_present': self.active_pol_id in self.policies, 'fw_type': self.fw_type}) if self.active_pol_id is not None: LOG.info("In Drvr create needed %(len_policy)s %(one_rule)s", {'len_policy': len(self.policies[self.active_pol_id]['rule_dict']), 'one_rule': self.one_rule_present(self.active_pol_id)}) return self.fw_created and self.active_pol_id and ( self.is_fw_drvr_created()) and self.fw_type and ( self.active_pol_id in self.policies) and ( len(self.policies[self.active_pol_id]['rule_dict'])) > 0 and ( self.one_rule_present(self.active_pol_id))
python
def is_fw_complete(self): """This API returns the completion status of FW. This returns True if a FW is created with a active policy that has more than one rule associated with it and if a driver init is done successfully. """ LOG.info("In fw_complete needed %(fw_created)s " "%(active_policy_id)s %(is_fw_drvr_created)s " "%(pol_present)s %(fw_type)s", {'fw_created': self.fw_created, 'active_policy_id': self.active_pol_id, 'is_fw_drvr_created': self.is_fw_drvr_created(), 'pol_present': self.active_pol_id in self.policies, 'fw_type': self.fw_type}) if self.active_pol_id is not None: LOG.info("In Drvr create needed %(len_policy)s %(one_rule)s", {'len_policy': len(self.policies[self.active_pol_id]['rule_dict']), 'one_rule': self.one_rule_present(self.active_pol_id)}) return self.fw_created and self.active_pol_id and ( self.is_fw_drvr_created()) and self.fw_type and ( self.active_pol_id in self.policies) and ( len(self.policies[self.active_pol_id]['rule_dict'])) > 0 and ( self.one_rule_present(self.active_pol_id))
[ "def", "is_fw_complete", "(", "self", ")", ":", "LOG", ".", "info", "(", "\"In fw_complete needed %(fw_created)s \"", "\"%(active_policy_id)s %(is_fw_drvr_created)s \"", "\"%(pol_present)s %(fw_type)s\"", ",", "{", "'fw_created'", ":", "self", ".", "fw_created", ",", "'acti...
This API returns the completion status of FW. This returns True if a FW is created with a active policy that has more than one rule associated with it and if a driver init is done successfully.
[ "This", "API", "returns", "the", "completion", "status", "of", "FW", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L185-L210
train
37,807
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMapAttr.one_rule_present
def one_rule_present(self, pol_id): """Returns if atleast one rule is present in the policy. """ pol_dict = self.policies[pol_id] for rule in pol_dict['rule_dict']: if self.is_rule_present(rule): return True return False
python
def one_rule_present(self, pol_id): """Returns if atleast one rule is present in the policy. """ pol_dict = self.policies[pol_id] for rule in pol_dict['rule_dict']: if self.is_rule_present(rule): return True return False
[ "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", ")", ":", "...
Returns if atleast one rule is present in the policy.
[ "Returns", "if", "atleast", "one", "rule", "is", "present", "in", "the", "policy", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L240-L246
train
37,808
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMapAttr.get_fw_dict
def get_fw_dict(self): """This API creates a FW dictionary from the local attributes. """ fw_dict = {} if self.fw_id is None: return fw_dict fw_dict = {'rules': {}, 'tenant_name': self.tenant_name, 'tenant_id': self.tenant_id, 'fw_id': self.fw_id, 'fw_name': self.fw_name, 'firewall_policy_id': self.active_pol_id, 'fw_type': self.fw_type, 'router_id': self.router_id} # When Firewall and Policy are both deleted and the SM is doing a # retry (maybe DCNM Out partition could not be deleted) during # which without this check, it throws an exception since # self.policies is empty. This is also an issue during restart. if self.active_pol_id not in self.policies: return fw_dict pol_dict = self.policies[self.active_pol_id] for rule in pol_dict['rule_dict']: fw_dict['rules'][rule] = self.rules[rule] return fw_dict
python
def get_fw_dict(self): """This API creates a FW dictionary from the local attributes. """ fw_dict = {} if self.fw_id is None: return fw_dict fw_dict = {'rules': {}, 'tenant_name': self.tenant_name, 'tenant_id': self.tenant_id, 'fw_id': self.fw_id, 'fw_name': self.fw_name, 'firewall_policy_id': self.active_pol_id, 'fw_type': self.fw_type, 'router_id': self.router_id} # When Firewall and Policy are both deleted and the SM is doing a # retry (maybe DCNM Out partition could not be deleted) during # which without this check, it throws an exception since # self.policies is empty. This is also an issue during restart. if self.active_pol_id not in self.policies: return fw_dict pol_dict = self.policies[self.active_pol_id] for rule in pol_dict['rule_dict']: fw_dict['rules'][rule] = self.rules[rule] return fw_dict
[ "def", "get_fw_dict", "(", "self", ")", ":", "fw_dict", "=", "{", "}", "if", "self", ".", "fw_id", "is", "None", ":", "return", "fw_dict", "fw_dict", "=", "{", "'rules'", ":", "{", "}", ",", "'tenant_name'", ":", "self", ".", "tenant_name", ",", "'te...
This API creates a FW dictionary from the local attributes.
[ "This", "API", "creates", "a", "FW", "dictionary", "from", "the", "local", "attributes", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L262-L281
train
37,809
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMapAttr.update_fw_params
def update_fw_params(self, rtr_id=-1, fw_type=-1): """Updates the FW parameters. """ if rtr_id != -1: self.router_id = rtr_id if fw_type != -1: self.fw_type = fw_type
python
def update_fw_params(self, rtr_id=-1, fw_type=-1): """Updates the FW parameters. """ if rtr_id != -1: self.router_id = rtr_id if fw_type != -1: self.fw_type = fw_type
[ "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_ty...
Updates the FW parameters.
[ "Updates", "the", "FW", "parameters", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L283-L288
train
37,810
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr.populate_cfg_dcnm
def populate_cfg_dcnm(self, cfg, dcnm_obj): """This routine stores the DCNM object. """ if not self.fw_init: return self.dcnm_obj = dcnm_obj self.fabric.store_dcnm(dcnm_obj) self.populate_dcnm_obj(dcnm_obj)
python
def populate_cfg_dcnm(self, cfg, dcnm_obj): """This routine stores the DCNM object. """ if not self.fw_init: return self.dcnm_obj = dcnm_obj self.fabric.store_dcnm(dcnm_obj) self.populate_dcnm_obj(dcnm_obj)
[ "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", ".", "...
This routine stores the DCNM object.
[ "This", "routine", "stores", "the", "DCNM", "object", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L327-L333
train
37,811
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr.populate_event_queue
def populate_event_queue(self, cfg, que_obj): """This routine is for storing the Event Queue obj. """ if not self.fw_init: return self.que_obj = que_obj self.populate_event_que(que_obj)
python
def populate_event_queue(self, cfg, que_obj): """This routine is for storing the Event Queue obj. """ if not self.fw_init: return self.que_obj = que_obj self.populate_event_que(que_obj)
[ "def", "populate_event_queue", "(", "self", ",", "cfg", ",", "que_obj", ")", ":", "if", "not", "self", ".", "fw_init", ":", "return", "self", ".", "que_obj", "=", "que_obj", "self", ".", "populate_event_que", "(", "que_obj", ")" ]
This routine is for storing the Event Queue obj.
[ "This", "routine", "is", "for", "storing", "the", "Event", "Queue", "obj", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L335-L340
train
37,812
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr.network_sub_create_notif
def network_sub_create_notif(self, tenant_id, tenant_name, cidr): """Network create notification. """ if not self.fw_init: return self.network_create_notif(tenant_id, tenant_name, cidr)
python
def network_sub_create_notif(self, tenant_id, tenant_name, cidr): """Network create notification. """ if not self.fw_init: return self.network_create_notif(tenant_id, tenant_name, cidr)
[ "def", "network_sub_create_notif", "(", "self", ",", "tenant_id", ",", "tenant_name", ",", "cidr", ")", ":", "if", "not", "self", ".", "fw_init", ":", "return", "self", ".", "network_create_notif", "(", "tenant_id", ",", "tenant_name", ",", "cidr", ")" ]
Network create notification.
[ "Network", "create", "notification", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L342-L346
train
37,813
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr.network_del_notif
def network_del_notif(self, tenant_id, tenant_name, net_id): """Network delete notification. """ if not self.fw_init: return self.network_delete_notif(tenant_id, tenant_name, net_id)
python
def network_del_notif(self, tenant_id, tenant_name, net_id): """Network delete notification. """ if not self.fw_init: return self.network_delete_notif(tenant_id, tenant_name, net_id)
[ "def", "network_del_notif", "(", "self", ",", "tenant_id", ",", "tenant_name", ",", "net_id", ")", ":", "if", "not", "self", ".", "fw_init", ":", "return", "self", ".", "network_delete_notif", "(", "tenant_id", ",", "tenant_name", ",", "net_id", ")" ]
Network delete notification.
[ "Network", "delete", "notification", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L348-L352
train
37,814
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr.project_create_notif
def project_create_notif(self, tenant_id, tenant_name): """Tenant Create notification. """ if not self.fw_init: return self.os_helper.create_router('_'.join([fw_constants.TENANT_EDGE_RTR, tenant_name]), tenant_id, [])
python
def project_create_notif(self, tenant_id, tenant_name): """Tenant Create notification. """ if not self.fw_init: return self.os_helper.create_router('_'.join([fw_constants.TENANT_EDGE_RTR, tenant_name]), tenant_id, [])
[ "def", "project_create_notif", "(", "self", ",", "tenant_id", ",", "tenant_name", ")", ":", "if", "not", "self", ".", "fw_init", ":", "return", "self", ".", "os_helper", ".", "create_router", "(", "'_'", ".", "join", "(", "[", "fw_constants", ".", "TENANT_...
Tenant Create notification.
[ "Tenant", "Create", "notification", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L354-L360
train
37,815
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr.project_delete_notif
def project_delete_notif(self, tenant_id, tenant_name): """Tenant Delete notification. """ if not self.fw_init: return rtr_name = '_'.join([fw_constants.TENANT_EDGE_RTR, tenant_name]) self.os_helper.delete_router_by_name(rtr_name, tenant_id)
python
def project_delete_notif(self, tenant_id, tenant_name): """Tenant Delete notification. """ if not self.fw_init: return rtr_name = '_'.join([fw_constants.TENANT_EDGE_RTR, tenant_name]) self.os_helper.delete_router_by_name(rtr_name, tenant_id)
[ "def", "project_delete_notif", "(", "self", ",", "tenant_id", ",", "tenant_name", ")", ":", "if", "not", "self", ".", "fw_init", ":", "return", "rtr_name", "=", "'_'", ".", "join", "(", "[", "fw_constants", ".", "TENANT_EDGE_RTR", ",", "tenant_name", "]", ...
Tenant Delete notification.
[ "Tenant", "Delete", "notification", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L362-L367
train
37,816
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr._create_fw_fab_dev_te
def _create_fw_fab_dev_te(self, tenant_id, drvr_name, fw_dict): """Prepares the Fabric and configures the device. This routine calls the fabric class to prepare the fabric when a firewall is created. It also calls the device manager to configure the device. It updates the database with the final result. """ 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) if not ret: LOG.error("Prepare Fabric failed") return else: self.update_fw_db_final_result(fw_dict.get('fw_id'), ( fw_constants.RESULT_FW_CREATE_DONE)) ret = self.create_fw_device(tenant_id, fw_dict.get('fw_id'), fw_dict) if ret: self.fwid_attr[tenant_id].fw_drvr_created(True) self.update_fw_db_dev_status(fw_dict.get('fw_id'), 'SUCCESS') LOG.info("FW device create returned success for tenant %s", tenant_id) else: LOG.error("FW device create returned failure for tenant %s", tenant_id)
python
def _create_fw_fab_dev_te(self, tenant_id, drvr_name, fw_dict): """Prepares the Fabric and configures the device. This routine calls the fabric class to prepare the fabric when a firewall is created. It also calls the device manager to configure the device. It updates the database with the final result. """ 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) if not ret: LOG.error("Prepare Fabric failed") return else: self.update_fw_db_final_result(fw_dict.get('fw_id'), ( fw_constants.RESULT_FW_CREATE_DONE)) ret = self.create_fw_device(tenant_id, fw_dict.get('fw_id'), fw_dict) if ret: self.fwid_attr[tenant_id].fw_drvr_created(True) self.update_fw_db_dev_status(fw_dict.get('fw_id'), 'SUCCESS') LOG.info("FW device create returned success for tenant %s", tenant_id) else: LOG.error("FW device create returned failure for tenant %s", tenant_id)
[ "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_...
Prepares the Fabric and configures the device. This routine calls the fabric class to prepare the fabric when a firewall is created. It also calls the device manager to configure the device. It updates the database with the final result.
[ "Prepares", "the", "Fabric", "and", "configures", "the", "device", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L369-L396
train
37,817
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr._create_fw_fab_dev
def _create_fw_fab_dev(self, tenant_id, drvr_name, fw_dict): """This routine calls the Tenant Edge routine if FW Type is TE. """ if fw_dict.get('fw_type') == fw_constants.FW_TENANT_EDGE: self._create_fw_fab_dev_te(tenant_id, drvr_name, fw_dict)
python
def _create_fw_fab_dev(self, tenant_id, drvr_name, fw_dict): """This routine calls the Tenant Edge routine if FW Type is TE. """ if fw_dict.get('fw_type') == fw_constants.FW_TENANT_EDGE: self._create_fw_fab_dev_te(tenant_id, drvr_name, fw_dict)
[ "def", "_create_fw_fab_dev", "(", "self", ",", "tenant_id", ",", "drvr_name", ",", "fw_dict", ")", ":", "if", "fw_dict", ".", "get", "(", "'fw_type'", ")", "==", "fw_constants", ".", "FW_TENANT_EDGE", ":", "self", ".", "_create_fw_fab_dev_te", "(", "tenant_id"...
This routine calls the Tenant Edge routine if FW Type is TE.
[ "This", "routine", "calls", "the", "Tenant", "Edge", "routine", "if", "FW", "Type", "is", "TE", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L398-L401
train
37,818
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr._check_create_fw
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 fabric and configure the device. """ if self.fwid_attr[tenant_id].is_fw_drvr_create_needed(): fw_dict = self.fwid_attr[tenant_id].get_fw_dict() try: with self.fwid_attr[tenant_id].mutex_lock: ret = self.add_fw_db(fw_dict.get('fw_id'), fw_dict, fw_constants.RESULT_FW_CREATE_INIT) if not ret: LOG.error("Adding FW DB failed for tenant %s", tenant_id) return self._create_fw_fab_dev(tenant_id, drvr_name, fw_dict) except Exception as exc: LOG.error("Exception raised in create fw %s", str(exc))
python
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 fabric and configure the device. """ if self.fwid_attr[tenant_id].is_fw_drvr_create_needed(): fw_dict = self.fwid_attr[tenant_id].get_fw_dict() try: with self.fwid_attr[tenant_id].mutex_lock: ret = self.add_fw_db(fw_dict.get('fw_id'), fw_dict, fw_constants.RESULT_FW_CREATE_INIT) if not ret: LOG.error("Adding FW DB failed for tenant %s", tenant_id) return self._create_fw_fab_dev(tenant_id, drvr_name, fw_dict) except Exception as exc: LOG.error("Exception raised in create fw %s", str(exc))
[ "def", "_check_create_fw", "(", "self", ",", "tenant_id", ",", "drvr_name", ")", ":", "if", "self", ".", "fwid_attr", "[", "tenant_id", "]", ".", "is_fw_drvr_create_needed", "(", ")", ":", "fw_dict", "=", "self", ".", "fwid_attr", "[", "tenant_id", "]", "....
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 fabric and configure the device.
[ "Creates", "the", "Firewall", "if", "all", "conditions", "are", "met", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L403-L423
train
37,819
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr._check_delete_fw
def _check_delete_fw(self, tenant_id, drvr_name): """Deletes the Firewall, if all conditioms are met. This function after modifying the DB with delete operation status, calls the routine to remove the fabric cfg from DB and unconfigure the device. """ 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('fw_id'), ( fw_constants.RESULT_FW_DELETE_INIT)) ret = self._delete_fw_fab_dev(tenant_id, drvr_name, fw_dict) except Exception as exc: LOG.error("Exception raised in delete fw %s", str(exc)) return ret
python
def _check_delete_fw(self, tenant_id, drvr_name): """Deletes the Firewall, if all conditioms are met. This function after modifying the DB with delete operation status, calls the routine to remove the fabric cfg from DB and unconfigure the device. """ 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('fw_id'), ( fw_constants.RESULT_FW_DELETE_INIT)) ret = self._delete_fw_fab_dev(tenant_id, drvr_name, fw_dict) except Exception as exc: LOG.error("Exception raised in delete fw %s", str(exc)) return ret
[ "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", "[", ...
Deletes the Firewall, if all conditioms are met. This function after modifying the DB with delete operation status, calls the routine to remove the fabric cfg from DB and unconfigure the device.
[ "Deletes", "the", "Firewall", "if", "all", "conditioms", "are", "met", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L455-L471
train
37,820
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr._check_update_fw
def _check_update_fw(self, tenant_id, drvr_name): """Update the Firewall config by calling the driver. This function calls the device manager routine to update the device with modified FW cfg. """ 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)
python
def _check_update_fw(self, tenant_id, drvr_name): """Update the Firewall config by calling the driver. This function calls the device manager routine to update the device with modified FW cfg. """ 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)
[ "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_...
Update the Firewall config by calling the driver. This function calls the device manager routine to update the device with modified FW cfg.
[ "Update", "the", "Firewall", "config", "by", "calling", "the", "driver", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L473-L481
train
37,821
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr._fw_create
def _fw_create(self, drvr_name, data, cache): """Firewall create routine. This function updates its local cache with FW parameters. It checks if local cache has information about the Policy associated with the FW. If not, it means a restart has happened. It retrieves the policy associated with the FW by calling Openstack API's and calls t he policy create internal routine. """ fw = data.get('firewall') tenant_id = fw.get('tenant_id') fw_name = fw.get('name') fw_id = fw.get('id') fw_pol_id = fw.get('firewall_policy_id') admin_state = fw.get('admin_state_up') rtr_id = None if 'router_ids' in fw and len(fw.get('router_ids')) != 0: rtr_id = fw.get('router_ids')[0] if not admin_state: LOG.debug("Admin state disabled") return name = dfa_dbm.DfaDBMixin.get_project_name(self, tenant_id) rtr_name = '_'.join([fw_constants.TENANT_EDGE_RTR, name]) fw_rtr_name = self.os_helper.get_rtr_name(rtr_id) fw_type = None if fw_rtr_name == rtr_name: fw_type = fw_constants.FW_TENANT_EDGE if tenant_id not in self.fwid_attr: self.fwid_attr[tenant_id] = FwMapAttr(tenant_id) tenant_obj = self.fwid_attr[tenant_id] tenant_obj.create_fw(name, fw_pol_id, fw_id, fw_name, fw_type, rtr_id) self.tenant_db.store_fw_tenant(fw_id, tenant_id) if not cache: self._check_create_fw(tenant_id, drvr_name) if fw_pol_id is not None and not ( tenant_obj.is_policy_present(fw_pol_id)): pol_data = self.os_helper.get_fw_policy(fw_pol_id) if pol_data is not None: self.fw_policy_create(pol_data, cache=cache)
python
def _fw_create(self, drvr_name, data, cache): """Firewall create routine. This function updates its local cache with FW parameters. It checks if local cache has information about the Policy associated with the FW. If not, it means a restart has happened. It retrieves the policy associated with the FW by calling Openstack API's and calls t he policy create internal routine. """ fw = data.get('firewall') tenant_id = fw.get('tenant_id') fw_name = fw.get('name') fw_id = fw.get('id') fw_pol_id = fw.get('firewall_policy_id') admin_state = fw.get('admin_state_up') rtr_id = None if 'router_ids' in fw and len(fw.get('router_ids')) != 0: rtr_id = fw.get('router_ids')[0] if not admin_state: LOG.debug("Admin state disabled") return name = dfa_dbm.DfaDBMixin.get_project_name(self, tenant_id) rtr_name = '_'.join([fw_constants.TENANT_EDGE_RTR, name]) fw_rtr_name = self.os_helper.get_rtr_name(rtr_id) fw_type = None if fw_rtr_name == rtr_name: fw_type = fw_constants.FW_TENANT_EDGE if tenant_id not in self.fwid_attr: self.fwid_attr[tenant_id] = FwMapAttr(tenant_id) tenant_obj = self.fwid_attr[tenant_id] tenant_obj.create_fw(name, fw_pol_id, fw_id, fw_name, fw_type, rtr_id) self.tenant_db.store_fw_tenant(fw_id, tenant_id) if not cache: self._check_create_fw(tenant_id, drvr_name) if fw_pol_id is not None and not ( tenant_obj.is_policy_present(fw_pol_id)): pol_data = self.os_helper.get_fw_policy(fw_pol_id) if pol_data is not None: self.fw_policy_create(pol_data, cache=cache)
[ "def", "_fw_create", "(", "self", ",", "drvr_name", ",", "data", ",", "cache", ")", ":", "fw", "=", "data", ".", "get", "(", "'firewall'", ")", "tenant_id", "=", "fw", ".", "get", "(", "'tenant_id'", ")", "fw_name", "=", "fw", ".", "get", "(", "'na...
Firewall create routine. This function updates its local cache with FW parameters. It checks if local cache has information about the Policy associated with the FW. If not, it means a restart has happened. It retrieves the policy associated with the FW by calling Openstack API's and calls t he policy create internal routine.
[ "Firewall", "create", "routine", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L496-L537
train
37,822
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr.fw_create
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))
python
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))
[ "def", "fw_create", "(", "self", ",", "data", ",", "fw_name", "=", "None", ",", "cache", "=", "False", ")", ":", "LOG", ".", "debug", "(", "\"FW create %s\"", ",", "data", ")", "try", ":", "self", ".", "_fw_create", "(", "fw_name", ",", "data", ",", ...
Top level FW create function.
[ "Top", "level", "FW", "create", "function", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L539-L545
train
37,823
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr._fw_update
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 cfgd or about to be cfgd in case of error. If yes, this may be a change in policies attached to FW. If no, do a check, create after storing the parameters like rtr_id. """ fw = data.get('firewall') tenant_id = fw.get('tenant_id') if self.fwid_attr[tenant_id].is_fw_complete() or \ self.fwid_attr[tenant_id].is_fw_drvr_create_needed(): prev_info_complete = True else: prev_info_complete = False tenant_obj = self.fwid_attr[tenant_id] if 'router_ids' in fw and len(fw.get('router_ids')) != 0: rtr_id = fw.get('router_ids')[0] name = dfa_dbm.DfaDBMixin.get_project_name(self, tenant_id) rtr_name = '_'.join([fw_constants.TENANT_EDGE_RTR, name]) fw_rtr_name = self.os_helper.get_rtr_name(rtr_id) fw_type = None if fw_rtr_name == rtr_name: fw_type = fw_constants.FW_TENANT_EDGE tenant_obj.update_fw_params(rtr_id, fw_type) if not prev_info_complete: self._check_create_fw(tenant_id, drvr_name)
python
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 cfgd or about to be cfgd in case of error. If yes, this may be a change in policies attached to FW. If no, do a check, create after storing the parameters like rtr_id. """ fw = data.get('firewall') tenant_id = fw.get('tenant_id') if self.fwid_attr[tenant_id].is_fw_complete() or \ self.fwid_attr[tenant_id].is_fw_drvr_create_needed(): prev_info_complete = True else: prev_info_complete = False tenant_obj = self.fwid_attr[tenant_id] if 'router_ids' in fw and len(fw.get('router_ids')) != 0: rtr_id = fw.get('router_ids')[0] name = dfa_dbm.DfaDBMixin.get_project_name(self, tenant_id) rtr_name = '_'.join([fw_constants.TENANT_EDGE_RTR, name]) fw_rtr_name = self.os_helper.get_rtr_name(rtr_id) fw_type = None if fw_rtr_name == rtr_name: fw_type = fw_constants.FW_TENANT_EDGE tenant_obj.update_fw_params(rtr_id, fw_type) if not prev_info_complete: self._check_create_fw(tenant_id, drvr_name)
[ "def", "_fw_update", "(", "self", ",", "drvr_name", ",", "data", ")", ":", "fw", "=", "data", ".", "get", "(", "'firewall'", ")", "tenant_id", "=", "fw", ".", "get", "(", "'tenant_id'", ")", "if", "self", ".", "fwid_attr", "[", "tenant_id", "]", ".",...
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 cfgd or about to be cfgd in case of error. If yes, this may be a change in policies attached to FW. If no, do a check, create after storing the parameters like rtr_id.
[ "Update", "routine", "for", "the", "Firewall", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L548-L581
train
37,824
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr.fw_update
def fw_update(self, data, fw_name=None): """Top level FW update function. """ LOG.debug("FW Update %s", data) self._fw_update(fw_name, data)
python
def fw_update(self, data, fw_name=None): """Top level FW update function. """ LOG.debug("FW Update %s", data) self._fw_update(fw_name, data)
[ "def", "fw_update", "(", "self", ",", "data", ",", "fw_name", "=", "None", ")", ":", "LOG", ".", "debug", "(", "\"FW Update %s\"", ",", "data", ")", "self", ".", "_fw_update", "(", "fw_name", ",", "data", ")" ]
Top level FW update function.
[ "Top", "level", "FW", "update", "function", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L583-L586
train
37,825
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr._fw_delete
def _fw_delete(self, drvr_name, data): """Firewall Delete routine. This function calls routines to remove FW from fabric and device. It also updates its local cache. """ fw_id = data.get('firewall_id') tenant_id = self.tenant_db.get_fw_tenant(fw_id) if tenant_id not in self.fwid_attr: LOG.error("Invalid tenant id for FW delete %s", tenant_id) return tenant_obj = self.fwid_attr[tenant_id] ret = self._check_delete_fw(tenant_id, drvr_name) if ret: tenant_obj.delete_fw(fw_id) self.tenant_db.del_fw_tenant(fw_id)
python
def _fw_delete(self, drvr_name, data): """Firewall Delete routine. This function calls routines to remove FW from fabric and device. It also updates its local cache. """ fw_id = data.get('firewall_id') tenant_id = self.tenant_db.get_fw_tenant(fw_id) if tenant_id not in self.fwid_attr: LOG.error("Invalid tenant id for FW delete %s", tenant_id) return tenant_obj = self.fwid_attr[tenant_id] ret = self._check_delete_fw(tenant_id, drvr_name) if ret: tenant_obj.delete_fw(fw_id) self.tenant_db.del_fw_tenant(fw_id)
[ "def", "_fw_delete", "(", "self", ",", "drvr_name", ",", "data", ")", ":", "fw_id", "=", "data", ".", "get", "(", "'firewall_id'", ")", "tenant_id", "=", "self", ".", "tenant_db", ".", "get_fw_tenant", "(", "fw_id", ")", "if", "tenant_id", "not", "in", ...
Firewall Delete routine. This function calls routines to remove FW from fabric and device. It also updates its local cache.
[ "Firewall", "Delete", "routine", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L589-L606
train
37,826
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr._fw_rule_decode_store
def _fw_rule_decode_store(self, data): """Misc function to decode the firewall rule from Openstack. """ 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_rule.get( 'destination_ip_address'), 'source_port': fw_rule.get('source_port'), 'destination_port': fw_rule.get('destination_port'), 'action': fw_rule.get('action'), 'enabled': fw_rule.get('enabled'), 'name': fw_rule.get('name')} return rule
python
def _fw_rule_decode_store(self, data): """Misc function to decode the firewall rule from Openstack. """ 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_rule.get( 'destination_ip_address'), 'source_port': fw_rule.get('source_port'), 'destination_port': fw_rule.get('destination_port'), 'action': fw_rule.get('action'), 'enabled': fw_rule.get('enabled'), 'name': fw_rule.get('name')} return rule
[ "def", "_fw_rule_decode_store", "(", "self", ",", "data", ")", ":", "fw_rule", "=", "data", ".", "get", "(", "'firewall_rule'", ")", "rule", "=", "{", "'protocol'", ":", "fw_rule", ".", "get", "(", "'protocol'", ")", ",", "'source_ip_address'", ":", "fw_ru...
Misc function to decode the firewall rule from Openstack.
[ "Misc", "function", "to", "decode", "the", "firewall", "rule", "from", "Openstack", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L612-L624
train
37,827
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr._fw_rule_create
def _fw_rule_create(self, drvr_name, data, cache): """Firewall Rule create routine. This function updates its local cache with rule parameters. It checks if local cache has information about the Policy associated with the rule. If not, it means a restart has happened. It retrieves the policy associated with the FW by calling Openstack API's and calls t he policy create internal routine. """ tenant_id = data.get('firewall_rule').get('tenant_id') fw_rule = data.get('firewall_rule') rule = self._fw_rule_decode_store(data) fw_pol_id = fw_rule.get('firewall_policy_id') rule_id = fw_rule.get('id') if tenant_id not in self.fwid_attr: self.fwid_attr[tenant_id] = FwMapAttr(tenant_id) self.fwid_attr[tenant_id].store_rule(rule_id, rule) if not cache: self._check_create_fw(tenant_id, drvr_name) self.tenant_db.store_rule_tenant(rule_id, tenant_id) if fw_pol_id is not None and not ( self.fwid_attr[tenant_id].is_policy_present(fw_pol_id)): pol_data = self.os_helper.get_fw_policy(fw_pol_id) if pol_data is not None: self.fw_policy_create(pol_data, cache=cache)
python
def _fw_rule_create(self, drvr_name, data, cache): """Firewall Rule create routine. This function updates its local cache with rule parameters. It checks if local cache has information about the Policy associated with the rule. If not, it means a restart has happened. It retrieves the policy associated with the FW by calling Openstack API's and calls t he policy create internal routine. """ tenant_id = data.get('firewall_rule').get('tenant_id') fw_rule = data.get('firewall_rule') rule = self._fw_rule_decode_store(data) fw_pol_id = fw_rule.get('firewall_policy_id') rule_id = fw_rule.get('id') if tenant_id not in self.fwid_attr: self.fwid_attr[tenant_id] = FwMapAttr(tenant_id) self.fwid_attr[tenant_id].store_rule(rule_id, rule) if not cache: self._check_create_fw(tenant_id, drvr_name) self.tenant_db.store_rule_tenant(rule_id, tenant_id) if fw_pol_id is not None and not ( self.fwid_attr[tenant_id].is_policy_present(fw_pol_id)): pol_data = self.os_helper.get_fw_policy(fw_pol_id) if pol_data is not None: self.fw_policy_create(pol_data, cache=cache)
[ "def", "_fw_rule_create", "(", "self", ",", "drvr_name", ",", "data", ",", "cache", ")", ":", "tenant_id", "=", "data", ".", "get", "(", "'firewall_rule'", ")", ".", "get", "(", "'tenant_id'", ")", "fw_rule", "=", "data", ".", "get", "(", "'firewall_rule...
Firewall Rule create routine. This function updates its local cache with rule parameters. It checks if local cache has information about the Policy associated with the rule. If not, it means a restart has happened. It retrieves the policy associated with the FW by calling Openstack API's and calls t he policy create internal routine.
[ "Firewall", "Rule", "create", "routine", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L627-L651
train
37,828
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr.fw_rule_create
def fw_rule_create(self, data, fw_name=None, cache=False): """Top level rule creation routine. """ LOG.debug("FW Rule create %s", data) self._fw_rule_create(fw_name, data, cache)
python
def fw_rule_create(self, data, fw_name=None, cache=False): """Top level rule creation routine. """ LOG.debug("FW Rule create %s", data) self._fw_rule_create(fw_name, data, cache)
[ "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", ",", ...
Top level rule creation routine.
[ "Top", "level", "rule", "creation", "routine", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L653-L656
train
37,829
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr._fw_rule_delete
def _fw_rule_delete(self, drvr_name, data): """Function that updates its local cache after a rule is deleted. """ 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 delete %s", tenant_id) return tenant_obj = self.fwid_attr[tenant_id] # Guess actual FW/policy need not be deleted if this is the active # rule, Openstack does not allow it to be deleted tenant_obj.delete_rule(rule_id) self.tenant_db.del_rule_tenant(rule_id)
python
def _fw_rule_delete(self, drvr_name, data): """Function that updates its local cache after a rule is deleted. """ 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 delete %s", tenant_id) return tenant_obj = self.fwid_attr[tenant_id] # Guess actual FW/policy need not be deleted if this is the active # rule, Openstack does not allow it to be deleted tenant_obj.delete_rule(rule_id) self.tenant_db.del_rule_tenant(rule_id)
[ "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", ...
Function that updates its local cache after a rule is deleted.
[ "Function", "that", "updates", "its", "local", "cache", "after", "a", "rule", "is", "deleted", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L659-L671
train
37,830
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr.fw_rule_delete
def fw_rule_delete(self, data, fw_name=None): """Top level rule delete function. """ LOG.debug("FW Rule delete %s", data) self._fw_rule_delete(fw_name, data)
python
def fw_rule_delete(self, data, fw_name=None): """Top level rule delete function. """ LOG.debug("FW Rule delete %s", data) self._fw_rule_delete(fw_name, data)
[ "def", "fw_rule_delete", "(", "self", ",", "data", ",", "fw_name", "=", "None", ")", ":", "LOG", ".", "debug", "(", "\"FW Rule delete %s\"", ",", "data", ")", "self", ".", "_fw_rule_delete", "(", "fw_name", ",", "data", ")" ]
Top level rule delete function.
[ "Top", "level", "rule", "delete", "function", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L673-L676
train
37,831
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr._fw_rule_update
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('tenant_id') fw_rule = data.get('firewall_rule') rule = self._fw_rule_decode_store(data) rule_id = fw_rule.get('id') if tenant_id not in self.fwid_attr or not ( self.fwid_attr[tenant_id].is_rule_present(rule_id)): LOG.error("Incorrect update info for tenant %s", tenant_id) return self.fwid_attr[tenant_id].rule_update(rule_id, rule) self._check_update_fw(tenant_id, drvr_name)
python
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('tenant_id') fw_rule = data.get('firewall_rule') rule = self._fw_rule_decode_store(data) rule_id = fw_rule.get('id') if tenant_id not in self.fwid_attr or not ( self.fwid_attr[tenant_id].is_rule_present(rule_id)): LOG.error("Incorrect update info for tenant %s", tenant_id) return self.fwid_attr[tenant_id].rule_update(rule_id, rule) self._check_update_fw(tenant_id, drvr_name)
[ "def", "_fw_rule_update", "(", "self", ",", "drvr_name", ",", "data", ")", ":", "LOG", ".", "debug", "(", "\"FW Update %s\"", ",", "data", ")", "tenant_id", "=", "data", ".", "get", "(", "'firewall_rule'", ")", ".", "get", "(", "'tenant_id'", ")", "fw_ru...
Firewall Rule update routine. Function to decode the updated rules and call routines that in turn calls the device routines to update rules.
[ "Firewall", "Rule", "update", "routine", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L679-L695
train
37,832
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr.fw_rule_update
def fw_rule_update(self, data, fw_name=None): """Top level rule update routine. """ LOG.debug("FW Update Debug") self._fw_rule_update(fw_name, data)
python
def fw_rule_update(self, data, fw_name=None): """Top level rule update routine. """ LOG.debug("FW Update Debug") self._fw_rule_update(fw_name, data)
[ "def", "fw_rule_update", "(", "self", ",", "data", ",", "fw_name", "=", "None", ")", ":", "LOG", ".", "debug", "(", "\"FW Update Debug\"", ")", "self", ".", "_fw_rule_update", "(", "fw_name", ",", "data", ")" ]
Top level rule update routine.
[ "Top", "level", "rule", "update", "routine", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L697-L700
train
37,833
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr._fw_policy_delete
def _fw_policy_delete(self, drvr_name, data): """Routine to delete the policy from local cache. """ 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 FW delete %s", tenant_id) return tenant_obj = self.fwid_attr[tenant_id] # Guess actual FW need not be deleted since if this is the active # policy, Openstack does not allow it to be deleted tenant_obj.delete_policy(policy_id) self.tenant_db.del_policy_tenant(policy_id)
python
def _fw_policy_delete(self, drvr_name, data): """Routine to delete the policy from local cache. """ 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 FW delete %s", tenant_id) return tenant_obj = self.fwid_attr[tenant_id] # Guess actual FW need not be deleted since if this is the active # policy, Openstack does not allow it to be deleted tenant_obj.delete_policy(policy_id) self.tenant_db.del_policy_tenant(policy_id)
[ "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", "tena...
Routine to delete the policy from local cache.
[ "Routine", "to", "delete", "the", "policy", "from", "local", "cache", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L703-L715
train
37,834
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr.fw_policy_delete
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)
python
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)
[ "def", "fw_policy_delete", "(", "self", ",", "data", ",", "fw_name", "=", "None", ")", ":", "LOG", ".", "debug", "(", "\"FW Policy Debug\"", ")", "self", ".", "_fw_policy_delete", "(", "fw_name", ",", "data", ")" ]
Top level policy delete routine.
[ "Top", "level", "policy", "delete", "routine", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L717-L720
train
37,835
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr._fw_policy_create
def _fw_policy_create(self, drvr_name, data, cache): """Firewall Policy create routine. This function updates its local cache with policy parameters. It checks if local cache has information about the rules associated with the policy. If not, it means a restart has happened. It retrieves the rules associated with the policy by calling Openstack API's and calls the rule create internal routine. """ 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.get('id') policy_name = fw_policy.get('name') pol_rule_dict = fw_policy.get('firewall_rules') if tenant_id not in self.fwid_attr: self.fwid_attr[tenant_id] = FwMapAttr(tenant_id) policy['name'] = policy_name policy['rule_dict'] = pol_rule_dict self.fwid_attr[tenant_id].store_policy(policy_id, policy) if not cache: self._check_create_fw(tenant_id, drvr_name) self.tenant_db.store_policy_tenant(policy_id, tenant_id) for rule in pol_rule_dict: rule_id = rule if not self.fwid_attr[tenant_id].is_rule_present(rule_id): rule_data = self.os_helper.get_fw_rule(rule_id) if rule_data is not None: self.fw_rule_create(rule_data, cache=cache)
python
def _fw_policy_create(self, drvr_name, data, cache): """Firewall Policy create routine. This function updates its local cache with policy parameters. It checks if local cache has information about the rules associated with the policy. If not, it means a restart has happened. It retrieves the rules associated with the policy by calling Openstack API's and calls the rule create internal routine. """ 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.get('id') policy_name = fw_policy.get('name') pol_rule_dict = fw_policy.get('firewall_rules') if tenant_id not in self.fwid_attr: self.fwid_attr[tenant_id] = FwMapAttr(tenant_id) policy['name'] = policy_name policy['rule_dict'] = pol_rule_dict self.fwid_attr[tenant_id].store_policy(policy_id, policy) if not cache: self._check_create_fw(tenant_id, drvr_name) self.tenant_db.store_policy_tenant(policy_id, tenant_id) for rule in pol_rule_dict: rule_id = rule if not self.fwid_attr[tenant_id].is_rule_present(rule_id): rule_data = self.os_helper.get_fw_rule(rule_id) if rule_data is not None: self.fw_rule_create(rule_data, cache=cache)
[ "def", "_fw_policy_create", "(", "self", ",", "drvr_name", ",", "data", ",", "cache", ")", ":", "policy", "=", "{", "}", "fw_policy", "=", "data", ".", "get", "(", "'firewall_policy'", ")", "tenant_id", "=", "fw_policy", ".", "get", "(", "'tenant_id'", "...
Firewall Policy create routine. This function updates its local cache with policy parameters. It checks if local cache has information about the rules associated with the policy. If not, it means a restart has happened. It retrieves the rules associated with the policy by calling Openstack API's and calls the rule create internal routine.
[ "Firewall", "Policy", "create", "routine", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L723-L752
train
37,836
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr.fw_policy_create
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)
python
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)
[ "def", "fw_policy_create", "(", "self", ",", "data", ",", "fw_name", "=", "None", ",", "cache", "=", "False", ")", ":", "LOG", ".", "debug", "(", "\"FW Policy Debug\"", ")", "self", ".", "_fw_policy_create", "(", "fw_name", ",", "data", ",", "cache", ")"...
Top level policy create routine.
[ "Top", "level", "policy", "create", "routine", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L754-L757
train
37,837
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr.convert_fwdb_event_msg
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 restart, in order to populate local cache. """ rule.update({'tenant_id': tenant_id, 'id': rule_id, 'firewall_policy_id': policy_id}) fw_rule_data = {'firewall_rule': rule} return fw_rule_data
python
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 restart, in order to populate local cache. """ rule.update({'tenant_id': tenant_id, 'id': rule_id, 'firewall_policy_id': policy_id}) fw_rule_data = {'firewall_rule': rule} return fw_rule_data
[ "def", "convert_fwdb_event_msg", "(", "self", ",", "rule", ",", "tenant_id", ",", "rule_id", ",", "policy_id", ")", ":", "rule", ".", "update", "(", "{", "'tenant_id'", ":", "tenant_id", ",", "'id'", ":", "rule_id", ",", "'firewall_policy_id'", ":", "policy_...
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 restart, in order to populate local cache.
[ "Convert", "the", "Firewall", "DB", "to", "a", "event", "message", "format", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L759-L770
train
37,838
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr.convert_fwdb
def convert_fwdb(self, tenant_id, name, policy_id, fw_id): """Convert the Firewall DB to a query response. From FWDB inputs, this will create a FW message that resembles the actual data from Openstack, when a query for FW is done. """ fw_dict = {'tenant_id': tenant_id, 'name': name, 'id': fw_id, 'firewall_policy_id': policy_id, 'admin_state_up': True} fw_data = {'firewall': fw_dict} return fw_data
python
def convert_fwdb(self, tenant_id, name, policy_id, fw_id): """Convert the Firewall DB to a query response. From FWDB inputs, this will create a FW message that resembles the actual data from Openstack, when a query for FW is done. """ fw_dict = {'tenant_id': tenant_id, 'name': name, 'id': fw_id, 'firewall_policy_id': policy_id, 'admin_state_up': True} fw_data = {'firewall': fw_dict} return fw_data
[ "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'", ":", "p...
Convert the Firewall DB to a query response. From FWDB inputs, this will create a FW message that resembles the actual data from Openstack, when a query for FW is done.
[ "Convert", "the", "Firewall", "DB", "to", "a", "query", "response", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L772-L782
train
37,839
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr.populate_local_cache
def populate_local_cache(self): """This populates the local cache after reading the Database. It calls the appropriate rule create, fw create routines. It doesn't actually call the routine to prepare the fabric or cfg the device since it will be handled by retry module. """ 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_dict = fw_data.get('rules').get('rules') policy_id = fw_data.get('rules').get('firewall_policy_id') for rule in rule_dict: fw_evt_data = self.convert_fwdb_event_msg(rule_dict.get(rule), tenant_id, rule, policy_id) LOG.info("Populating Rules for tenant %s", tenant_id) self.fw_rule_create(fw_evt_data, cache=True) fw_os_data = self.os_helper.get_fw(fw_id) # If enabler is stopped and FW is deleted, then the above routine # will fail. if fw_os_data is None: fw_os_data = self.convert_fwdb(tenant_id, fw_data.get('name'), policy_id, fw_id) LOG.info("Populating FW for tenant %s", tenant_id) self.fw_create(fw_os_data, cache=True) if fw_data.get('device_status') == 'SUCCESS': self.fwid_attr[tenant_id].fw_drvr_created(True) else: self.fwid_attr[tenant_id].fw_drvr_created(False) return fw_dict
python
def populate_local_cache(self): """This populates the local cache after reading the Database. It calls the appropriate rule create, fw create routines. It doesn't actually call the routine to prepare the fabric or cfg the device since it will be handled by retry module. """ 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_dict = fw_data.get('rules').get('rules') policy_id = fw_data.get('rules').get('firewall_policy_id') for rule in rule_dict: fw_evt_data = self.convert_fwdb_event_msg(rule_dict.get(rule), tenant_id, rule, policy_id) LOG.info("Populating Rules for tenant %s", tenant_id) self.fw_rule_create(fw_evt_data, cache=True) fw_os_data = self.os_helper.get_fw(fw_id) # If enabler is stopped and FW is deleted, then the above routine # will fail. if fw_os_data is None: fw_os_data = self.convert_fwdb(tenant_id, fw_data.get('name'), policy_id, fw_id) LOG.info("Populating FW for tenant %s", tenant_id) self.fw_create(fw_os_data, cache=True) if fw_data.get('device_status') == 'SUCCESS': self.fwid_attr[tenant_id].fw_drvr_created(True) else: self.fwid_attr[tenant_id].fw_drvr_created(False) return fw_dict
[ "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", "(",...
This populates the local cache after reading the Database. It calls the appropriate rule create, fw create routines. It doesn't actually call the routine to prepare the fabric or cfg the device since it will be handled by retry module.
[ "This", "populates", "the", "local", "cache", "after", "reading", "the", "Database", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L784-L816
train
37,840
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr.retry_failure_fab_dev_create
def retry_failure_fab_dev_create(self, tenant_id, fw_data, fw_dict): """This module calls routine in fabric to retry the failure cases. If device is not successfully cfg/uncfg, it calls the device manager routine to cfg/uncfg the device. """ result = fw_data.get('result').split('(')[0] is_fw_virt = self.is_device_virtual() # Fabric portion if result == fw_constants.RESULT_FW_CREATE_INIT: name = dfa_dbm.DfaDBMixin.get_project_name(self, tenant_id) ret = self.fabric.retry_failure(tenant_id, name, fw_dict, is_fw_virt, result) if not ret: LOG.error("Retry failure returned fail for tenant %s", tenant_id) return else: result = fw_constants.RESULT_FW_CREATE_DONE self.update_fw_db_final_result(fw_dict.get('fw_id'), result) # Device portion if result == fw_constants.RESULT_FW_CREATE_DONE: if fw_data.get('device_status') != 'SUCCESS': ret = self.create_fw_device(tenant_id, fw_dict.get('fw_id'), fw_dict) if ret: self.fwid_attr[tenant_id].fw_drvr_created(True) self.update_fw_db_dev_status(fw_dict.get('fw_id'), 'SUCCESS') LOG.info("Retry failue return success for create" " tenant %s", tenant_id)
python
def retry_failure_fab_dev_create(self, tenant_id, fw_data, fw_dict): """This module calls routine in fabric to retry the failure cases. If device is not successfully cfg/uncfg, it calls the device manager routine to cfg/uncfg the device. """ result = fw_data.get('result').split('(')[0] is_fw_virt = self.is_device_virtual() # Fabric portion if result == fw_constants.RESULT_FW_CREATE_INIT: name = dfa_dbm.DfaDBMixin.get_project_name(self, tenant_id) ret = self.fabric.retry_failure(tenant_id, name, fw_dict, is_fw_virt, result) if not ret: LOG.error("Retry failure returned fail for tenant %s", tenant_id) return else: result = fw_constants.RESULT_FW_CREATE_DONE self.update_fw_db_final_result(fw_dict.get('fw_id'), result) # Device portion if result == fw_constants.RESULT_FW_CREATE_DONE: if fw_data.get('device_status') != 'SUCCESS': ret = self.create_fw_device(tenant_id, fw_dict.get('fw_id'), fw_dict) if ret: self.fwid_attr[tenant_id].fw_drvr_created(True) self.update_fw_db_dev_status(fw_dict.get('fw_id'), 'SUCCESS') LOG.info("Retry failue return success for create" " tenant %s", tenant_id)
[ "def", "retry_failure_fab_dev_create", "(", "self", ",", "tenant_id", ",", "fw_data", ",", "fw_dict", ")", ":", "result", "=", "fw_data", ".", "get", "(", "'result'", ")", ".", "split", "(", "'('", ")", "[", "0", "]", "is_fw_virt", "=", "self", ".", "i...
This module calls routine in fabric to retry the failure cases. If device is not successfully cfg/uncfg, it calls the device manager routine to cfg/uncfg the device.
[ "This", "module", "calls", "routine", "in", "fabric", "to", "retry", "the", "failure", "cases", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L818-L848
train
37,841
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr.retry_failure_fab_dev_delete
def retry_failure_fab_dev_delete(self, tenant_id, fw_data, fw_dict): """Retry the failure cases for delete. This module calls routine in fabric to retry the failure cases for delete. If device is not successfully cfg/uncfg, it calls the device manager routine to cfg/uncfg the device. """ 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_device_virtual() if result == fw_constants.RESULT_FW_DELETE_INIT: if self.fwid_attr[tenant_id].is_fw_drvr_created(): ret = self.delete_fw_device(tenant_id, fw_dict.get('fw_id'), fw_dict) if ret: # Device portion self.update_fw_db_dev_status(fw_dict.get('fw_id'), '') self.fwid_attr[tenant_id].fw_drvr_created(False) LOG.info("Retry failue dev return success for delete" " tenant %s", tenant_id) else: return name = dfa_dbm.DfaDBMixin.get_project_name(self, tenant_id) ret = self.fabric.retry_failure(tenant_id, name, fw_dict, is_fw_virt, result) if not ret: LOG.error("Retry failure returned fail for tenant %s", tenant_id) return result = fw_constants.RESULT_FW_DELETE_DONE self.update_fw_db_final_result(fw_dict.get('fw_id'), result) self.delete_fw(fw_dict.get('fw_id')) self.fwid_attr[tenant_id].delete_fw(fw_dict.get('fw_id')) self.tenant_db.del_fw_tenant(fw_dict.get('fw_id'))
python
def retry_failure_fab_dev_delete(self, tenant_id, fw_data, fw_dict): """Retry the failure cases for delete. This module calls routine in fabric to retry the failure cases for delete. If device is not successfully cfg/uncfg, it calls the device manager routine to cfg/uncfg the device. """ 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_device_virtual() if result == fw_constants.RESULT_FW_DELETE_INIT: if self.fwid_attr[tenant_id].is_fw_drvr_created(): ret = self.delete_fw_device(tenant_id, fw_dict.get('fw_id'), fw_dict) if ret: # Device portion self.update_fw_db_dev_status(fw_dict.get('fw_id'), '') self.fwid_attr[tenant_id].fw_drvr_created(False) LOG.info("Retry failue dev return success for delete" " tenant %s", tenant_id) else: return name = dfa_dbm.DfaDBMixin.get_project_name(self, tenant_id) ret = self.fabric.retry_failure(tenant_id, name, fw_dict, is_fw_virt, result) if not ret: LOG.error("Retry failure returned fail for tenant %s", tenant_id) return result = fw_constants.RESULT_FW_DELETE_DONE self.update_fw_db_final_result(fw_dict.get('fw_id'), result) self.delete_fw(fw_dict.get('fw_id')) self.fwid_attr[tenant_id].delete_fw(fw_dict.get('fw_id')) self.tenant_db.del_fw_tenant(fw_dict.get('fw_id'))
[ "def", "retry_failure_fab_dev_delete", "(", "self", ",", "tenant_id", ",", "fw_data", ",", "fw_dict", ")", ":", "result", "=", "fw_data", ".", "get", "(", "'result'", ")", ".", "split", "(", "'('", ")", "[", "0", "]", "name", "=", "dfa_dbm", ".", "DfaD...
Retry the failure cases for delete. This module calls routine in fabric to retry the failure cases for delete. If device is not successfully cfg/uncfg, it calls the device manager routine to cfg/uncfg the device.
[ "Retry", "the", "failure", "cases", "for", "delete", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L850-L886
train
37,842
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr.fw_retry_failures_create
def fw_retry_failures_create(self): """This module is called for retrying the create cases. """ 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_attr[tenant_id].get_fw_dict() if fw_dict: fw_obj, fw_data = self.get_fw(fw_dict.get('fw_id')) self.retry_failure_fab_dev_create(tenant_id, fw_data, fw_dict) else: LOG.error("FW data not found for tenant %s", tenant_id) except Exception as exc: LOG.error("Exception in retry failure create %s", str(exc))
python
def fw_retry_failures_create(self): """This module is called for retrying the create cases. """ 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_attr[tenant_id].get_fw_dict() if fw_dict: fw_obj, fw_data = self.get_fw(fw_dict.get('fw_id')) self.retry_failure_fab_dev_create(tenant_id, fw_data, fw_dict) else: LOG.error("FW data not found for tenant %s", tenant_id) except Exception as exc: LOG.error("Exception in retry failure create %s", str(exc))
[ "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"...
This module is called for retrying the create cases.
[ "This", "module", "is", "called", "for", "retrying", "the", "create", "cases", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L888-L905
train
37,843
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr.fill_fw_dict_from_db
def fill_fw_dict_from_db(self, fw_data): """ This routine is called to create a local fw_dict with data from DB. """ 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_policy_id'), 'fw_type': fw_data.get('fw_type'), 'router_id': fw_data.get('router_id'), 'rules': {}} for rule in rule_dict: fw_dict['rules'][rule] = rule_dict.get(rule) return fw_dict
python
def fill_fw_dict_from_db(self, fw_data): """ This routine is called to create a local fw_dict with data from DB. """ 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_policy_id'), 'fw_type': fw_data.get('fw_type'), 'router_id': fw_data.get('router_id'), 'rules': {}} for rule in rule_dict: fw_dict['rules'][rule] = rule_dict.get(rule) return fw_dict
[ "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'", ")", ",", ...
This routine is called to create a local fw_dict with data from DB.
[ "This", "routine", "is", "called", "to", "create", "a", "local", "fw_dict", "with", "data", "from", "DB", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L907-L919
train
37,844
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr.fw_retry_failures_delete
def fw_retry_failures_delete(self): """This routine is called for retrying the delete cases. """ for tenant_id in self.fwid_attr: try: with self.fwid_attr[tenant_id].mutex_lock: # For both create and delete case fw_data = self.get_fw_by_tenant_id(tenant_id) if fw_data is None: LOG.info("No FW for tenant %s", tenant_id) continue result = fw_data.get('result').split('(')[0] if result == fw_constants.RESULT_FW_DELETE_INIT: fw_dict = self.fwid_attr[tenant_id].get_fw_dict() # This means a restart has happened before the FW is # completely deleted if not fw_dict: # Need to fill fw_dict from fw_data fw_dict = self.fill_fw_dict_from_db(fw_data) self.retry_failure_fab_dev_delete(tenant_id, fw_data, fw_dict) except Exception as exc: LOG.error("Exception in retry failure delete %s", str(exc))
python
def fw_retry_failures_delete(self): """This routine is called for retrying the delete cases. """ for tenant_id in self.fwid_attr: try: with self.fwid_attr[tenant_id].mutex_lock: # For both create and delete case fw_data = self.get_fw_by_tenant_id(tenant_id) if fw_data is None: LOG.info("No FW for tenant %s", tenant_id) continue result = fw_data.get('result').split('(')[0] if result == fw_constants.RESULT_FW_DELETE_INIT: fw_dict = self.fwid_attr[tenant_id].get_fw_dict() # This means a restart has happened before the FW is # completely deleted if not fw_dict: # Need to fill fw_dict from fw_data fw_dict = self.fill_fw_dict_from_db(fw_data) self.retry_failure_fab_dev_delete(tenant_id, fw_data, fw_dict) except Exception as exc: LOG.error("Exception in retry failure delete %s", str(exc))
[ "def", "fw_retry_failures_delete", "(", "self", ")", ":", "for", "tenant_id", "in", "self", ".", "fwid_attr", ":", "try", ":", "with", "self", ".", "fwid_attr", "[", "tenant_id", "]", ".", "mutex_lock", ":", "# For both create and delete case", "fw_data", "=", ...
This routine is called for retrying the delete cases.
[ "This", "routine", "is", "called", "for", "retrying", "the", "delete", "cases", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L921-L943
train
37,845
openstack/networking-cisco
networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py
FwMgr.fw_retry_failures
def fw_retry_failures(self): """Top level retry routine called. """ 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 failures %s", str(exc))
python
def fw_retry_failures(self): """Top level retry routine called. """ 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 failures %s", str(exc))
[ "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", ":", ...
Top level retry routine called.
[ "Top", "level", "retry", "routine", "called", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/services/firewall/native/fw_mgr.py#L945-L953
train
37,846
openstack/networking-cisco
networking_cisco/plugins/cisco/common/htparser.py
HTParser._find_starts
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._indent_list: match = re.search(linespec, item[1]) if match: entry = (item, self._indent_list.index(item)) start_points.append(entry) return start_points
python
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._indent_list: match = re.search(linespec, item[1]) if match: entry = (item, self._indent_list.index(item)) start_points.append(entry) return start_points
[ "def", "_find_starts", "(", "self", ",", "linespec", ")", ":", "linespec", "+=", "\".*\"", "start_points", "=", "[", "]", "for", "item", "in", "self", ".", "_indent_list", ":", "match", "=", "re", ".", "search", "(", "linespec", ",", "item", "[", "1", ...
Finds the start points. Start points matching the linespec regex are returned as list in the following format: [(item, index), (item, index).....
[ "Finds", "the", "start", "points", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/common/htparser.py#L80-L95
train
37,847
openstack/networking-cisco
networking_cisco/plugins/cisco/common/htparser.py
HTParser.find_children
def find_children(self, linespec): """Find lines and immediate children that match the linespec regex. :param linespec: regular expression of line to match :returns: list of lines. These correspond to the lines that were matched and their immediate children """ res = [] for parent in self.find_objects(linespec): res.append(parent.line) res.extend([child.line for child in parent.children]) return res
python
def find_children(self, linespec): """Find lines and immediate children that match the linespec regex. :param linespec: regular expression of line to match :returns: list of lines. These correspond to the lines that were matched and their immediate children """ res = [] for parent in self.find_objects(linespec): res.append(parent.line) res.extend([child.line for child in parent.children]) return res
[ "def", "find_children", "(", "self", ",", "linespec", ")", ":", "res", "=", "[", "]", "for", "parent", "in", "self", ".", "find_objects", "(", "linespec", ")", ":", "res", ".", "append", "(", "parent", ".", "line", ")", "res", ".", "extend", "(", "...
Find lines and immediate children that match the linespec regex. :param linespec: regular expression of line to match :returns: list of lines. These correspond to the lines that were matched and their immediate children
[ "Find", "lines", "and", "immediate", "children", "that", "match", "the", "linespec", "regex", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/common/htparser.py#L144-L155
train
37,848
openstack/networking-cisco
networking_cisco/apps/saf/agent/vdp/lldpad.py
LldpadDriver.enable_evb
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: LOG.error("EVB cannot be set on NB") return False
python
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: LOG.error("EVB cannot be set on NB") return False
[ "def", "enable_evb", "(", "self", ")", ":", "if", "self", ".", "is_ncb", ":", "self", ".", "run_lldptool", "(", "[", "\"-T\"", ",", "\"-i\"", ",", "self", ".", "port_name", ",", "\"-g\"", ",", "\"ncb\"", ",", "\"-V\"", ",", "\"evb\"", ",", "\"enableTx=...
Function to enable EVB on the interface.
[ "Function", "to", "enable", "EVB", "on", "the", "interface", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/vdp/lldpad.py#L115-L124
train
37,849
openstack/networking-cisco
networking_cisco/apps/saf/agent/vdp/lldpad.py
LldpadDriver.enable_gpid
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"]) return True else: LOG.error("GPID cannot be set on NB") return False
python
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"]) return True else: LOG.error("GPID cannot be set on NB") return False
[ "def", "enable_gpid", "(", "self", ")", ":", "if", "self", ".", "is_ncb", ":", "self", ".", "run_lldptool", "(", "[", "\"-T\"", ",", "\"-i\"", ",", "self", ".", "port_name", ",", "\"-g\"", ",", "\"ncb\"", ",", "\"-V\"", ",", "\"evb\"", ",", "\"-c\"", ...
Function to enable Group ID on the interface. This is needed to use the MAC, GID, VID Filter.
[ "Function", "to", "enable", "Group", "ID", "on", "the", "interface", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/vdp/lldpad.py#L126-L137
train
37,850
openstack/networking-cisco
networking_cisco/apps/saf/agent/vdp/lldpad.py
LldpadDriver._vdp_refrsh_hndlr
def _vdp_refrsh_hndlr(self): """Periodic refresh of vNIC events to VDP. VDP daemon itself has keepalives. This is needed on top of it to keep Orchestrator like OpenStack, VDP daemon and the physical switch in sync. """ 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_vif_map = dict.copy(self.oui_vif_map) for key in six.iterkeys(vdp_vif_map): lvdp_dict = vdp_vif_map.get(key) loui_dict = oui_vif_map.get(key) if not lvdp_dict: return if not loui_dict: oui_id = "" oui_data = "" else: oui_id = loui_dict.get('oui_id') oui_data = loui_dict.get('oui_data') with self.mutex_lock: if key in self.vdp_vif_map: LOG.debug("Sending Refresh for VSI %s", lvdp_dict) vdp_vlan, fail_reason = self.send_vdp_assoc( vsiid=lvdp_dict.get('vsiid'), mgrid=lvdp_dict.get('mgrid'), typeid=lvdp_dict.get('typeid'), typeid_ver=lvdp_dict.get('typeid_ver'), vsiid_frmt=lvdp_dict.get('vsiid_frmt'), filter_frmt=lvdp_dict.get('filter_frmt'), gid=lvdp_dict.get('gid'), mac=lvdp_dict.get('mac'), vlan=0, oui_id=oui_id, oui_data=oui_data, sw_resp=True) # check validity. if not utils.is_valid_vlan_tag(vdp_vlan): LOG.error("Returned vlan %(vlan)s is invalid.", {'vlan': vdp_vlan}) # Need to invoke CB. So no return here. vdp_vlan = 0 exist_vdp_vlan = lvdp_dict.get('vdp_vlan') exist_fail_reason = lvdp_dict.get('fail_reason') callback_count = lvdp_dict.get('callback_count') # Condition will be hit only during error cases when switch # reloads or when compute reloads if vdp_vlan != exist_vdp_vlan or ( fail_reason != exist_fail_reason or callback_count > vdp_const.CALLBACK_THRESHOLD): # Invoke the CB Function cb_fn = lvdp_dict.get('vsw_cb_fn') cb_data = lvdp_dict.get('vsw_cb_data') if cb_fn: cb_fn(cb_data, vdp_vlan, fail_reason) lvdp_dict['vdp_vlan'] = vdp_vlan lvdp_dict['fail_reason'] = fail_reason lvdp_dict['callback_count'] = 0 else: lvdp_dict['callback_count'] += 1 except Exception as e: LOG.error("Exception in Refrsh %s", str(e))
python
def _vdp_refrsh_hndlr(self): """Periodic refresh of vNIC events to VDP. VDP daemon itself has keepalives. This is needed on top of it to keep Orchestrator like OpenStack, VDP daemon and the physical switch in sync. """ 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_vif_map = dict.copy(self.oui_vif_map) for key in six.iterkeys(vdp_vif_map): lvdp_dict = vdp_vif_map.get(key) loui_dict = oui_vif_map.get(key) if not lvdp_dict: return if not loui_dict: oui_id = "" oui_data = "" else: oui_id = loui_dict.get('oui_id') oui_data = loui_dict.get('oui_data') with self.mutex_lock: if key in self.vdp_vif_map: LOG.debug("Sending Refresh for VSI %s", lvdp_dict) vdp_vlan, fail_reason = self.send_vdp_assoc( vsiid=lvdp_dict.get('vsiid'), mgrid=lvdp_dict.get('mgrid'), typeid=lvdp_dict.get('typeid'), typeid_ver=lvdp_dict.get('typeid_ver'), vsiid_frmt=lvdp_dict.get('vsiid_frmt'), filter_frmt=lvdp_dict.get('filter_frmt'), gid=lvdp_dict.get('gid'), mac=lvdp_dict.get('mac'), vlan=0, oui_id=oui_id, oui_data=oui_data, sw_resp=True) # check validity. if not utils.is_valid_vlan_tag(vdp_vlan): LOG.error("Returned vlan %(vlan)s is invalid.", {'vlan': vdp_vlan}) # Need to invoke CB. So no return here. vdp_vlan = 0 exist_vdp_vlan = lvdp_dict.get('vdp_vlan') exist_fail_reason = lvdp_dict.get('fail_reason') callback_count = lvdp_dict.get('callback_count') # Condition will be hit only during error cases when switch # reloads or when compute reloads if vdp_vlan != exist_vdp_vlan or ( fail_reason != exist_fail_reason or callback_count > vdp_const.CALLBACK_THRESHOLD): # Invoke the CB Function cb_fn = lvdp_dict.get('vsw_cb_fn') cb_data = lvdp_dict.get('vsw_cb_data') if cb_fn: cb_fn(cb_data, vdp_vlan, fail_reason) lvdp_dict['vdp_vlan'] = vdp_vlan lvdp_dict['fail_reason'] = fail_reason lvdp_dict['callback_count'] = 0 else: lvdp_dict['callback_count'] += 1 except Exception as e: LOG.error("Exception in Refrsh %s", str(e))
[ "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", ...
Periodic refresh of vNIC events to VDP. VDP daemon itself has keepalives. This is needed on top of it to keep Orchestrator like OpenStack, VDP daemon and the physical switch in sync.
[ "Periodic", "refresh", "of", "vNIC", "events", "to", "VDP", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/vdp/lldpad.py#L140-L204
train
37,851
openstack/networking-cisco
networking_cisco/apps/saf/agent/vdp/lldpad.py
LldpadDriver.store_oui
def store_oui(self, port_uuid, oui_type, oui_data): """Function for storing the OUI. param uuid: UUID of the vNIC param oui_type: OUI ID param oui_data: OUI Opaque Data """ self.oui_vif_map[port_uuid] = {'oui_id': oui_type, 'oui_data': oui_data}
python
def store_oui(self, port_uuid, oui_type, oui_data): """Function for storing the OUI. param uuid: UUID of the vNIC param oui_type: OUI ID param oui_data: OUI Opaque Data """ self.oui_vif_map[port_uuid] = {'oui_id': oui_type, 'oui_data': oui_data}
[ "def", "store_oui", "(", "self", ",", "port_uuid", ",", "oui_type", ",", "oui_data", ")", ":", "self", ".", "oui_vif_map", "[", "port_uuid", "]", "=", "{", "'oui_id'", ":", "oui_type", ",", "'oui_data'", ":", "oui_data", "}" ]
Function for storing the OUI. param uuid: UUID of the vNIC param oui_type: OUI ID param oui_data: OUI Opaque Data
[ "Function", "for", "storing", "the", "OUI", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/vdp/lldpad.py#L216-L224
train
37,852
openstack/networking-cisco
networking_cisco/apps/saf/agent/vdp/lldpad.py
LldpadDriver.clear_oui
def clear_oui(self, port_uuid): """Clears the OUI specific info. :param uuid: vNIC UUID Currently only one OUI per VSI fixme(padkrish) """ if port_uuid in self.oui_vif_map: del self.oui_vif_map[port_uuid] else: LOG.debug("OUI does not exist")
python
def clear_oui(self, port_uuid): """Clears the OUI specific info. :param uuid: vNIC UUID Currently only one OUI per VSI fixme(padkrish) """ if port_uuid in self.oui_vif_map: del self.oui_vif_map[port_uuid] else: LOG.debug("OUI does not exist")
[ "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\"", ")" ]
Clears the OUI specific info. :param uuid: vNIC UUID Currently only one OUI per VSI fixme(padkrish)
[ "Clears", "the", "OUI", "specific", "info", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/vdp/lldpad.py#L276-L286
train
37,853
openstack/networking-cisco
networking_cisco/apps/saf/agent/vdp/lldpad.py
LldpadDriver.gen_cisco_vdp_oui
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 oui_list.append(oui_name_str) ip_addr = oui_data.get('ip_addr') if ip_addr is not None: oui_str = "oui=%s," % oui_id ip_addr_str = oui_str + "ipv4_addr=" + ip_addr oui_list.append(ip_addr_str) vm_uuid = oui_data.get('vm_uuid') if vm_uuid is not None: oui_str = "oui=%s," % oui_id vm_uuid_str = oui_str + "vm_uuid=" + vm_uuid oui_list.append(vm_uuid_str) return oui_list
python
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 oui_list.append(oui_name_str) ip_addr = oui_data.get('ip_addr') if ip_addr is not None: oui_str = "oui=%s," % oui_id ip_addr_str = oui_str + "ipv4_addr=" + ip_addr oui_list.append(ip_addr_str) vm_uuid = oui_data.get('vm_uuid') if vm_uuid is not None: oui_str = "oui=%s," % oui_id vm_uuid_str = oui_str + "vm_uuid=" + vm_uuid oui_list.append(vm_uuid_str) return oui_list
[ "def", "gen_cisco_vdp_oui", "(", "self", ",", "oui_id", ",", "oui_data", ")", ":", "oui_list", "=", "[", "]", "vm_name", "=", "oui_data", ".", "get", "(", "'vm_name'", ")", "if", "vm_name", "is", "not", "None", ":", "oui_str", "=", "\"oui=%s,\"", "%", ...
Cisco specific handler for constructing OUI arguments.
[ "Cisco", "specific", "handler", "for", "constructing", "OUI", "arguments", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/vdp/lldpad.py#L302-L320
train
37,854
openstack/networking-cisco
networking_cisco/apps/saf/agent/vdp/lldpad.py
LldpadDriver.gen_oui_str
def gen_oui_str(self, oui_list): """Generate the OUI string for vdptool. """ oui_str = [] for oui in oui_list: oui_str.append('-c') oui_str.append(oui) return oui_str
python
def gen_oui_str(self, oui_list): """Generate the OUI string for vdptool. """ oui_str = [] for oui in oui_list: oui_str.append('-c') oui_str.append(oui) return oui_str
[ "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" ]
Generate the OUI string for vdptool.
[ "Generate", "the", "OUI", "string", "for", "vdptool", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/vdp/lldpad.py#L322-L328
train
37,855
openstack/networking-cisco
networking_cisco/apps/saf/agent/vdp/lldpad.py
LldpadDriver.construct_vdp_dict
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/802.1bg.html VDP Section for more detailed information :param mode: Associate or De-associate :param mgrid: MGR ID :param typeid: Type ID :param typeid_ver: Version of the Type ID :param vsiid_frmt: Format of the following VSI argument :param vsiid: VSI value :param filter_frmt: Filter Format :param gid: Group ID the vNIC belongs to :param mac: MAC Address of the vNIC :param vlan: VLAN of the vNIC :param oui_id: OUI Type :param oui_data: OUI Data :return vdp_keyword_str: Dictionary of VDP arguments and values """ vdp_keyword_str = {} if mgrid is None: mgrid = self.vdp_opts.get('mgrid') mgrid_str = "mgrid2=%s" % mgrid if typeid is None: typeid = self.vdp_opts.get('typeid') typeid_str = "typeid=%s" % typeid if typeid_ver is None: typeid_ver = self.vdp_opts.get('typeidver') typeid_ver_str = "typeidver=%s" % typeid_ver if int(vsiid_frmt) == int(self.vdp_opts.get('vsiidfrmt')): vsiid_str = "uuid=%s" % vsiid else: # Only format supported for now LOG.error("Unsupported VSIID Format1") return vdp_keyword_str if vlan == constants.INVALID_VLAN: vlan = 0 if int(filter_frmt) == vdp_const.VDP_FILTER_GIDMACVID: if not mac or gid == 0: LOG.error("Incorrect Filter Format Specified") return vdp_keyword_str else: f = "filter=%s-%s-%s" filter_str = f % (vlan, mac, gid) elif int(filter_frmt) == vdp_const.VDP_FILTER_GIDVID: if gid == 0: LOG.error("NULL GID Specified") return vdp_keyword_str else: filter_str = "filter=" + '%d' % vlan + "--" + '%ld' % gid elif int(filter_frmt) == vdp_const.VDP_FILTER_MACVID: if not mac: LOG.error("NULL MAC Specified") return vdp_keyword_str else: filter_str = "filter=" + '%d' % vlan + "-" + mac elif int(filter_frmt) == vdp_const.VDP_FILTER_VID: filter_str = "filter=" + '%d' % vlan else: LOG.error("Incorrect Filter Format Specified") return vdp_keyword_str oui_list = [] if oui_id is not None and oui_data is not None: if oui_id is 'cisco': oui_list = self.gen_cisco_vdp_oui(oui_id, oui_data) mode_str = "mode=" + mode vdp_keyword_str = dict(mode=mode_str, mgrid=mgrid_str, typeid=typeid_str, typeid_ver=typeid_ver_str, vsiid=vsiid_str, filter=filter_str, oui_list=oui_list) return vdp_keyword_str
python
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/802.1bg.html VDP Section for more detailed information :param mode: Associate or De-associate :param mgrid: MGR ID :param typeid: Type ID :param typeid_ver: Version of the Type ID :param vsiid_frmt: Format of the following VSI argument :param vsiid: VSI value :param filter_frmt: Filter Format :param gid: Group ID the vNIC belongs to :param mac: MAC Address of the vNIC :param vlan: VLAN of the vNIC :param oui_id: OUI Type :param oui_data: OUI Data :return vdp_keyword_str: Dictionary of VDP arguments and values """ vdp_keyword_str = {} if mgrid is None: mgrid = self.vdp_opts.get('mgrid') mgrid_str = "mgrid2=%s" % mgrid if typeid is None: typeid = self.vdp_opts.get('typeid') typeid_str = "typeid=%s" % typeid if typeid_ver is None: typeid_ver = self.vdp_opts.get('typeidver') typeid_ver_str = "typeidver=%s" % typeid_ver if int(vsiid_frmt) == int(self.vdp_opts.get('vsiidfrmt')): vsiid_str = "uuid=%s" % vsiid else: # Only format supported for now LOG.error("Unsupported VSIID Format1") return vdp_keyword_str if vlan == constants.INVALID_VLAN: vlan = 0 if int(filter_frmt) == vdp_const.VDP_FILTER_GIDMACVID: if not mac or gid == 0: LOG.error("Incorrect Filter Format Specified") return vdp_keyword_str else: f = "filter=%s-%s-%s" filter_str = f % (vlan, mac, gid) elif int(filter_frmt) == vdp_const.VDP_FILTER_GIDVID: if gid == 0: LOG.error("NULL GID Specified") return vdp_keyword_str else: filter_str = "filter=" + '%d' % vlan + "--" + '%ld' % gid elif int(filter_frmt) == vdp_const.VDP_FILTER_MACVID: if not mac: LOG.error("NULL MAC Specified") return vdp_keyword_str else: filter_str = "filter=" + '%d' % vlan + "-" + mac elif int(filter_frmt) == vdp_const.VDP_FILTER_VID: filter_str = "filter=" + '%d' % vlan else: LOG.error("Incorrect Filter Format Specified") return vdp_keyword_str oui_list = [] if oui_id is not None and oui_data is not None: if oui_id is 'cisco': oui_list = self.gen_cisco_vdp_oui(oui_id, oui_data) mode_str = "mode=" + mode vdp_keyword_str = dict(mode=mode_str, mgrid=mgrid_str, typeid=typeid_str, typeid_ver=typeid_ver_str, vsiid=vsiid_str, filter=filter_str, oui_list=oui_list) return vdp_keyword_str
[ "def", "construct_vdp_dict", "(", "self", ",", "mode", ",", "mgrid", ",", "typeid", ",", "typeid_ver", ",", "vsiid_frmt", ",", "vsiid", ",", "filter_frmt", ",", "gid", ",", "mac", ",", "vlan", ",", "oui_id", ",", "oui_data", ")", ":", "vdp_keyword_str", ...
Constructs the VDP Message. Please refer http://www.ieee802.org/1/pages/802.1bg.html VDP Section for more detailed information :param mode: Associate or De-associate :param mgrid: MGR ID :param typeid: Type ID :param typeid_ver: Version of the Type ID :param vsiid_frmt: Format of the following VSI argument :param vsiid: VSI value :param filter_frmt: Filter Format :param gid: Group ID the vNIC belongs to :param mac: MAC Address of the vNIC :param vlan: VLAN of the vNIC :param oui_id: OUI Type :param oui_data: OUI Data :return vdp_keyword_str: Dictionary of VDP arguments and values
[ "Constructs", "the", "VDP", "Message", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/vdp/lldpad.py#L330-L402
train
37,856
openstack/networking-cisco
networking_cisco/apps/saf/agent/vdp/lldpad.py
LldpadDriver.send_vdp_query_msg
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 Section for more detailed information :param mode: Associate or De-associate :param mgrid: MGR ID :param typeid: Type ID :param typeid_ver: Version of the Type ID :param vsiid_frmt: Format of the following VSI argument :param vsiid: VSI value :param filter_frmt: Filter Format :param gid: Group ID the vNIC belongs to :param mac: MAC Address of the vNIC :param vlan: VLAN of the vNIC :param oui_id: OUI Type :param oui_data: OUI Data :param sw_resp: Flag indicating if response is required from the daemon :return reply: Reply from vdptool """ if not self.is_ncb: LOG.error("EVB cannot be set on NB") return vdp_key_str = self.construct_vdp_dict(mode, mgrid, typeid, typeid_ver, vsiid_frmt, vsiid, filter_frmt, gid, mac, vlan, None, None) if len(vdp_key_str) == 0: LOG.error("NULL List") return reply = self.run_vdptool(["-t", "-i", self.port_name, "-R", "-V", mode, "-c", vdp_key_str['mode'], "-c", vdp_key_str['mgrid'], "-c", vdp_key_str['typeid'], "-c", vdp_key_str['typeid_ver'], "-c", vdp_key_str['vsiid']]) return reply
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 Section for more detailed information :param mode: Associate or De-associate :param mgrid: MGR ID :param typeid: Type ID :param typeid_ver: Version of the Type ID :param vsiid_frmt: Format of the following VSI argument :param vsiid: VSI value :param filter_frmt: Filter Format :param gid: Group ID the vNIC belongs to :param mac: MAC Address of the vNIC :param vlan: VLAN of the vNIC :param oui_id: OUI Type :param oui_data: OUI Data :param sw_resp: Flag indicating if response is required from the daemon :return reply: Reply from vdptool """ if not self.is_ncb: LOG.error("EVB cannot be set on NB") return vdp_key_str = self.construct_vdp_dict(mode, mgrid, typeid, typeid_ver, vsiid_frmt, vsiid, filter_frmt, gid, mac, vlan, None, None) if len(vdp_key_str) == 0: LOG.error("NULL List") return reply = self.run_vdptool(["-t", "-i", self.port_name, "-R", "-V", mode, "-c", vdp_key_str['mode'], "-c", vdp_key_str['mgrid'], "-c", vdp_key_str['typeid'], "-c", vdp_key_str['typeid_ver'], "-c", vdp_key_str['vsiid']]) return reply
[ "def", "send_vdp_query_msg", "(", "self", ",", "mode", ",", "mgrid", ",", "typeid", ",", "typeid_ver", ",", "vsiid_frmt", ",", "vsiid", ",", "filter_frmt", ",", "gid", ",", "mac", ",", "vlan", ",", "oui_id", ",", "oui_data", ")", ":", "if", "not", "sel...
Constructs and Sends the VDP Query Message. Please refer http://www.ieee802.org/1/pages/802.1bg.html VDP Section for more detailed information :param mode: Associate or De-associate :param mgrid: MGR ID :param typeid: Type ID :param typeid_ver: Version of the Type ID :param vsiid_frmt: Format of the following VSI argument :param vsiid: VSI value :param filter_frmt: Filter Format :param gid: Group ID the vNIC belongs to :param mac: MAC Address of the vNIC :param vlan: VLAN of the vNIC :param oui_id: OUI Type :param oui_data: OUI Data :param sw_resp: Flag indicating if response is required from the daemon :return reply: Reply from vdptool
[ "Constructs", "and", "Sends", "the", "VDP", "Query", "Message", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/vdp/lldpad.py#L404-L442
train
37,857
openstack/networking-cisco
networking_cisco/apps/saf/agent/vdp/lldpad.py
LldpadDriver.send_vdp_msg
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 detailed information :param mode: Associate or De-associate :param mgrid: MGR ID :param typeid: Type ID :param typeid_ver: Version of the Type ID :param vsiid_frmt: Format of the following VSI argument :param vsiid: VSI value :param filter_frmt: Filter Format :param gid: Group ID the vNIC belongs to :param mac: MAC Address of the vNIC :param vlan: VLAN of the vNIC :param oui_id: OUI Type :param oui_data: OUI Data :param sw_resp: Flag indicating if response is required from the daemon :return reply: Reply from vdptool """ if not self.is_ncb: LOG.error("EVB cannot be set on NB") return vdp_key_str = self.construct_vdp_dict(mode, mgrid, typeid, typeid_ver, vsiid_frmt, vsiid, filter_frmt, gid, mac, vlan, oui_id, oui_data) if len(vdp_key_str) == 0: LOG.error("NULL List") return oui_cmd_str = self.gen_oui_str(vdp_key_str['oui_list']) if sw_resp: # If filter is not VID and if VLAN is 0, Query for the TLV first, # if found VDP will return the VLAN. Add support for this once # vdptool has the support for querying exact VSI filters # fixme(padkrish) reply = self.run_vdptool(["-T", "-i", self.port_name, "-W", "-V", mode, "-c", vdp_key_str['mode'], "-c", vdp_key_str['mgrid'], "-c", vdp_key_str['typeid'], "-c", vdp_key_str['typeid_ver'], "-c", vdp_key_str['vsiid'], "-c", "hints=none", "-c", vdp_key_str['filter']], oui_args=oui_cmd_str) else: reply = self.run_vdptool(["-T", "-i", self.port_name, "-V", mode, "-c", vdp_key_str['mode'], "-c", vdp_key_str['mgrid'], "-c", vdp_key_str['typeid'], "-c", vdp_key_str['typeid_ver'], "-c", vdp_key_str['vsiid'], "-c", "hints=none", "-c", vdp_key_str['filter']], oui_args=oui_cmd_str) return reply
python
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 detailed information :param mode: Associate or De-associate :param mgrid: MGR ID :param typeid: Type ID :param typeid_ver: Version of the Type ID :param vsiid_frmt: Format of the following VSI argument :param vsiid: VSI value :param filter_frmt: Filter Format :param gid: Group ID the vNIC belongs to :param mac: MAC Address of the vNIC :param vlan: VLAN of the vNIC :param oui_id: OUI Type :param oui_data: OUI Data :param sw_resp: Flag indicating if response is required from the daemon :return reply: Reply from vdptool """ if not self.is_ncb: LOG.error("EVB cannot be set on NB") return vdp_key_str = self.construct_vdp_dict(mode, mgrid, typeid, typeid_ver, vsiid_frmt, vsiid, filter_frmt, gid, mac, vlan, oui_id, oui_data) if len(vdp_key_str) == 0: LOG.error("NULL List") return oui_cmd_str = self.gen_oui_str(vdp_key_str['oui_list']) if sw_resp: # If filter is not VID and if VLAN is 0, Query for the TLV first, # if found VDP will return the VLAN. Add support for this once # vdptool has the support for querying exact VSI filters # fixme(padkrish) reply = self.run_vdptool(["-T", "-i", self.port_name, "-W", "-V", mode, "-c", vdp_key_str['mode'], "-c", vdp_key_str['mgrid'], "-c", vdp_key_str['typeid'], "-c", vdp_key_str['typeid_ver'], "-c", vdp_key_str['vsiid'], "-c", "hints=none", "-c", vdp_key_str['filter']], oui_args=oui_cmd_str) else: reply = self.run_vdptool(["-T", "-i", self.port_name, "-V", mode, "-c", vdp_key_str['mode'], "-c", vdp_key_str['mgrid'], "-c", vdp_key_str['typeid'], "-c", vdp_key_str['typeid_ver'], "-c", vdp_key_str['vsiid'], "-c", "hints=none", "-c", vdp_key_str['filter']], oui_args=oui_cmd_str) return reply
[ "def", "send_vdp_msg", "(", "self", ",", "mode", ",", "mgrid", ",", "typeid", ",", "typeid_ver", ",", "vsiid_frmt", ",", "vsiid", ",", "filter_frmt", ",", "gid", ",", "mac", ",", "vlan", ",", "oui_id", ",", "oui_data", ",", "sw_resp", ")", ":", "if", ...
Constructs and Sends the VDP Message. Please refer http://www.ieee802.org/1/pages/802.1bg.html VDP Section for more detailed information :param mode: Associate or De-associate :param mgrid: MGR ID :param typeid: Type ID :param typeid_ver: Version of the Type ID :param vsiid_frmt: Format of the following VSI argument :param vsiid: VSI value :param filter_frmt: Filter Format :param gid: Group ID the vNIC belongs to :param mac: MAC Address of the vNIC :param vlan: VLAN of the vNIC :param oui_id: OUI Type :param oui_data: OUI Data :param sw_resp: Flag indicating if response is required from the daemon :return reply: Reply from vdptool
[ "Constructs", "and", "Sends", "the", "VDP", "Message", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/vdp/lldpad.py#L444-L502
train
37,858
openstack/networking-cisco
networking_cisco/apps/saf/agent/vdp/lldpad.py
LldpadDriver.crosscheck_query_vsiid_mac
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 % ( vsiid, vsiid_reply) LOG.error("%s", fail_reason) return False, fail_reason mac_reply = reply.partition("filter")[2].split('-')[1] if mac != mac_reply: fail_reason = vdp_const.mac_mismatch_failure_reason % ( mac, mac_reply) LOG.error("%s", fail_reason) return False, fail_reason return True, None
python
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 % ( vsiid, vsiid_reply) LOG.error("%s", fail_reason) return False, fail_reason mac_reply = reply.partition("filter")[2].split('-')[1] if mac != mac_reply: fail_reason = vdp_const.mac_mismatch_failure_reason % ( mac, mac_reply) LOG.error("%s", fail_reason) return False, fail_reason return True, None
[ "def", "crosscheck_query_vsiid_mac", "(", "self", ",", "reply", ",", "vsiid", ",", "mac", ")", ":", "vsiid_reply", "=", "reply", ".", "partition", "(", "\"uuid\"", ")", "[", "2", "]", ".", "split", "(", ")", "[", "0", "]", "[", "4", ":", "]", "if",...
Cross Check the reply against the input vsiid,mac for get query.
[ "Cross", "Check", "the", "reply", "against", "the", "input", "vsiid", "mac", "for", "get", "query", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/vdp/lldpad.py#L520-L534
train
37,859
openstack/networking-cisco
networking_cisco/apps/saf/agent/vdp/lldpad.py
LldpadDriver.get_vdp_failure_reason
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) except Exception: fail_reason = vdp_const.retrieve_failure_reason % (reply) return fail_reason
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) except Exception: fail_reason = vdp_const.retrieve_failure_reason % (reply) return fail_reason
[ "def", "get_vdp_failure_reason", "(", "self", ",", "reply", ")", ":", "try", ":", "fail_reason", "=", "reply", ".", "partition", "(", "\"filter\"", ")", "[", "0", "]", ".", "replace", "(", "'\\t'", ",", "''", ")", ".", "split", "(", "'\\n'", ")", "["...
Parse the failure reason from VDP.
[ "Parse", "the", "failure", "reason", "from", "VDP", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/vdp/lldpad.py#L536-L545
train
37,860
openstack/networking-cisco
networking_cisco/apps/saf/agent/vdp/lldpad.py
LldpadDriver.check_filter_validity
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.error("%s", fail_reason) return False, fail_reason if f_ind != l_ind: # Currently not supported if reply contains a filter keyword fail_reason = vdp_const.multiple_filter_failure_reason % (reply) LOG.error("%s", fail_reason) return False, fail_reason return True, None
python
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.error("%s", fail_reason) return False, fail_reason if f_ind != l_ind: # Currently not supported if reply contains a filter keyword fail_reason = vdp_const.multiple_filter_failure_reason % (reply) LOG.error("%s", fail_reason) return False, fail_reason return True, None
[ "def", "check_filter_validity", "(", "self", ",", "reply", ",", "filter_str", ")", ":", "try", ":", "f_ind", "=", "reply", ".", "index", "(", "filter_str", ")", "l_ind", "=", "reply", ".", "rindex", "(", "filter_str", ")", "except", "Exception", ":", "fa...
Check for the validify of the filter.
[ "Check", "for", "the", "validify", "of", "the", "filter", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/vdp/lldpad.py#L547-L561
train
37,861
openstack/networking-cisco
networking_cisco/apps/saf/agent/vdp/lldpad.py
LldpadDriver.get_vlan_from_associate_reply
def get_vlan_from_associate_reply(self, reply, vsiid, mac): """Parse the associate reply from VDP daemon to get the VLAN value. """ try: verify_flag, fail_reason = self.crosscheck_reply_vsiid_mac( reply, vsiid, mac) if not verify_flag: return constants.INVALID_VLAN, fail_reason mode_str = reply.partition("mode = ")[2].split()[0] if mode_str != "assoc": fail_reason = self.get_vdp_failure_reason(reply) return constants.INVALID_VLAN, fail_reason except Exception: fail_reason = vdp_const.mode_failure_reason % (reply) LOG.error("%s", fail_reason) return constants.INVALID_VLAN, fail_reason check_filter, fail_reason = self.check_filter_validity( reply, "filter = ") if not check_filter: return constants.INVALID_VLAN, fail_reason try: vlan_val = reply.partition("filter = ")[2].split('-')[0] vlan = int(vlan_val) except ValueError: fail_reason = vdp_const.format_failure_reason % (reply) LOG.error("%s", fail_reason) return constants.INVALID_VLAN, fail_reason return vlan, None
python
def get_vlan_from_associate_reply(self, reply, vsiid, mac): """Parse the associate reply from VDP daemon to get the VLAN value. """ try: verify_flag, fail_reason = self.crosscheck_reply_vsiid_mac( reply, vsiid, mac) if not verify_flag: return constants.INVALID_VLAN, fail_reason mode_str = reply.partition("mode = ")[2].split()[0] if mode_str != "assoc": fail_reason = self.get_vdp_failure_reason(reply) return constants.INVALID_VLAN, fail_reason except Exception: fail_reason = vdp_const.mode_failure_reason % (reply) LOG.error("%s", fail_reason) return constants.INVALID_VLAN, fail_reason check_filter, fail_reason = self.check_filter_validity( reply, "filter = ") if not check_filter: return constants.INVALID_VLAN, fail_reason try: vlan_val = reply.partition("filter = ")[2].split('-')[0] vlan = int(vlan_val) except ValueError: fail_reason = vdp_const.format_failure_reason % (reply) LOG.error("%s", fail_reason) return constants.INVALID_VLAN, fail_reason return vlan, None
[ "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", ...
Parse the associate reply from VDP daemon to get the VLAN value.
[ "Parse", "the", "associate", "reply", "from", "VDP", "daemon", "to", "get", "the", "VLAN", "value", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/vdp/lldpad.py#L563-L589
train
37,862
openstack/networking-cisco
networking_cisco/apps/saf/agent/vdp/lldpad.py
LldpadDriver.check_hints
def check_hints(self, reply): """Parse the hints to check for errors. """ 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_reason) return False, fail_reason if f_ind != l_ind: # Currently not supported if reply contains a filter keyword fail_reason = vdp_const.multiple_hints_failure_reason % (reply) LOG.error("%s", fail_reason) return False, fail_reason try: hints_compl = reply.partition("hints")[2] hints_val = reply.partition("hints")[2][0:4] len_hints = int(hints_val) hints_val = hints_compl[4:4 + len_hints] hints = int(hints_val) if hints != 0: fail_reason = vdp_const.nonzero_hints_failure % (hints) return False, fail_reason except ValueError: fail_reason = vdp_const.format_failure_reason % (reply) LOG.error("%s", fail_reason) return False, fail_reason return True, None
python
def check_hints(self, reply): """Parse the hints to check for errors. """ 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_reason) return False, fail_reason if f_ind != l_ind: # Currently not supported if reply contains a filter keyword fail_reason = vdp_const.multiple_hints_failure_reason % (reply) LOG.error("%s", fail_reason) return False, fail_reason try: hints_compl = reply.partition("hints")[2] hints_val = reply.partition("hints")[2][0:4] len_hints = int(hints_val) hints_val = hints_compl[4:4 + len_hints] hints = int(hints_val) if hints != 0: fail_reason = vdp_const.nonzero_hints_failure % (hints) return False, fail_reason except ValueError: fail_reason = vdp_const.format_failure_reason % (reply) LOG.error("%s", fail_reason) return False, fail_reason return True, None
[ "def", "check_hints", "(", "self", ",", "reply", ")", ":", "try", ":", "f_ind", "=", "reply", ".", "index", "(", "\"hints\"", ")", "l_ind", "=", "reply", ".", "rindex", "(", "\"hints\"", ")", "except", "Exception", ":", "fail_reason", "=", "vdp_const", ...
Parse the hints to check for errors.
[ "Parse", "the", "hints", "to", "check", "for", "errors", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/vdp/lldpad.py#L591-L618
train
37,863
openstack/networking-cisco
networking_cisco/apps/saf/agent/vdp/lldpad.py
LldpadDriver.get_vlan_from_query_reply
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_reason check_filter, fail_reason = self.check_filter_validity(reply, "filter") if not check_filter: return constants.INVALID_VLAN, fail_reason try: verify_flag, fail_reason = self.crosscheck_query_vsiid_mac( reply, vsiid, mac) if not verify_flag: return constants.INVALID_VLAN, fail_reason filter_val = reply.partition("filter")[2] len_fil = len(filter_val) vlan_val = filter_val[4:len_fil].split('-')[0] vlan = int(vlan_val) except ValueError: fail_reason = vdp_const.format_failure_reason % (reply) LOG.error("%s", fail_reason) return constants.INVALID_VLAN, fail_reason return vlan, None
python
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_reason check_filter, fail_reason = self.check_filter_validity(reply, "filter") if not check_filter: return constants.INVALID_VLAN, fail_reason try: verify_flag, fail_reason = self.crosscheck_query_vsiid_mac( reply, vsiid, mac) if not verify_flag: return constants.INVALID_VLAN, fail_reason filter_val = reply.partition("filter")[2] len_fil = len(filter_val) vlan_val = filter_val[4:len_fil].split('-')[0] vlan = int(vlan_val) except ValueError: fail_reason = vdp_const.format_failure_reason % (reply) LOG.error("%s", fail_reason) return constants.INVALID_VLAN, fail_reason return vlan, None
[ "def", "get_vlan_from_query_reply", "(", "self", ",", "reply", ",", "vsiid", ",", "mac", ")", ":", "hints_ret", ",", "fail_reason", "=", "self", ".", "check_hints", "(", "reply", ")", "if", "not", "hints_ret", ":", "LOG", ".", "error", "(", "\"Incorrect hi...
Parse the query reply from VDP daemon to get the VLAN value.
[ "Parse", "the", "query", "reply", "from", "VDP", "daemon", "to", "get", "the", "VLAN", "value", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/vdp/lldpad.py#L620-L642
train
37,864
openstack/networking-cisco
networking_cisco/apps/saf/agent/vdp/lldpad.py
LldpadDriver.send_vdp_assoc
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 Associate Message. Please refer http://www.ieee802.org/1/pages/802.1bg.html VDP Section for more detailed information :param vsiid: VSI value, Only UUID supported for now :param mgrid: MGR ID :param typeid: Type ID :param typeid_ver: Version of the Type ID :param vsiid_frmt: Format of the following VSI argument :param filter_frmt: Filter Format. Only <GID,MAC,VID> supported for now :param gid: Group ID the vNIC belongs to :param mac: MAC Address of the vNIC :param vlan: VLAN of the vNIC :param oui_id: OUI Type :param oui_data: OUI Data :param sw_resp: Flag indicating if response is required from the daemon :return vlan: VLAN value returned by vdptool which in turn is given : by Switch """ if sw_resp and filter_frmt == vdp_const.VDP_FILTER_GIDMACVID: reply = self.send_vdp_query_msg("assoc", mgrid, typeid, typeid_ver, vsiid_frmt, vsiid, filter_frmt, gid, mac, vlan, oui_id, oui_data) vlan_resp, fail_reason = self.get_vlan_from_query_reply( reply, vsiid, mac) if vlan_resp != constants.INVALID_VLAN: return vlan_resp, fail_reason reply = self.send_vdp_msg("assoc", mgrid, typeid, typeid_ver, vsiid_frmt, vsiid, filter_frmt, gid, mac, vlan, oui_id, oui_data, sw_resp) if sw_resp: vlan, fail_reason = self.get_vlan_from_associate_reply( reply, vsiid, mac) return vlan, fail_reason return None, None
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 Associate Message. Please refer http://www.ieee802.org/1/pages/802.1bg.html VDP Section for more detailed information :param vsiid: VSI value, Only UUID supported for now :param mgrid: MGR ID :param typeid: Type ID :param typeid_ver: Version of the Type ID :param vsiid_frmt: Format of the following VSI argument :param filter_frmt: Filter Format. Only <GID,MAC,VID> supported for now :param gid: Group ID the vNIC belongs to :param mac: MAC Address of the vNIC :param vlan: VLAN of the vNIC :param oui_id: OUI Type :param oui_data: OUI Data :param sw_resp: Flag indicating if response is required from the daemon :return vlan: VLAN value returned by vdptool which in turn is given : by Switch """ if sw_resp and filter_frmt == vdp_const.VDP_FILTER_GIDMACVID: reply = self.send_vdp_query_msg("assoc", mgrid, typeid, typeid_ver, vsiid_frmt, vsiid, filter_frmt, gid, mac, vlan, oui_id, oui_data) vlan_resp, fail_reason = self.get_vlan_from_query_reply( reply, vsiid, mac) if vlan_resp != constants.INVALID_VLAN: return vlan_resp, fail_reason reply = self.send_vdp_msg("assoc", mgrid, typeid, typeid_ver, vsiid_frmt, vsiid, filter_frmt, gid, mac, vlan, oui_id, oui_data, sw_resp) if sw_resp: vlan, fail_reason = self.get_vlan_from_associate_reply( reply, vsiid, mac) return vlan, fail_reason return None, None
[ "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", ".",...
Sends the VDP Associate Message. Please refer http://www.ieee802.org/1/pages/802.1bg.html VDP Section for more detailed information :param vsiid: VSI value, Only UUID supported for now :param mgrid: MGR ID :param typeid: Type ID :param typeid_ver: Version of the Type ID :param vsiid_frmt: Format of the following VSI argument :param filter_frmt: Filter Format. Only <GID,MAC,VID> supported for now :param gid: Group ID the vNIC belongs to :param mac: MAC Address of the vNIC :param vlan: VLAN of the vNIC :param oui_id: OUI Type :param oui_data: OUI Data :param sw_resp: Flag indicating if response is required from the daemon :return vlan: VLAN value returned by vdptool which in turn is given : by Switch
[ "Sends", "the", "VDP", "Associate", "Message", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/vdp/lldpad.py#L644-L683
train
37,865
openstack/networking-cisco
networking_cisco/apps/saf/agent/vdp/lldpad.py
LldpadDriver.send_vdp_vnic_up
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, gid=0, mac="", vlan=0, oui=None, new_network=False, vsw_cb_fn=None, vsw_cb_data=None): """Interface function to apps, called for a vNIC UP. This currently sends an VDP associate message. Please refer http://www.ieee802.org/1/pages/802.1bg.html VDP Section for more detailed information :param uuid: uuid of the vNIC :param vsiid: VSI value, Only UUID supported for now :param mgrid: MGR ID :param typeid: Type ID :param typeid_ver: Version of the Type ID :param vsiid_frmt: Format of the following VSI argument :param filter_frmt: Filter Format. Only <GID,MAC,VID> supported for now :param gid: Group ID the vNIC belongs to :param mac: MAC Address of the vNIC :param vlan: VLAN of the vNIC :param oui_id: OUI Type :param oui_data: OUI Data :param sw_resp: Flag indicating if response is required from the daemon :return reply: VLAN reply from vdptool """ if oui is None: oui = {} oui_id = None oui_data = None if 'oui_id' in oui: oui_id = oui['oui_id'] oui_data = oui reply, fail_reason = self.send_vdp_assoc( vsiid=vsiid, mgrid=mgrid, typeid=typeid, typeid_ver=typeid_ver, vsiid_frmt=vsiid_frmt, filter_frmt=filter_frmt, gid=gid, mac=mac, vlan=vlan, oui_id=oui_id, oui_data=oui_data, sw_resp=new_network) self.store_vdp_vsi(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, fail_reason) return reply, fail_reason
python
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, gid=0, mac="", vlan=0, oui=None, new_network=False, vsw_cb_fn=None, vsw_cb_data=None): """Interface function to apps, called for a vNIC UP. This currently sends an VDP associate message. Please refer http://www.ieee802.org/1/pages/802.1bg.html VDP Section for more detailed information :param uuid: uuid of the vNIC :param vsiid: VSI value, Only UUID supported for now :param mgrid: MGR ID :param typeid: Type ID :param typeid_ver: Version of the Type ID :param vsiid_frmt: Format of the following VSI argument :param filter_frmt: Filter Format. Only <GID,MAC,VID> supported for now :param gid: Group ID the vNIC belongs to :param mac: MAC Address of the vNIC :param vlan: VLAN of the vNIC :param oui_id: OUI Type :param oui_data: OUI Data :param sw_resp: Flag indicating if response is required from the daemon :return reply: VLAN reply from vdptool """ if oui is None: oui = {} oui_id = None oui_data = None if 'oui_id' in oui: oui_id = oui['oui_id'] oui_data = oui reply, fail_reason = self.send_vdp_assoc( vsiid=vsiid, mgrid=mgrid, typeid=typeid, typeid_ver=typeid_ver, vsiid_frmt=vsiid_frmt, filter_frmt=filter_frmt, gid=gid, mac=mac, vlan=vlan, oui_id=oui_id, oui_data=oui_data, sw_resp=new_network) self.store_vdp_vsi(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, fail_reason) return reply, fail_reason
[ "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", ",", "f...
Interface function to apps, called for a vNIC UP. This currently sends an VDP associate message. Please refer http://www.ieee802.org/1/pages/802.1bg.html VDP Section for more detailed information :param uuid: uuid of the vNIC :param vsiid: VSI value, Only UUID supported for now :param mgrid: MGR ID :param typeid: Type ID :param typeid_ver: Version of the Type ID :param vsiid_frmt: Format of the following VSI argument :param filter_frmt: Filter Format. Only <GID,MAC,VID> supported for now :param gid: Group ID the vNIC belongs to :param mac: MAC Address of the vNIC :param vlan: VLAN of the vNIC :param oui_id: OUI Type :param oui_data: OUI Data :param sw_resp: Flag indicating if response is required from the daemon :return reply: VLAN reply from vdptool
[ "Interface", "function", "to", "apps", "called", "for", "a", "vNIC", "UP", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/vdp/lldpad.py#L729-L770
train
37,866
openstack/networking-cisco
networking_cisco/apps/saf/agent/vdp/lldpad.py
LldpadDriver.send_vdp_vnic_down
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, gid=0, mac="", vlan=0, oui=""): """Interface function to apps, called for a vNIC DOWN. This currently sends an VDP dis-associate message. Please refer http://www.ieee802.org/1/pages/802.1bg.html VDP Section for more detailed information :param uuid: uuid of the vNIC :param vsiid: VSI value, Only UUID supported for now :param mgrid: MGR ID :param typeid: Type ID :param typeid_ver: Version of the Type ID :param vsiid_frmt: Format of the following VSI argument :param filter_frmt: Filter Format. Only <GID,MAC,VID> supported for now :param gid: Group ID the vNIC belongs to :param mac: MAC Address of the vNIC :param vlan: VLAN of the vNIC :param oui_id: OUI Type :param oui_data: OUI Data :param sw_resp: Flag indicating if response is required from the daemon """ # Correct non-zero VLAN needs to be specified try: with self.mutex_lock: self.send_vdp_deassoc(vsiid=vsiid, mgrid=mgrid, typeid=typeid, typeid_ver=typeid_ver, vsiid_frmt=vsiid_frmt, filter_frmt=filter_frmt, gid=gid, mac=mac, vlan=vlan) self.clear_vdp_vsi(port_uuid) except Exception as e: LOG.error("VNIC Down exception %s", e)
python
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, gid=0, mac="", vlan=0, oui=""): """Interface function to apps, called for a vNIC DOWN. This currently sends an VDP dis-associate message. Please refer http://www.ieee802.org/1/pages/802.1bg.html VDP Section for more detailed information :param uuid: uuid of the vNIC :param vsiid: VSI value, Only UUID supported for now :param mgrid: MGR ID :param typeid: Type ID :param typeid_ver: Version of the Type ID :param vsiid_frmt: Format of the following VSI argument :param filter_frmt: Filter Format. Only <GID,MAC,VID> supported for now :param gid: Group ID the vNIC belongs to :param mac: MAC Address of the vNIC :param vlan: VLAN of the vNIC :param oui_id: OUI Type :param oui_data: OUI Data :param sw_resp: Flag indicating if response is required from the daemon """ # Correct non-zero VLAN needs to be specified try: with self.mutex_lock: self.send_vdp_deassoc(vsiid=vsiid, mgrid=mgrid, typeid=typeid, typeid_ver=typeid_ver, vsiid_frmt=vsiid_frmt, filter_frmt=filter_frmt, gid=gid, mac=mac, vlan=vlan) self.clear_vdp_vsi(port_uuid) except Exception as e: LOG.error("VNIC Down exception %s", e)
[ "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", ",", ...
Interface function to apps, called for a vNIC DOWN. This currently sends an VDP dis-associate message. Please refer http://www.ieee802.org/1/pages/802.1bg.html VDP Section for more detailed information :param uuid: uuid of the vNIC :param vsiid: VSI value, Only UUID supported for now :param mgrid: MGR ID :param typeid: Type ID :param typeid_ver: Version of the Type ID :param vsiid_frmt: Format of the following VSI argument :param filter_frmt: Filter Format. Only <GID,MAC,VID> supported for now :param gid: Group ID the vNIC belongs to :param mac: MAC Address of the vNIC :param vlan: VLAN of the vNIC :param oui_id: OUI Type :param oui_data: OUI Data :param sw_resp: Flag indicating if response is required from the daemon
[ "Interface", "function", "to", "apps", "called", "for", "a", "vNIC", "DOWN", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/vdp/lldpad.py#L772-L806
train
37,867
openstack/networking-cisco
networking_cisco/apps/saf/agent/vdp/lldpad.py
LldpadDriver.run_vdptool
def run_vdptool(self, args, oui_args=None): """Function that runs the vdptool utility. """ 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 e: LOG.error("Unable to execute %(cmd)s. " "Exception: %(exception)s", {'cmd': full_args, 'exception': e})
python
def run_vdptool(self, args, oui_args=None): """Function that runs the vdptool utility. """ 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 e: LOG.error("Unable to execute %(cmd)s. " "Exception: %(exception)s", {'cmd': full_args, 'exception': e})
[ "def", "run_vdptool", "(", "self", ",", "args", ",", "oui_args", "=", "None", ")", ":", "if", "oui_args", "is", "None", ":", "oui_args", "=", "[", "]", "full_args", "=", "[", "'vdptool'", "]", "+", "args", "+", "oui_args", "try", ":", "return", "util...
Function that runs the vdptool utility.
[ "Function", "that", "runs", "the", "vdptool", "utility", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/vdp/lldpad.py#L808-L818
train
37,868
openstack/networking-cisco
networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py
CiscoRoutingPluginApi.get_routers
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 hosting devices will be returned. """ cctxt = self.client.prepare(version='1.1') return cctxt.call(context, 'cfg_sync_routers', host=self.host, router_ids=router_ids, hosting_device_ids=hd_ids)
python
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 hosting devices will be returned. """ cctxt = self.client.prepare(version='1.1') return cctxt.call(context, 'cfg_sync_routers', host=self.host, router_ids=router_ids, hosting_device_ids=hd_ids)
[ "def", "get_routers", "(", "self", ",", "context", ",", "router_ids", "=", "None", ",", "hd_ids", "=", "None", ")", ":", "cctxt", "=", "self", ".", "client", ".", "prepare", "(", "version", "=", "'1.1'", ")", "return", "cctxt", ".", "call", "(", "con...
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 hosting devices will be returned.
[ "Make", "a", "remote", "process", "call", "to", "retrieve", "the", "sync", "data", "for", "routers", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py#L130-L140
train
37,869
openstack/networking-cisco
networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py
CiscoRoutingPluginApi.update_floatingip_statuses
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_statuses: dict with floatingip_id as key and status as value """ cctxt = self.client.prepare(version='1.1') return cctxt.call(context, 'update_floatingip_statuses_cfg', router_id=router_id, fip_statuses=fip_statuses)
python
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_statuses: dict with floatingip_id as key and status as value """ cctxt = self.client.prepare(version='1.1') return cctxt.call(context, 'update_floatingip_statuses_cfg', router_id=router_id, fip_statuses=fip_statuses)
[ "def", "update_floatingip_statuses", "(", "self", ",", "context", ",", "router_id", ",", "fip_statuses", ")", ":", "cctxt", "=", "self", ".", "client", ".", "prepare", "(", "version", "=", "'1.1'", ")", "return", "cctxt", ".", "call", "(", "context", ",", ...
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_statuses: dict with floatingip_id as key and status as value
[ "Make", "a", "remote", "process", "call", "to", "update", "operational", "status", "for", "one", "or", "several", "floating", "IPs", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py#L155-L165
train
37,870
openstack/networking-cisco
networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py
CiscoRoutingPluginApi.send_update_port_statuses
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 given port list (port_ids) """ cctxt = self.client.prepare(version='1.1') return cctxt.call(context, 'update_port_statuses_cfg', port_ids=port_ids, status=status)
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 given port list (port_ids) """ cctxt = self.client.prepare(version='1.1') return cctxt.call(context, 'update_port_statuses_cfg', port_ids=port_ids, status=status)
[ "def", "send_update_port_statuses", "(", "self", ",", "context", ",", "port_ids", ",", "status", ")", ":", "cctxt", "=", "self", ".", "client", ".", "prepare", "(", "version", "=", "'1.1'", ")", "return", "cctxt", ".", "call", "(", "context", ",", "'upda...
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 given port list (port_ids)
[ "Call", "the", "pluging", "to", "update", "the", "port", "status", "which", "updates", "the", "DB", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py#L167-L176
train
37,871
openstack/networking-cisco
networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py
RoutingServiceHelper.router_deleted
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)
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)
[ "def", "router_deleted", "(", "self", ",", "context", ",", "routers", ")", ":", "LOG", ".", "debug", "(", "'Got router deleted notification for %s'", ",", "routers", ")", "self", ".", "_update_removed_routers_cache", "(", "routers", ")" ]
Deal with router deletion RPC message.
[ "Deal", "with", "router", "deletion", "RPC", "message", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py#L216-L219
train
37,872
openstack/networking-cisco
networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py
RoutingServiceHelper.routers_updated
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): routers = [router['id'] for router in routers] self._update_updated_routers_cache(routers)
python
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): routers = [router['id'] for router in routers] self._update_updated_routers_cache(routers)
[ "def", "routers_updated", "(", "self", ",", "context", ",", "routers", ")", ":", "LOG", ".", "debug", "(", "'Got routers updated notification :%s'", ",", "routers", ")", "if", "routers", ":", "# This is needed for backward compatibility", "if", "isinstance", "(", "r...
Deal with routers modification and creation RPC message.
[ "Deal", "with", "routers", "modification", "and", "creation", "RPC", "message", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py#L221-L228
train
37,873
openstack/networking-cisco
networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py
RoutingServiceHelper.collect_state
def collect_state(self, configurations): """Collect state from this helper. A set of attributes which summarizes the state of the routers and configurations managed by this config agent. :param configurations: dict of configuration values :return dict of updated configuration values """ 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) for ri in router_infos: ex_gw_port = ri.router.get('gw_port') if ex_gw_port: num_ex_gw_ports += 1 num_interfaces += len(ri.router.get( bc.constants.INTERFACE_KEY, [])) num_floating_ips += len(ri.router.get( bc.constants.FLOATINGIP_KEY, [])) hd = ri.router['hosting_device'] if hd: num_hd_routers[hd['id']] += 1 routers_per_hd = dict((hd_id, {'routers': num}) for hd_id, num in num_hd_routers.items()) non_responding = self._dev_status.get_backlogged_hosting_devices() configurations['total routers'] = num_routers configurations['total ex_gw_ports'] = num_ex_gw_ports configurations['total interfaces'] = num_interfaces configurations['total floating_ips'] = num_floating_ips configurations['hosting_devices'] = routers_per_hd configurations['non_responding_hosting_devices'] = non_responding return configurations
python
def collect_state(self, configurations): """Collect state from this helper. A set of attributes which summarizes the state of the routers and configurations managed by this config agent. :param configurations: dict of configuration values :return dict of updated configuration values """ 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) for ri in router_infos: ex_gw_port = ri.router.get('gw_port') if ex_gw_port: num_ex_gw_ports += 1 num_interfaces += len(ri.router.get( bc.constants.INTERFACE_KEY, [])) num_floating_ips += len(ri.router.get( bc.constants.FLOATINGIP_KEY, [])) hd = ri.router['hosting_device'] if hd: num_hd_routers[hd['id']] += 1 routers_per_hd = dict((hd_id, {'routers': num}) for hd_id, num in num_hd_routers.items()) non_responding = self._dev_status.get_backlogged_hosting_devices() configurations['total routers'] = num_routers configurations['total ex_gw_ports'] = num_ex_gw_ports configurations['total interfaces'] = num_interfaces configurations['total floating_ips'] = num_floating_ips configurations['hosting_devices'] = routers_per_hd configurations['non_responding_hosting_devices'] = non_responding return configurations
[ "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", ...
Collect state from this helper. A set of attributes which summarizes the state of the routers and configurations managed by this config agent. :param configurations: dict of configuration values :return dict of updated configuration values
[ "Collect", "state", "from", "this", "helper", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py#L317-L351
train
37,874
openstack/networking-cisco
networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py
RoutingServiceHelper._fetch_router_info
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_routers: If True fetch all the routers for this agent. :return: List of router dicts of format: [ {router_dict1}, {router_dict2},.....] """ try: if all_routers: LOG.debug('Fetching all routers') router_ids = self.plugin_rpc.get_router_ids(self.context) routers = self._fetch_router_chunk_data(router_ids) elif router_ids: routers = self._fetch_router_chunk_data(router_ids) elif device_ids: return self.plugin_rpc.get_routers(self.context, hd_ids=device_ids) except oslo_messaging.MessagingTimeout: if self.sync_routers_chunk_size > SYNC_ROUTERS_MIN_CHUNK_SIZE: self.sync_routers_chunk_size = max( int(round(self.sync_routers_chunk_size / 2)), SYNC_ROUTERS_MIN_CHUNK_SIZE) LOG.warning('Server failed to return info for routers in ' 'required time, decreasing chunk size to: %s', self.sync_routers_chunk_size) else: LOG.warning('Server failed to return info for routers in ' 'required time even with min chunk size: %s. ' 'It might be under very high load or just ' 'inoperable', self.sync_routers_chunk_size) raise except oslo_messaging.MessagingException: LOG.exception("RPC Error in fetching routers from plugin") self.fullsync = True raise n_exc.AbortSyncRouters() LOG.debug("Periodic_sync_routers_task successfully completed") # adjust chunk size after successful sync if (self.sync_routers_chunk_size < cfg.CONF.cfg_agent.max_device_sync_batch_size): self.sync_routers_chunk_size = min( self.sync_routers_chunk_size + SYNC_ROUTERS_MIN_CHUNK_SIZE, cfg.CONF.cfg_agent.max_device_sync_batch_size) return routers
python
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_routers: If True fetch all the routers for this agent. :return: List of router dicts of format: [ {router_dict1}, {router_dict2},.....] """ try: if all_routers: LOG.debug('Fetching all routers') router_ids = self.plugin_rpc.get_router_ids(self.context) routers = self._fetch_router_chunk_data(router_ids) elif router_ids: routers = self._fetch_router_chunk_data(router_ids) elif device_ids: return self.plugin_rpc.get_routers(self.context, hd_ids=device_ids) except oslo_messaging.MessagingTimeout: if self.sync_routers_chunk_size > SYNC_ROUTERS_MIN_CHUNK_SIZE: self.sync_routers_chunk_size = max( int(round(self.sync_routers_chunk_size / 2)), SYNC_ROUTERS_MIN_CHUNK_SIZE) LOG.warning('Server failed to return info for routers in ' 'required time, decreasing chunk size to: %s', self.sync_routers_chunk_size) else: LOG.warning('Server failed to return info for routers in ' 'required time even with min chunk size: %s. ' 'It might be under very high load or just ' 'inoperable', self.sync_routers_chunk_size) raise except oslo_messaging.MessagingException: LOG.exception("RPC Error in fetching routers from plugin") self.fullsync = True raise n_exc.AbortSyncRouters() LOG.debug("Periodic_sync_routers_task successfully completed") # adjust chunk size after successful sync if (self.sync_routers_chunk_size < cfg.CONF.cfg_agent.max_device_sync_batch_size): self.sync_routers_chunk_size = min( self.sync_routers_chunk_size + SYNC_ROUTERS_MIN_CHUNK_SIZE, cfg.CONF.cfg_agent.max_device_sync_batch_size) return routers
[ "def", "_fetch_router_info", "(", "self", ",", "router_ids", "=", "None", ",", "device_ids", "=", "None", ",", "all_routers", "=", "False", ")", ":", "try", ":", "if", "all_routers", ":", "LOG", ".", "debug", "(", "'Fetching all routers'", ")", "router_ids",...
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_routers: If True fetch all the routers for this agent. :return: List of router dicts of format: [ {router_dict1}, {router_dict2},.....]
[ "Fetch", "router", "dict", "from", "the", "routing", "plugin", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py#L406-L455
train
37,875
openstack/networking-cisco
networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py
RoutingServiceHelper._fetch_router_chunk_data
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},.....] """ curr_router = [] if len(router_ids) > self.sync_routers_chunk_size: # fetch routers by chunks to reduce the load on server and # to start router processing earlier for i in range(0, len(router_ids), self.sync_routers_chunk_size): routers = self.plugin_rpc.get_routers( self.context, (router_ids[i:i + self.sync_routers_chunk_size])) LOG.debug('Processing :%r', routers) for r in routers: curr_router.append(r) else: curr_router = self.plugin_rpc.get_routers( self.context, router_ids=router_ids) return curr_router
python
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},.....] """ curr_router = [] if len(router_ids) > self.sync_routers_chunk_size: # fetch routers by chunks to reduce the load on server and # to start router processing earlier for i in range(0, len(router_ids), self.sync_routers_chunk_size): routers = self.plugin_rpc.get_routers( self.context, (router_ids[i:i + self.sync_routers_chunk_size])) LOG.debug('Processing :%r', routers) for r in routers: curr_router.append(r) else: curr_router = self.plugin_rpc.get_routers( self.context, router_ids=router_ids) return curr_router
[ "def", "_fetch_router_chunk_data", "(", "self", ",", "router_ids", "=", "None", ")", ":", "curr_router", "=", "[", "]", "if", "len", "(", "router_ids", ")", ">", "self", ".", "sync_routers_chunk_size", ":", "# fetch routers by chunks to reduce the load on server and",...
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},.....]
[ "Fetch", "router", "data", "from", "the", "routing", "plugin", "in", "chunks", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py#L457-L481
train
37,876
openstack/networking-cisco
networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py
RoutingServiceHelper._handle_sync_devices
def _handle_sync_devices(self, routers): """ Handles routers during a device_sync. This method performs post-processing on routers fetched from the routing plugin during a device sync. Routers are first fetched from the plugin based on the list of device_ids. Since fetched routers take precedence over pending work, matching router-ids buffered in update_routers and removed_routers are discarded. The existing router cache is also cleared in order to properly trigger updates and deletes. Lastly, invalid configuration in the underlying hosting-device is deleted via _cleanup_invalid_cfg. Modifies updated_routers, removed_routers, and sync_devices attributes :param routers: working list of routers as populated in process_services """ 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_routers: LOG.debug("[sync_devices] Fetched routers :%s", pp.pformat(fetched_routers)) # clear router_config cache for router_dict in fetched_routers: self._del_from_updated_routers_cache(router_dict['id']) self._del_from_removed_routers_cache(router_dict['id']) LOG.debug("[sync_devices] invoking " "_router_removed(%s)", router_dict['id']) self._router_removed(router_dict['id'], deconfigure=False) self._cleanup_invalid_cfg(fetched_routers) routers.extend(fetched_routers) self.sync_devices.clear() LOG.debug("[sync_devices] %s finished", sync_devices_list) else: # If the initial attempt to sync a device # failed, retry again (by not clearing sync_devices) # Normal updated_routers processing is still allowed # to happen self.sync_devices_attempts += 1 if (self.sync_devices_attempts >= cfg.CONF.cfg_agent.max_device_sync_attempts): LOG.debug("Max number [%d / %d ] of sync_devices " "attempted. No further retries will " "be attempted." % (self.sync_devices_attempts, cfg.CONF.cfg_agent.max_device_sync_attempts)) self.sync_devices.clear() self.sync_devices_attempts = 0 else: LOG.debug("Fetched routers was blank for sync attempt " "[%d / %d], will attempt resync of %s devices " "again in the next iteration" % (self.sync_devices_attempts, cfg.CONF.cfg_agent.max_device_sync_attempts, pp.pformat(self.sync_devices)))
python
def _handle_sync_devices(self, routers): """ Handles routers during a device_sync. This method performs post-processing on routers fetched from the routing plugin during a device sync. Routers are first fetched from the plugin based on the list of device_ids. Since fetched routers take precedence over pending work, matching router-ids buffered in update_routers and removed_routers are discarded. The existing router cache is also cleared in order to properly trigger updates and deletes. Lastly, invalid configuration in the underlying hosting-device is deleted via _cleanup_invalid_cfg. Modifies updated_routers, removed_routers, and sync_devices attributes :param routers: working list of routers as populated in process_services """ 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_routers: LOG.debug("[sync_devices] Fetched routers :%s", pp.pformat(fetched_routers)) # clear router_config cache for router_dict in fetched_routers: self._del_from_updated_routers_cache(router_dict['id']) self._del_from_removed_routers_cache(router_dict['id']) LOG.debug("[sync_devices] invoking " "_router_removed(%s)", router_dict['id']) self._router_removed(router_dict['id'], deconfigure=False) self._cleanup_invalid_cfg(fetched_routers) routers.extend(fetched_routers) self.sync_devices.clear() LOG.debug("[sync_devices] %s finished", sync_devices_list) else: # If the initial attempt to sync a device # failed, retry again (by not clearing sync_devices) # Normal updated_routers processing is still allowed # to happen self.sync_devices_attempts += 1 if (self.sync_devices_attempts >= cfg.CONF.cfg_agent.max_device_sync_attempts): LOG.debug("Max number [%d / %d ] of sync_devices " "attempted. No further retries will " "be attempted." % (self.sync_devices_attempts, cfg.CONF.cfg_agent.max_device_sync_attempts)) self.sync_devices.clear() self.sync_devices_attempts = 0 else: LOG.debug("Fetched routers was blank for sync attempt " "[%d / %d], will attempt resync of %s devices " "again in the next iteration" % (self.sync_devices_attempts, cfg.CONF.cfg_agent.max_device_sync_attempts, pp.pformat(self.sync_devices)))
[ "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", ...
Handles routers during a device_sync. This method performs post-processing on routers fetched from the routing plugin during a device sync. Routers are first fetched from the plugin based on the list of device_ids. Since fetched routers take precedence over pending work, matching router-ids buffered in update_routers and removed_routers are discarded. The existing router cache is also cleared in order to properly trigger updates and deletes. Lastly, invalid configuration in the underlying hosting-device is deleted via _cleanup_invalid_cfg. Modifies updated_routers, removed_routers, and sync_devices attributes :param routers: working list of routers as populated in process_services
[ "Handles", "routers", "during", "a", "device_sync", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py#L483-L548
train
37,877
openstack/networking-cisco
networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py
RoutingServiceHelper._get_router_ids_from_removed_devices_info
def _get_router_ids_from_removed_devices_info(removed_devices_info): """Extract router_ids from the removed devices info dict. :param removed_devices_info: Dict of removed devices and their associated resources. Format: { 'hosting_data': {'hd_id1': {'routers': [id1, id2, ...]}, 'hd_id2': {'routers': [id3, id4, ...]}, ... }, 'deconfigure': True/False } :return removed_router_ids: List of removed router ids """ removed_router_ids = [] for hd_id, resources in removed_devices_info['hosting_data'].items(): removed_router_ids += resources.get('routers', []) return removed_router_ids
python
def _get_router_ids_from_removed_devices_info(removed_devices_info): """Extract router_ids from the removed devices info dict. :param removed_devices_info: Dict of removed devices and their associated resources. Format: { 'hosting_data': {'hd_id1': {'routers': [id1, id2, ...]}, 'hd_id2': {'routers': [id3, id4, ...]}, ... }, 'deconfigure': True/False } :return removed_router_ids: List of removed router ids """ removed_router_ids = [] for hd_id, resources in removed_devices_info['hosting_data'].items(): removed_router_ids += resources.get('routers', []) return removed_router_ids
[ "def", "_get_router_ids_from_removed_devices_info", "(", "removed_devices_info", ")", ":", "removed_router_ids", "=", "[", "]", "for", "hd_id", ",", "resources", "in", "removed_devices_info", "[", "'hosting_data'", "]", ".", "items", "(", ")", ":", "removed_router_ids...
Extract router_ids from the removed devices info dict. :param removed_devices_info: Dict of removed devices and their associated resources. Format: { 'hosting_data': {'hd_id1': {'routers': [id1, id2, ...]}, 'hd_id2': {'routers': [id3, id4, ...]}, ... }, 'deconfigure': True/False } :return removed_router_ids: List of removed router ids
[ "Extract", "router_ids", "from", "the", "removed", "devices", "info", "dict", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py#L551-L569
train
37,878
openstack/networking-cisco
networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py
RoutingServiceHelper._sort_resources_per_hosting_device
def _sort_resources_per_hosting_device(resources): """This function will sort the resources on hosting device. The sorting on hosting device is done by looking up the `hosting_device` attribute of the resource, and its `id`. :param resources: a dict with key of resource name :return dict sorted on the hosting device of input resource. Format: hosting_devices = { 'hd_id1' : {'routers':[routers], 'removed_routers':[routers], .... } 'hd_id2' : {'routers':[routers], .. } ....... } """ hosting_devices = {} for key in resources.keys(): for r in resources.get(key) or []: if r.get('hosting_device') is None: continue hd_id = r['hosting_device']['id'] hosting_devices.setdefault(hd_id, {}) hosting_devices[hd_id].setdefault(key, []).append(r) return hosting_devices
python
def _sort_resources_per_hosting_device(resources): """This function will sort the resources on hosting device. The sorting on hosting device is done by looking up the `hosting_device` attribute of the resource, and its `id`. :param resources: a dict with key of resource name :return dict sorted on the hosting device of input resource. Format: hosting_devices = { 'hd_id1' : {'routers':[routers], 'removed_routers':[routers], .... } 'hd_id2' : {'routers':[routers], .. } ....... } """ hosting_devices = {} for key in resources.keys(): for r in resources.get(key) or []: if r.get('hosting_device') is None: continue hd_id = r['hosting_device']['id'] hosting_devices.setdefault(hd_id, {}) hosting_devices[hd_id].setdefault(key, []).append(r) return hosting_devices
[ "def", "_sort_resources_per_hosting_device", "(", "resources", ")", ":", "hosting_devices", "=", "{", "}", "for", "key", "in", "resources", ".", "keys", "(", ")", ":", "for", "r", "in", "resources", ".", "get", "(", "key", ")", "or", "[", "]", ":", "if...
This function will sort the resources on hosting device. The sorting on hosting device is done by looking up the `hosting_device` attribute of the resource, and its `id`. :param resources: a dict with key of resource name :return dict sorted on the hosting device of input resource. Format: hosting_devices = { 'hd_id1' : {'routers':[routers], 'removed_routers':[routers], .... } 'hd_id2' : {'routers':[routers], .. } ....... }
[ "This", "function", "will", "sort", "the", "resources", "on", "hosting", "device", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py#L572-L595
train
37,879
openstack/networking-cisco
networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py
RoutingServiceHelper._adjust_router_list_for_global_router
def _adjust_router_list_for_global_router(self, routers): """ Pushes 'Global' routers to the end of the router list, so that deleting default route occurs before deletion of external nw subintf """ #ToDo(Hareesh): Simplify if possible for r in routers: if r[ROUTER_ROLE_ATTR] == c_constants.ROUTER_ROLE_GLOBAL: LOG.debug("Global router:%s found. Moved to the end of list " "for processing", r['id']) routers.remove(r) routers.append(r)
python
def _adjust_router_list_for_global_router(self, routers): """ Pushes 'Global' routers to the end of the router list, so that deleting default route occurs before deletion of external nw subintf """ #ToDo(Hareesh): Simplify if possible for r in routers: if r[ROUTER_ROLE_ATTR] == c_constants.ROUTER_ROLE_GLOBAL: LOG.debug("Global router:%s found. Moved to the end of list " "for processing", r['id']) routers.remove(r) routers.append(r)
[ "def", "_adjust_router_list_for_global_router", "(", "self", ",", "routers", ")", ":", "#ToDo(Hareesh): Simplify if possible", "for", "r", "in", "routers", ":", "if", "r", "[", "ROUTER_ROLE_ATTR", "]", "==", "c_constants", ".", "ROUTER_ROLE_GLOBAL", ":", "LOG", ".",...
Pushes 'Global' routers to the end of the router list, so that deleting default route occurs before deletion of external nw subintf
[ "Pushes", "Global", "routers", "to", "the", "end", "of", "the", "router", "list", "so", "that", "deleting", "default", "route", "occurs", "before", "deletion", "of", "external", "nw", "subintf" ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py#L597-L608
train
37,880
openstack/networking-cisco
networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py
RoutingServiceHelper._send_update_port_statuses
def _send_update_port_statuses(self, port_ids, status): """Sends update notifications to set the operational status of the list of router ports provided. To make each notification doesn't exceed the RPC length, each message contains a maximum of MAX_PORTS_IN_BATCH port ids. :param port_ids: List of ports to update the status :param status: operational status to update (ex: bc.constants.PORT_STATUS_ACTIVE) """ if not port_ids: return MAX_PORTS_IN_BATCH = 50 list_chunks_ports = [port_ids[i:i + MAX_PORTS_IN_BATCH] for i in six.moves.range(0, len(port_ids), MAX_PORTS_IN_BATCH)] for chunk_ports in list_chunks_ports: self.plugin_rpc.send_update_port_statuses(self.context, chunk_ports, status)
python
def _send_update_port_statuses(self, port_ids, status): """Sends update notifications to set the operational status of the list of router ports provided. To make each notification doesn't exceed the RPC length, each message contains a maximum of MAX_PORTS_IN_BATCH port ids. :param port_ids: List of ports to update the status :param status: operational status to update (ex: bc.constants.PORT_STATUS_ACTIVE) """ if not port_ids: return MAX_PORTS_IN_BATCH = 50 list_chunks_ports = [port_ids[i:i + MAX_PORTS_IN_BATCH] for i in six.moves.range(0, len(port_ids), MAX_PORTS_IN_BATCH)] for chunk_ports in list_chunks_ports: self.plugin_rpc.send_update_port_statuses(self.context, chunk_ports, status)
[ "def", "_send_update_port_statuses", "(", "self", ",", "port_ids", ",", "status", ")", ":", "if", "not", "port_ids", ":", "return", "MAX_PORTS_IN_BATCH", "=", "50", "list_chunks_ports", "=", "[", "port_ids", "[", "i", ":", "i", "+", "MAX_PORTS_IN_BATCH", "]", ...
Sends update notifications to set the operational status of the list of router ports provided. To make each notification doesn't exceed the RPC length, each message contains a maximum of MAX_PORTS_IN_BATCH port ids. :param port_ids: List of ports to update the status :param status: operational status to update (ex: bc.constants.PORT_STATUS_ACTIVE)
[ "Sends", "update", "notifications", "to", "set", "the", "operational", "status", "of", "the", "list", "of", "router", "ports", "provided", ".", "To", "make", "each", "notification", "doesn", "t", "exceed", "the", "RPC", "length", "each", "message", "contains",...
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py#L728-L746
train
37,881
openstack/networking-cisco
networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py
RoutingServiceHelper._process_router
def _process_router(self, ri): """Process a router, apply latest configuration and update router_info. Get the router dict from RouterInfo and proceed to detect changes from the last known state. When new ports or deleted ports are detected, `internal_network_added()` or `internal_networks_removed()` are called accordingly. Similarly changes in ex_gw_port causes `external_gateway_added()` or `external_gateway_removed()` calls. Next, floating_ips and routes are processed. Also, latest state is stored in ri.internal_ports and ri.ex_gw_port for future comparisons. :param ri : RouterInfo object of the router being processed. :return:None :raises: networking_cisco.plugins.cisco.cfg_agent.cfg_exceptions. DriverException if the configuration operation fails. """ try: ex_gw_port = ri.router.get('gw_port') ri.ha_info = ri.router.get('ha_info', None) gateway_set = ex_gw_port and not ri.ex_gw_port gateway_cleared = not ex_gw_port and ri.ex_gw_port internal_ports = ri.router.get(bc.constants.INTERFACE_KEY, []) # Once the gateway is set, then we know which VRF this router # belongs to. Keep track of it in our lists of routers, organized # as a dictionary by VRF name if gateway_set: self._add_rid_to_vrf_list(ri) new_ports, old_ports, change_details = ( self._get_internal_port_changes(ri, internal_ports)) list_port_ids_up = [] non_global_router_roles = [None, c_constants.ROUTER_ROLE_HA_REDUNDANCY] if ri.router[ROUTER_ROLE_ATTR] in non_global_router_roles: self._process_new_ports(ri, new_ports, ex_gw_port, list_port_ids_up, change_details) self._process_old_ports(ri, old_ports, ex_gw_port, change_details) else: self._process_new_ports_global(ri, new_ports, ex_gw_port, list_port_ids_up) self._process_old_ports_global(ri, old_ports, ex_gw_port) if gateway_set: self._process_gateway_set(ri, ex_gw_port, list_port_ids_up) elif gateway_cleared: self._process_gateway_cleared(ri, ri.ex_gw_port) self._send_update_port_statuses(list_port_ids_up, bc.constants.PORT_STATUS_ACTIVE) if ex_gw_port: self._process_router_floating_ips(ri, ex_gw_port) global_router_roles = [c_constants.ROUTER_ROLE_GLOBAL, c_constants.ROUTER_ROLE_LOGICAL_GLOBAL] if ri.router[ROUTER_ROLE_ATTR] not in global_router_roles: self._enable_disable_ports(ri, ex_gw_port, internal_ports) if gateway_cleared: # Remove this router from the list of routers by VRF self._remove_rid_from_vrf_list(ri) ri.ex_gw_port = ex_gw_port self._routes_updated(ri) except cfg_exceptions.HAParamsMissingException as e: self._update_updated_routers_cache([ri.router_id]) LOG.warning(e) except cfg_exceptions.DriverException as e: with excutils.save_and_reraise_exception(): self._update_updated_routers_cache([ri.router_id]) LOG.error(e)
python
def _process_router(self, ri): """Process a router, apply latest configuration and update router_info. Get the router dict from RouterInfo and proceed to detect changes from the last known state. When new ports or deleted ports are detected, `internal_network_added()` or `internal_networks_removed()` are called accordingly. Similarly changes in ex_gw_port causes `external_gateway_added()` or `external_gateway_removed()` calls. Next, floating_ips and routes are processed. Also, latest state is stored in ri.internal_ports and ri.ex_gw_port for future comparisons. :param ri : RouterInfo object of the router being processed. :return:None :raises: networking_cisco.plugins.cisco.cfg_agent.cfg_exceptions. DriverException if the configuration operation fails. """ try: ex_gw_port = ri.router.get('gw_port') ri.ha_info = ri.router.get('ha_info', None) gateway_set = ex_gw_port and not ri.ex_gw_port gateway_cleared = not ex_gw_port and ri.ex_gw_port internal_ports = ri.router.get(bc.constants.INTERFACE_KEY, []) # Once the gateway is set, then we know which VRF this router # belongs to. Keep track of it in our lists of routers, organized # as a dictionary by VRF name if gateway_set: self._add_rid_to_vrf_list(ri) new_ports, old_ports, change_details = ( self._get_internal_port_changes(ri, internal_ports)) list_port_ids_up = [] non_global_router_roles = [None, c_constants.ROUTER_ROLE_HA_REDUNDANCY] if ri.router[ROUTER_ROLE_ATTR] in non_global_router_roles: self._process_new_ports(ri, new_ports, ex_gw_port, list_port_ids_up, change_details) self._process_old_ports(ri, old_ports, ex_gw_port, change_details) else: self._process_new_ports_global(ri, new_ports, ex_gw_port, list_port_ids_up) self._process_old_ports_global(ri, old_ports, ex_gw_port) if gateway_set: self._process_gateway_set(ri, ex_gw_port, list_port_ids_up) elif gateway_cleared: self._process_gateway_cleared(ri, ri.ex_gw_port) self._send_update_port_statuses(list_port_ids_up, bc.constants.PORT_STATUS_ACTIVE) if ex_gw_port: self._process_router_floating_ips(ri, ex_gw_port) global_router_roles = [c_constants.ROUTER_ROLE_GLOBAL, c_constants.ROUTER_ROLE_LOGICAL_GLOBAL] if ri.router[ROUTER_ROLE_ATTR] not in global_router_roles: self._enable_disable_ports(ri, ex_gw_port, internal_ports) if gateway_cleared: # Remove this router from the list of routers by VRF self._remove_rid_from_vrf_list(ri) ri.ex_gw_port = ex_gw_port self._routes_updated(ri) except cfg_exceptions.HAParamsMissingException as e: self._update_updated_routers_cache([ri.router_id]) LOG.warning(e) except cfg_exceptions.DriverException as e: with excutils.save_and_reraise_exception(): self._update_updated_routers_cache([ri.router_id]) LOG.error(e)
[ "def", "_process_router", "(", "self", ",", "ri", ")", ":", "try", ":", "ex_gw_port", "=", "ri", ".", "router", ".", "get", "(", "'gw_port'", ")", "ri", ".", "ha_info", "=", "ri", ".", "router", ".", "get", "(", "'ha_info'", ",", "None", ")", "gate...
Process a router, apply latest configuration and update router_info. Get the router dict from RouterInfo and proceed to detect changes from the last known state. When new ports or deleted ports are detected, `internal_network_added()` or `internal_networks_removed()` are called accordingly. Similarly changes in ex_gw_port causes `external_gateway_added()` or `external_gateway_removed()` calls. Next, floating_ips and routes are processed. Also, latest state is stored in ri.internal_ports and ri.ex_gw_port for future comparisons. :param ri : RouterInfo object of the router being processed. :return:None :raises: networking_cisco.plugins.cisco.cfg_agent.cfg_exceptions. DriverException if the configuration operation fails.
[ "Process", "a", "router", "apply", "latest", "configuration", "and", "update", "router_info", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py#L968-L1041
train
37,882
openstack/networking-cisco
networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py
RoutingServiceHelper._process_router_floating_ips
def _process_router_floating_ips(self, ri, ex_gw_port): """Process a router's floating ips. Compare floatingips configured in device (i.e., those fips in the ri.floating_ips "cache") with the router's updated floating ips (in ri.router.floating_ips) and determine floating_ips which were added or removed. Notify driver of the change via `floating_ip_added()` or `floating_ip_removed()`. Also update plugin with status of fips. :param ri: RouterInfo object of the router being processed. :param ex_gw_port: Port dict of the external gateway port. :return: None :raises: networking_cisco.plugins.cisco.cfg_agent.cfg_exceptions. DriverException if the configuration operation fails. """ # fips that exist in neutron db (i.e., the desired "truth") current_fips = ri.router.get(bc.constants.FLOATINGIP_KEY, []) # ids of fips that exist in neutron db current_fip_ids = {fip['id'] for fip in current_fips} # ids of fips that are configured in device configured_fip_ids = {fip['id'] for fip in ri.floating_ips} id_to_current_fip_map = {} fips_to_add = [] # iterate of fips that exist in neutron db for configured_fip in current_fips: if configured_fip['port_id']: # store to later check if this fip has been remapped id_to_current_fip_map[configured_fip['id']] = configured_fip if configured_fip['id'] not in configured_fip_ids: # Ensure that we add only after remove, in case same # fixed_ip is mapped to different floating_ip within # the same loop cycle. If add occurs before first, # cfg will fail because of existing entry with # identical fixed_ip fips_to_add.append(configured_fip) fip_ids_to_remove = configured_fip_ids - current_fip_ids LOG.debug("fip_ids_to_add: %s" % fips_to_add) LOG.debug("fip_ids_to_remove: %s" % fip_ids_to_remove) fips_to_remove = [] fip_statuses = {} # iterate over fips that are configured in device for configured_fip in ri.floating_ips: if configured_fip['id'] in fip_ids_to_remove: fips_to_remove.append(configured_fip) self._floating_ip_removed( ri, ri.ex_gw_port, configured_fip['floating_ip_address'], configured_fip['fixed_ip_address']) fip_statuses[configured_fip['id']] = ( bc.constants.FLOATINGIP_STATUS_DOWN) LOG.debug("Add to fip_statuses DOWN id:%s fl_ip:%s fx_ip:%s", configured_fip['id'], configured_fip['floating_ip_address'], configured_fip['fixed_ip_address']) else: # handle possibly required remapping of a fip # ip address that fip currently is configured for configured_fixed_ip = configured_fip['fixed_ip_address'] new_fip = id_to_current_fip_map[configured_fip['id']] # ip address that fip should be configured for current_fixed_ip = new_fip['fixed_ip_address'] if (current_fixed_ip and configured_fixed_ip and current_fixed_ip != configured_fixed_ip): floating_ip = configured_fip['floating_ip_address'] self._floating_ip_removed(ri, ri.ex_gw_port, floating_ip, configured_fixed_ip) fip_statuses[configured_fip['id']] = ( bc.constants.FLOATINGIP_STATUS_DOWN) fips_to_remove.append(configured_fip) fips_to_add.append(new_fip) for configured_fip in fips_to_remove: # remove fip from "cache" of fips configured in device ri.floating_ips.remove(configured_fip) for configured_fip in fips_to_add: self._floating_ip_added(ri, ex_gw_port, configured_fip['floating_ip_address'], configured_fip['fixed_ip_address']) # add fip to "cache" of fips configured in device ri.floating_ips.append(configured_fip) fip_statuses[configured_fip['id']] = ( bc.constants.FLOATINGIP_STATUS_ACTIVE) LOG.debug("Add to fip_statuses ACTIVE id:%s fl_ip:%s fx_ip:%s", configured_fip['id'], configured_fip['floating_ip_address'], configured_fip['fixed_ip_address']) if fip_statuses: LOG.debug("Sending floatingip_statuses_update: %s", fip_statuses) self.plugin_rpc.update_floatingip_statuses( self.context, ri.router_id, fip_statuses)
python
def _process_router_floating_ips(self, ri, ex_gw_port): """Process a router's floating ips. Compare floatingips configured in device (i.e., those fips in the ri.floating_ips "cache") with the router's updated floating ips (in ri.router.floating_ips) and determine floating_ips which were added or removed. Notify driver of the change via `floating_ip_added()` or `floating_ip_removed()`. Also update plugin with status of fips. :param ri: RouterInfo object of the router being processed. :param ex_gw_port: Port dict of the external gateway port. :return: None :raises: networking_cisco.plugins.cisco.cfg_agent.cfg_exceptions. DriverException if the configuration operation fails. """ # fips that exist in neutron db (i.e., the desired "truth") current_fips = ri.router.get(bc.constants.FLOATINGIP_KEY, []) # ids of fips that exist in neutron db current_fip_ids = {fip['id'] for fip in current_fips} # ids of fips that are configured in device configured_fip_ids = {fip['id'] for fip in ri.floating_ips} id_to_current_fip_map = {} fips_to_add = [] # iterate of fips that exist in neutron db for configured_fip in current_fips: if configured_fip['port_id']: # store to later check if this fip has been remapped id_to_current_fip_map[configured_fip['id']] = configured_fip if configured_fip['id'] not in configured_fip_ids: # Ensure that we add only after remove, in case same # fixed_ip is mapped to different floating_ip within # the same loop cycle. If add occurs before first, # cfg will fail because of existing entry with # identical fixed_ip fips_to_add.append(configured_fip) fip_ids_to_remove = configured_fip_ids - current_fip_ids LOG.debug("fip_ids_to_add: %s" % fips_to_add) LOG.debug("fip_ids_to_remove: %s" % fip_ids_to_remove) fips_to_remove = [] fip_statuses = {} # iterate over fips that are configured in device for configured_fip in ri.floating_ips: if configured_fip['id'] in fip_ids_to_remove: fips_to_remove.append(configured_fip) self._floating_ip_removed( ri, ri.ex_gw_port, configured_fip['floating_ip_address'], configured_fip['fixed_ip_address']) fip_statuses[configured_fip['id']] = ( bc.constants.FLOATINGIP_STATUS_DOWN) LOG.debug("Add to fip_statuses DOWN id:%s fl_ip:%s fx_ip:%s", configured_fip['id'], configured_fip['floating_ip_address'], configured_fip['fixed_ip_address']) else: # handle possibly required remapping of a fip # ip address that fip currently is configured for configured_fixed_ip = configured_fip['fixed_ip_address'] new_fip = id_to_current_fip_map[configured_fip['id']] # ip address that fip should be configured for current_fixed_ip = new_fip['fixed_ip_address'] if (current_fixed_ip and configured_fixed_ip and current_fixed_ip != configured_fixed_ip): floating_ip = configured_fip['floating_ip_address'] self._floating_ip_removed(ri, ri.ex_gw_port, floating_ip, configured_fixed_ip) fip_statuses[configured_fip['id']] = ( bc.constants.FLOATINGIP_STATUS_DOWN) fips_to_remove.append(configured_fip) fips_to_add.append(new_fip) for configured_fip in fips_to_remove: # remove fip from "cache" of fips configured in device ri.floating_ips.remove(configured_fip) for configured_fip in fips_to_add: self._floating_ip_added(ri, ex_gw_port, configured_fip['floating_ip_address'], configured_fip['fixed_ip_address']) # add fip to "cache" of fips configured in device ri.floating_ips.append(configured_fip) fip_statuses[configured_fip['id']] = ( bc.constants.FLOATINGIP_STATUS_ACTIVE) LOG.debug("Add to fip_statuses ACTIVE id:%s fl_ip:%s fx_ip:%s", configured_fip['id'], configured_fip['floating_ip_address'], configured_fip['fixed_ip_address']) if fip_statuses: LOG.debug("Sending floatingip_statuses_update: %s", fip_statuses) self.plugin_rpc.update_floatingip_statuses( self.context, ri.router_id, fip_statuses)
[ "def", "_process_router_floating_ips", "(", "self", ",", "ri", ",", "ex_gw_port", ")", ":", "# fips that exist in neutron db (i.e., the desired \"truth\")", "current_fips", "=", "ri", ".", "router", ".", "get", "(", "bc", ".", "constants", ".", "FLOATINGIP_KEY", ",", ...
Process a router's floating ips. Compare floatingips configured in device (i.e., those fips in the ri.floating_ips "cache") with the router's updated floating ips (in ri.router.floating_ips) and determine floating_ips which were added or removed. Notify driver of the change via `floating_ip_added()` or `floating_ip_removed()`. Also update plugin with status of fips. :param ri: RouterInfo object of the router being processed. :param ex_gw_port: Port dict of the external gateway port. :return: None :raises: networking_cisco.plugins.cisco.cfg_agent.cfg_exceptions. DriverException if the configuration operation fails.
[ "Process", "a", "router", "s", "floating", "ips", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py#L1043-L1139
train
37,883
openstack/networking-cisco
networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py
RoutingServiceHelper._router_added
def _router_added(self, router_id, router): """Operations when a router is added. Create a new RouterInfo object for this router and add it to the service helpers router_info dictionary. Then `router_added()` is called on the device driver. :param router_id: id of the router :param router: router dict :return: None """ ri = RouterInfo(router_id, router) driver = self.driver_manager.set_driver(router) if router[ROUTER_ROLE_ATTR] in [ c_constants.ROUTER_ROLE_GLOBAL, c_constants.ROUTER_ROLE_LOGICAL_GLOBAL]: # No need to create a vrf for Global or logical global routers LOG.debug("Skipping router_added device processing for %(id)s as " "its role is %(role)s", {'id': router_id, 'role': router[ROUTER_ROLE_ATTR]}) else: driver.router_added(ri) self.router_info[router_id] = ri
python
def _router_added(self, router_id, router): """Operations when a router is added. Create a new RouterInfo object for this router and add it to the service helpers router_info dictionary. Then `router_added()` is called on the device driver. :param router_id: id of the router :param router: router dict :return: None """ ri = RouterInfo(router_id, router) driver = self.driver_manager.set_driver(router) if router[ROUTER_ROLE_ATTR] in [ c_constants.ROUTER_ROLE_GLOBAL, c_constants.ROUTER_ROLE_LOGICAL_GLOBAL]: # No need to create a vrf for Global or logical global routers LOG.debug("Skipping router_added device processing for %(id)s as " "its role is %(role)s", {'id': router_id, 'role': router[ROUTER_ROLE_ATTR]}) else: driver.router_added(ri) self.router_info[router_id] = ri
[ "def", "_router_added", "(", "self", ",", "router_id", ",", "router", ")", ":", "ri", "=", "RouterInfo", "(", "router_id", ",", "router", ")", "driver", "=", "self", ".", "driver_manager", ".", "set_driver", "(", "router", ")", "if", "router", "[", "ROUT...
Operations when a router is added. Create a new RouterInfo object for this router and add it to the service helpers router_info dictionary. Then `router_added()` is called on the device driver. :param router_id: id of the router :param router: router dict :return: None
[ "Operations", "when", "a", "router", "is", "added", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py#L1141-L1163
train
37,884
openstack/networking-cisco
networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py
RoutingServiceHelper._router_removed
def _router_removed(self, router_id, deconfigure=True): """Operations when a router is removed. Get the RouterInfo object corresponding to the router in the service helpers's router_info dict. If deconfigure is set to True, remove this router's configuration from the hosting device. :param router_id: id of the router :param deconfigure: if True, the router's configuration is deleted from the hosting device. :return: None """ ri = self.router_info.get(router_id) if ri is None: LOG.warning("Info for router %s was not found. " "Skipping router removal.", router_id) return ri.router['gw_port'] = None ri.router[bc.constants.INTERFACE_KEY] = [] ri.router[bc.constants.FLOATINGIP_KEY] = [] try: hd = ri.router['hosting_device'] # We proceed to removing the configuration from the device # only if (a) deconfigure is set to True (default) # (b) the router's hosting device is reachable. if (deconfigure and self._dev_status.is_hosting_device_reachable(hd)): self._process_router(ri) driver = self.driver_manager.get_driver(router_id) driver.router_removed(ri) self.driver_manager.remove_driver(router_id) del self.router_info[router_id] self._del_from_removed_routers_cache(router_id) except cfg_exceptions.DriverException: LOG.warning("Router remove for router_id: %s was incomplete. " "Adding the router to removed_routers list", router_id) self._update_removed_routers_cache([router_id]) # remove this router from updated_routers if it is there. It might # end up there too if exception was thrown earlier inside # `_process_router()` self._del_from_updated_routers_cache(router_id) except ncc_errors.SessionCloseError as e: LOG.exception("ncclient Unexpected session close %s" " while attempting to remove router", e) if not self._dev_status.is_hosting_device_reachable(hd): LOG.debug("Lost connectivity to Hosting Device %s" % hd['id']) # rely on heartbeat to detect HD state # and schedule resync when the device comes back else: # retry the router removal on the next pass self._update_removed_routers_cache([router_id]) LOG.debug("Interim connectivity lost to hosting device %s, " "enqueuing router %s in removed_routers set" % pp.pformat(hd), router_id)
python
def _router_removed(self, router_id, deconfigure=True): """Operations when a router is removed. Get the RouterInfo object corresponding to the router in the service helpers's router_info dict. If deconfigure is set to True, remove this router's configuration from the hosting device. :param router_id: id of the router :param deconfigure: if True, the router's configuration is deleted from the hosting device. :return: None """ ri = self.router_info.get(router_id) if ri is None: LOG.warning("Info for router %s was not found. " "Skipping router removal.", router_id) return ri.router['gw_port'] = None ri.router[bc.constants.INTERFACE_KEY] = [] ri.router[bc.constants.FLOATINGIP_KEY] = [] try: hd = ri.router['hosting_device'] # We proceed to removing the configuration from the device # only if (a) deconfigure is set to True (default) # (b) the router's hosting device is reachable. if (deconfigure and self._dev_status.is_hosting_device_reachable(hd)): self._process_router(ri) driver = self.driver_manager.get_driver(router_id) driver.router_removed(ri) self.driver_manager.remove_driver(router_id) del self.router_info[router_id] self._del_from_removed_routers_cache(router_id) except cfg_exceptions.DriverException: LOG.warning("Router remove for router_id: %s was incomplete. " "Adding the router to removed_routers list", router_id) self._update_removed_routers_cache([router_id]) # remove this router from updated_routers if it is there. It might # end up there too if exception was thrown earlier inside # `_process_router()` self._del_from_updated_routers_cache(router_id) except ncc_errors.SessionCloseError as e: LOG.exception("ncclient Unexpected session close %s" " while attempting to remove router", e) if not self._dev_status.is_hosting_device_reachable(hd): LOG.debug("Lost connectivity to Hosting Device %s" % hd['id']) # rely on heartbeat to detect HD state # and schedule resync when the device comes back else: # retry the router removal on the next pass self._update_removed_routers_cache([router_id]) LOG.debug("Interim connectivity lost to hosting device %s, " "enqueuing router %s in removed_routers set" % pp.pformat(hd), router_id)
[ "def", "_router_removed", "(", "self", ",", "router_id", ",", "deconfigure", "=", "True", ")", ":", "ri", "=", "self", ".", "router_info", ".", "get", "(", "router_id", ")", "if", "ri", "is", "None", ":", "LOG", ".", "warning", "(", "\"Info for router %s...
Operations when a router is removed. Get the RouterInfo object corresponding to the router in the service helpers's router_info dict. If deconfigure is set to True, remove this router's configuration from the hosting device. :param router_id: id of the router :param deconfigure: if True, the router's configuration is deleted from the hosting device. :return: None
[ "Operations", "when", "a", "router", "is", "removed", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py#L1165-L1218
train
37,885
openstack/networking-cisco
networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py
RoutingServiceHelper._routes_updated
def _routes_updated(self, ri): """Update the state of routes in the router. Compares the current routes with the (configured) existing routes and detect what was removed or added. Then configure the logical router in the hosting device accordingly. :param ri: RouterInfo corresponding to the router. :return: None :raises: networking_cisco.plugins.cisco.cfg_agent.cfg_exceptions. DriverException if the configuration operation fails. """ new_routes = ri.router['routes'] old_routes = ri.routes adds, removes = bc.common_utils.diff_list_of_dict(old_routes, new_routes) for route in adds: LOG.debug("Added route entry is '%s'", route) # remove replaced route from deleted route for del_route in removes: if route['destination'] == del_route['destination']: removes.remove(del_route) driver = self.driver_manager.get_driver(ri.id) driver.routes_updated(ri, 'replace', route) for route in removes: LOG.debug("Removed route entry is '%s'", route) driver = self.driver_manager.get_driver(ri.id) driver.routes_updated(ri, 'delete', route) ri.routes = new_routes
python
def _routes_updated(self, ri): """Update the state of routes in the router. Compares the current routes with the (configured) existing routes and detect what was removed or added. Then configure the logical router in the hosting device accordingly. :param ri: RouterInfo corresponding to the router. :return: None :raises: networking_cisco.plugins.cisco.cfg_agent.cfg_exceptions. DriverException if the configuration operation fails. """ new_routes = ri.router['routes'] old_routes = ri.routes adds, removes = bc.common_utils.diff_list_of_dict(old_routes, new_routes) for route in adds: LOG.debug("Added route entry is '%s'", route) # remove replaced route from deleted route for del_route in removes: if route['destination'] == del_route['destination']: removes.remove(del_route) driver = self.driver_manager.get_driver(ri.id) driver.routes_updated(ri, 'replace', route) for route in removes: LOG.debug("Removed route entry is '%s'", route) driver = self.driver_manager.get_driver(ri.id) driver.routes_updated(ri, 'delete', route) ri.routes = new_routes
[ "def", "_routes_updated", "(", "self", ",", "ri", ")", ":", "new_routes", "=", "ri", ".", "router", "[", "'routes'", "]", "old_routes", "=", "ri", ".", "routes", "adds", ",", "removes", "=", "bc", ".", "common_utils", ".", "diff_list_of_dict", "(", "old_...
Update the state of routes in the router. Compares the current routes with the (configured) existing routes and detect what was removed or added. Then configure the logical router in the hosting device accordingly. :param ri: RouterInfo corresponding to the router. :return: None :raises: networking_cisco.plugins.cisco.cfg_agent.cfg_exceptions. DriverException if the configuration operation fails.
[ "Update", "the", "state", "of", "routes", "in", "the", "router", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cfg_agent/service_helpers/routing_svc_helper.py#L1264-L1292
train
37,886
openstack/networking-cisco
networking_cisco/plugins/cisco/cfg_agent/device_drivers/asr1k/asr1k_cfg_syncer.py
ConfigSyncer.subintf_real_ip_check_gw_port
def subintf_real_ip_check_gw_port(self, gw_port, ip_addr, netmask): """ checks running-cfg derived ip_addr and netmask against neutron-db gw_port """ if gw_port is not None: found = False for i in range(len(gw_port['fixed_ips'])): target_ip = gw_port['fixed_ips'][i]['ip_address'] if ip_addr == target_ip: found = True break if found is False: LOG.info("Subintf real IP is incorrect, deleting") return False subnet_id = gw_port['fixed_ips'][i]['subnet_id'] subnet = next( sn for sn in gw_port['subnets'] if sn['id'] == subnet_id) target_net = netaddr.IPNetwork(subnet['cidr']) if netmask != str(target_net.netmask): LOG.info("Subintf has incorrect netmask, deleting") return False return True return False
python
def subintf_real_ip_check_gw_port(self, gw_port, ip_addr, netmask): """ checks running-cfg derived ip_addr and netmask against neutron-db gw_port """ if gw_port is not None: found = False for i in range(len(gw_port['fixed_ips'])): target_ip = gw_port['fixed_ips'][i]['ip_address'] if ip_addr == target_ip: found = True break if found is False: LOG.info("Subintf real IP is incorrect, deleting") return False subnet_id = gw_port['fixed_ips'][i]['subnet_id'] subnet = next( sn for sn in gw_port['subnets'] if sn['id'] == subnet_id) target_net = netaddr.IPNetwork(subnet['cidr']) if netmask != str(target_net.netmask): LOG.info("Subintf has incorrect netmask, deleting") return False return True return False
[ "def", "subintf_real_ip_check_gw_port", "(", "self", ",", "gw_port", ",", "ip_addr", ",", "netmask", ")", ":", "if", "gw_port", "is", "not", "None", ":", "found", "=", "False", "for", "i", "in", "range", "(", "len", "(", "gw_port", "[", "'fixed_ips'", "]...
checks running-cfg derived ip_addr and netmask against neutron-db gw_port
[ "checks", "running", "-", "cfg", "derived", "ip_addr", "and", "netmask", "against", "neutron", "-", "db", "gw_port" ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cfg_agent/device_drivers/asr1k/asr1k_cfg_syncer.py#L900-L925
train
37,887
openstack/networking-cisco
networking_cisco/plugins/cisco/cfg_agent/device_drivers/iosxe/iosxe_routing_driver.py
IosXeRoutingDriver._get_connection
def _get_connection(self): """Make SSH connection to the IOS XE device. The external ncclient library is used for creating this connection. This method keeps state of any existing connections and reuses them if already connected. Also interfaces (except management) are typically disabled by default when it is booted. So if connecting for the first time, driver will enable all other interfaces and keep that status in the `_itfcs_enabled` flag. """ try: if self._ncc_connection and self._ncc_connection.connected: return self._ncc_connection else: # ncclient needs 'name' to be 'csr' in order to communicate # with the device in the correct way. self._ncc_connection = manager.connect( host=self._host_ip, port=self._host_ssh_port, username=self._username, password=self._password, device_params={'name': "csr"}, timeout=self._timeout) if not self._itfcs_enabled: self._itfcs_enabled = self._enable_itfcs( self._ncc_connection) return self._ncc_connection except Exception as e: conn_params = {'host': self._host_ip, 'port': self._host_ssh_port, 'user': self._username, 'timeout': self._timeout, 'reason': e.message} raise cfg_exc.ConnectionException(**conn_params)
python
def _get_connection(self): """Make SSH connection to the IOS XE device. The external ncclient library is used for creating this connection. This method keeps state of any existing connections and reuses them if already connected. Also interfaces (except management) are typically disabled by default when it is booted. So if connecting for the first time, driver will enable all other interfaces and keep that status in the `_itfcs_enabled` flag. """ try: if self._ncc_connection and self._ncc_connection.connected: return self._ncc_connection else: # ncclient needs 'name' to be 'csr' in order to communicate # with the device in the correct way. self._ncc_connection = manager.connect( host=self._host_ip, port=self._host_ssh_port, username=self._username, password=self._password, device_params={'name': "csr"}, timeout=self._timeout) if not self._itfcs_enabled: self._itfcs_enabled = self._enable_itfcs( self._ncc_connection) return self._ncc_connection except Exception as e: conn_params = {'host': self._host_ip, 'port': self._host_ssh_port, 'user': self._username, 'timeout': self._timeout, 'reason': e.message} raise cfg_exc.ConnectionException(**conn_params)
[ "def", "_get_connection", "(", "self", ")", ":", "try", ":", "if", "self", ".", "_ncc_connection", "and", "self", ".", "_ncc_connection", ".", "connected", ":", "return", "self", ".", "_ncc_connection", "else", ":", "# ncclient needs 'name' to be 'csr' in order to c...
Make SSH connection to the IOS XE device. The external ncclient library is used for creating this connection. This method keeps state of any existing connections and reuses them if already connected. Also interfaces (except management) are typically disabled by default when it is booted. So if connecting for the first time, driver will enable all other interfaces and keep that status in the `_itfcs_enabled` flag.
[ "Make", "SSH", "connection", "to", "the", "IOS", "XE", "device", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cfg_agent/device_drivers/iosxe/iosxe_routing_driver.py#L257-L285
train
37,888
openstack/networking-cisco
networking_cisco/plugins/cisco/cfg_agent/device_drivers/iosxe/iosxe_routing_driver.py
IosXeRoutingDriver._get_interfaces
def _get_interfaces(self): """Get a list of interfaces on this hosting device. :return: List of the interfaces """ ios_cfg = self._get_running_config() parse = HTParser(ios_cfg) itfcs_raw = parse.find_lines("^interface GigabitEthernet") itfcs = [raw_if.strip().split(' ')[1] for raw_if in itfcs_raw] LOG.debug("Interfaces on hosting device: %s", itfcs) return itfcs
python
def _get_interfaces(self): """Get a list of interfaces on this hosting device. :return: List of the interfaces """ ios_cfg = self._get_running_config() parse = HTParser(ios_cfg) itfcs_raw = parse.find_lines("^interface GigabitEthernet") itfcs = [raw_if.strip().split(' ')[1] for raw_if in itfcs_raw] LOG.debug("Interfaces on hosting device: %s", itfcs) return itfcs
[ "def", "_get_interfaces", "(", "self", ")", ":", "ios_cfg", "=", "self", ".", "_get_running_config", "(", ")", "parse", "=", "HTParser", "(", "ios_cfg", ")", "itfcs_raw", "=", "parse", ".", "find_lines", "(", "\"^interface GigabitEthernet\"", ")", "itfcs", "="...
Get a list of interfaces on this hosting device. :return: List of the interfaces
[ "Get", "a", "list", "of", "interfaces", "on", "this", "hosting", "device", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cfg_agent/device_drivers/iosxe/iosxe_routing_driver.py#L295-L305
train
37,889
openstack/networking-cisco
networking_cisco/plugins/cisco/cfg_agent/device_drivers/iosxe/iosxe_routing_driver.py
IosXeRoutingDriver._get_interface_ip
def _get_interface_ip(self, interface_name): """Get the ip address for an interface. :param interface_name: interface_name as a string :return: ip address of interface as a string """ ios_cfg = self._get_running_config() parse = HTParser(ios_cfg) children = parse.find_children("^interface %s" % interface_name) for line in children: if 'ip address' in line: ip_address = line.strip().split(' ')[2] LOG.debug("IP Address:%s", ip_address) return ip_address LOG.warning("Cannot find interface: %s", interface_name) return None
python
def _get_interface_ip(self, interface_name): """Get the ip address for an interface. :param interface_name: interface_name as a string :return: ip address of interface as a string """ ios_cfg = self._get_running_config() parse = HTParser(ios_cfg) children = parse.find_children("^interface %s" % interface_name) for line in children: if 'ip address' in line: ip_address = line.strip().split(' ')[2] LOG.debug("IP Address:%s", ip_address) return ip_address LOG.warning("Cannot find interface: %s", interface_name) return None
[ "def", "_get_interface_ip", "(", "self", ",", "interface_name", ")", ":", "ios_cfg", "=", "self", ".", "_get_running_config", "(", ")", "parse", "=", "HTParser", "(", "ios_cfg", ")", "children", "=", "parse", ".", "find_children", "(", "\"^interface %s\"", "%"...
Get the ip address for an interface. :param interface_name: interface_name as a string :return: ip address of interface as a string
[ "Get", "the", "ip", "address", "for", "an", "interface", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cfg_agent/device_drivers/iosxe/iosxe_routing_driver.py#L307-L322
train
37,890
openstack/networking-cisco
networking_cisco/plugins/cisco/cfg_agent/device_drivers/iosxe/iosxe_routing_driver.py
IosXeRoutingDriver._interface_exists
def _interface_exists(self, interface): """Check whether interface exists.""" ios_cfg = self._get_running_config() parse = HTParser(ios_cfg) itfcs_raw = parse.find_lines("^interface " + interface) return len(itfcs_raw) > 0
python
def _interface_exists(self, interface): """Check whether interface exists.""" ios_cfg = self._get_running_config() parse = HTParser(ios_cfg) itfcs_raw = parse.find_lines("^interface " + interface) return len(itfcs_raw) > 0
[ "def", "_interface_exists", "(", "self", ",", "interface", ")", ":", "ios_cfg", "=", "self", ".", "_get_running_config", "(", ")", "parse", "=", "HTParser", "(", "ios_cfg", ")", "itfcs_raw", "=", "parse", ".", "find_lines", "(", "\"^interface \"", "+", "inte...
Check whether interface exists.
[ "Check", "whether", "interface", "exists", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cfg_agent/device_drivers/iosxe/iosxe_routing_driver.py#L324-L329
train
37,891
openstack/networking-cisco
networking_cisco/plugins/cisco/cfg_agent/device_drivers/iosxe/iosxe_routing_driver.py
IosXeRoutingDriver._get_vrfs
def _get_vrfs(self): """Get the current VRFs configured in the device. :return: A list of vrf names as string """ vrfs = [] ios_cfg = self._get_running_config() parse = HTParser(ios_cfg) vrfs_raw = parse.find_lines("^vrf definition") for line in vrfs_raw: # raw format ['ip vrf <vrf-name>',....] vrf_name = line.strip().split(' ')[2] vrfs.append(vrf_name) LOG.info("VRFs:%s", vrfs) return vrfs
python
def _get_vrfs(self): """Get the current VRFs configured in the device. :return: A list of vrf names as string """ vrfs = [] ios_cfg = self._get_running_config() parse = HTParser(ios_cfg) vrfs_raw = parse.find_lines("^vrf definition") for line in vrfs_raw: # raw format ['ip vrf <vrf-name>',....] vrf_name = line.strip().split(' ')[2] vrfs.append(vrf_name) LOG.info("VRFs:%s", vrfs) return vrfs
[ "def", "_get_vrfs", "(", "self", ")", ":", "vrfs", "=", "[", "]", "ios_cfg", "=", "self", ".", "_get_running_config", "(", ")", "parse", "=", "HTParser", "(", "ios_cfg", ")", "vrfs_raw", "=", "parse", ".", "find_lines", "(", "\"^vrf definition\"", ")", "...
Get the current VRFs configured in the device. :return: A list of vrf names as string
[ "Get", "the", "current", "VRFs", "configured", "in", "the", "device", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cfg_agent/device_drivers/iosxe/iosxe_routing_driver.py#L339-L353
train
37,892
openstack/networking-cisco
networking_cisco/plugins/cisco/cfg_agent/device_drivers/iosxe/iosxe_routing_driver.py
IosXeRoutingDriver._get_capabilities
def _get_capabilities(self): """Get the servers NETCONF capabilities. :return: List of server capabilities. """ conn = self._get_connection() capabilities = [] for c in conn.server_capabilities: capabilities.append(c) LOG.debug("Server capabilities: %s", capabilities) return capabilities
python
def _get_capabilities(self): """Get the servers NETCONF capabilities. :return: List of server capabilities. """ conn = self._get_connection() capabilities = [] for c in conn.server_capabilities: capabilities.append(c) LOG.debug("Server capabilities: %s", capabilities) return capabilities
[ "def", "_get_capabilities", "(", "self", ")", ":", "conn", "=", "self", ".", "_get_connection", "(", ")", "capabilities", "=", "[", "]", "for", "c", "in", "conn", ".", "server_capabilities", ":", "capabilities", ".", "append", "(", "c", ")", "LOG", ".", ...
Get the servers NETCONF capabilities. :return: List of server capabilities.
[ "Get", "the", "servers", "NETCONF", "capabilities", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cfg_agent/device_drivers/iosxe/iosxe_routing_driver.py#L355-L365
train
37,893
openstack/networking-cisco
networking_cisco/plugins/cisco/cfg_agent/device_drivers/iosxe/iosxe_routing_driver.py
IosXeRoutingDriver._get_running_config
def _get_running_config(self, split=True): """Get the IOS XE device's current running config. :return: Current IOS running config as multiline string """ conn = self._get_connection() config = conn.get_config(source="running") if config: root = ET.fromstring(config._raw) running_config = root[0][0] if split is True: rgx = re.compile("\r*\n+") ioscfg = rgx.split(running_config.text) else: ioscfg = running_config.text return ioscfg
python
def _get_running_config(self, split=True): """Get the IOS XE device's current running config. :return: Current IOS running config as multiline string """ conn = self._get_connection() config = conn.get_config(source="running") if config: root = ET.fromstring(config._raw) running_config = root[0][0] if split is True: rgx = re.compile("\r*\n+") ioscfg = rgx.split(running_config.text) else: ioscfg = running_config.text return ioscfg
[ "def", "_get_running_config", "(", "self", ",", "split", "=", "True", ")", ":", "conn", "=", "self", ".", "_get_connection", "(", ")", "config", "=", "conn", ".", "get_config", "(", "source", "=", "\"running\"", ")", "if", "config", ":", "root", "=", "...
Get the IOS XE device's current running config. :return: Current IOS running config as multiline string
[ "Get", "the", "IOS", "XE", "device", "s", "current", "running", "config", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cfg_agent/device_drivers/iosxe/iosxe_routing_driver.py#L367-L382
train
37,894
openstack/networking-cisco
networking_cisco/plugins/cisco/cfg_agent/device_drivers/iosxe/iosxe_routing_driver.py
IosXeRoutingDriver._check_acl
def _check_acl(self, acl_no, network, netmask): """Check a ACL config exists in the running config. :param acl_no: access control list (ACL) number :param network: network which this ACL permits :param netmask: netmask of the network :return: """ exp_cfg_lines = ['ip access-list standard ' + str(acl_no), ' permit ' + str(network) + ' ' + str(netmask)] ios_cfg = self._get_running_config() parse = HTParser(ios_cfg) acls_raw = parse.find_children(exp_cfg_lines[0]) if acls_raw: if exp_cfg_lines[1] in acls_raw: return True LOG.error("Mismatch in ACL configuration for %s", acl_no) return False LOG.debug("%s is not present in config", acl_no) return False
python
def _check_acl(self, acl_no, network, netmask): """Check a ACL config exists in the running config. :param acl_no: access control list (ACL) number :param network: network which this ACL permits :param netmask: netmask of the network :return: """ exp_cfg_lines = ['ip access-list standard ' + str(acl_no), ' permit ' + str(network) + ' ' + str(netmask)] ios_cfg = self._get_running_config() parse = HTParser(ios_cfg) acls_raw = parse.find_children(exp_cfg_lines[0]) if acls_raw: if exp_cfg_lines[1] in acls_raw: return True LOG.error("Mismatch in ACL configuration for %s", acl_no) return False LOG.debug("%s is not present in config", acl_no) return False
[ "def", "_check_acl", "(", "self", ",", "acl_no", ",", "network", ",", "netmask", ")", ":", "exp_cfg_lines", "=", "[", "'ip access-list standard '", "+", "str", "(", "acl_no", ")", ",", "' permit '", "+", "str", "(", "network", ")", "+", "' '", "+", "str"...
Check a ACL config exists in the running config. :param acl_no: access control list (ACL) number :param network: network which this ACL permits :param netmask: netmask of the network :return:
[ "Check", "a", "ACL", "config", "exists", "in", "the", "running", "config", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cfg_agent/device_drivers/iosxe/iosxe_routing_driver.py#L384-L403
train
37,895
openstack/networking-cisco
networking_cisco/plugins/cisco/cfg_agent/device_drivers/iosxe/iosxe_routing_driver.py
IosXeRoutingDriver._cfg_exists
def _cfg_exists(self, cfg_str): """Check a partial config string exists in the running config. :param cfg_str: config string to check :return : True or False """ ios_cfg = self._get_running_config() parse = HTParser(ios_cfg) cfg_raw = parse.find_lines("^" + cfg_str) LOG.debug("_cfg_exists(): Found lines %s", cfg_raw) return len(cfg_raw) > 0
python
def _cfg_exists(self, cfg_str): """Check a partial config string exists in the running config. :param cfg_str: config string to check :return : True or False """ ios_cfg = self._get_running_config() parse = HTParser(ios_cfg) cfg_raw = parse.find_lines("^" + cfg_str) LOG.debug("_cfg_exists(): Found lines %s", cfg_raw) return len(cfg_raw) > 0
[ "def", "_cfg_exists", "(", "self", ",", "cfg_str", ")", ":", "ios_cfg", "=", "self", ".", "_get_running_config", "(", ")", "parse", "=", "HTParser", "(", "ios_cfg", ")", "cfg_raw", "=", "parse", ".", "find_lines", "(", "\"^\"", "+", "cfg_str", ")", "LOG"...
Check a partial config string exists in the running config. :param cfg_str: config string to check :return : True or False
[ "Check", "a", "partial", "config", "string", "exists", "in", "the", "running", "config", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cfg_agent/device_drivers/iosxe/iosxe_routing_driver.py#L405-L415
train
37,896
openstack/networking-cisco
networking_cisco/plugins/cisco/cfg_agent/device_drivers/iosxe/iosxe_routing_driver.py
IosXeRoutingDriver._check_response
def _check_response(self, rpc_obj, snippet_name, conf_str=None): """This function checks the rpc response object for status. This function takes as input the response rpc_obj and the snippet name that was executed. It parses it to see, if the last edit operation was a success or not. <?xml version="1.0" encoding="UTF-8"?> <rpc-reply message-id="urn:uuid:81bf8082-....-b69a-000c29e1b85c" xmlns="urn:ietf:params:netconf:base:1.0"> <ok /> </rpc-reply> In case of error, IOS XE device sends a response as follows. We take the error type and tag. <?xml version="1.0" encoding="UTF-8"?> <rpc-reply message-id="urn:uuid:81bf8082-....-b69a-000c29e1b85c" xmlns="urn:ietf:params:netconf:base:1.0"> <rpc-error> <error-type>protocol</error-type> <error-tag>operation-failed</error-tag> <error-severity>error</error-severity> </rpc-error> </rpc-reply> :return: True if the config operation completed successfully :raises: networking_cisco.plugins.cisco.cfg_agent.cfg_exceptions. IOSXEConfigException """ LOG.debug("RPCReply for %(snippet_name)s is %(rpc_obj)s", {'snippet_name': snippet_name, 'rpc_obj': rpc_obj.xml}) xml_str = rpc_obj.xml if "<ok />" in xml_str: # LOG.debug("RPCReply for %s is OK", snippet_name) LOG.info("%s was successfully executed", snippet_name) return True # Not Ok, we throw a ConfigurationException e_type = rpc_obj._root[0][0].text e_tag = rpc_obj._root[0][1].text params = {'snippet': snippet_name, 'type': e_type, 'tag': e_tag, 'dev_id': self.hosting_device['id'], 'ip': self._host_ip, 'confstr': conf_str} raise cfg_exc.IOSXEConfigException(**params)
python
def _check_response(self, rpc_obj, snippet_name, conf_str=None): """This function checks the rpc response object for status. This function takes as input the response rpc_obj and the snippet name that was executed. It parses it to see, if the last edit operation was a success or not. <?xml version="1.0" encoding="UTF-8"?> <rpc-reply message-id="urn:uuid:81bf8082-....-b69a-000c29e1b85c" xmlns="urn:ietf:params:netconf:base:1.0"> <ok /> </rpc-reply> In case of error, IOS XE device sends a response as follows. We take the error type and tag. <?xml version="1.0" encoding="UTF-8"?> <rpc-reply message-id="urn:uuid:81bf8082-....-b69a-000c29e1b85c" xmlns="urn:ietf:params:netconf:base:1.0"> <rpc-error> <error-type>protocol</error-type> <error-tag>operation-failed</error-tag> <error-severity>error</error-severity> </rpc-error> </rpc-reply> :return: True if the config operation completed successfully :raises: networking_cisco.plugins.cisco.cfg_agent.cfg_exceptions. IOSXEConfigException """ LOG.debug("RPCReply for %(snippet_name)s is %(rpc_obj)s", {'snippet_name': snippet_name, 'rpc_obj': rpc_obj.xml}) xml_str = rpc_obj.xml if "<ok />" in xml_str: # LOG.debug("RPCReply for %s is OK", snippet_name) LOG.info("%s was successfully executed", snippet_name) return True # Not Ok, we throw a ConfigurationException e_type = rpc_obj._root[0][0].text e_tag = rpc_obj._root[0][1].text params = {'snippet': snippet_name, 'type': e_type, 'tag': e_tag, 'dev_id': self.hosting_device['id'], 'ip': self._host_ip, 'confstr': conf_str} raise cfg_exc.IOSXEConfigException(**params)
[ "def", "_check_response", "(", "self", ",", "rpc_obj", ",", "snippet_name", ",", "conf_str", "=", "None", ")", ":", "LOG", ".", "debug", "(", "\"RPCReply for %(snippet_name)s is %(rpc_obj)s\"", ",", "{", "'snippet_name'", ":", "snippet_name", ",", "'rpc_obj'", ":"...
This function checks the rpc response object for status. This function takes as input the response rpc_obj and the snippet name that was executed. It parses it to see, if the last edit operation was a success or not. <?xml version="1.0" encoding="UTF-8"?> <rpc-reply message-id="urn:uuid:81bf8082-....-b69a-000c29e1b85c" xmlns="urn:ietf:params:netconf:base:1.0"> <ok /> </rpc-reply> In case of error, IOS XE device sends a response as follows. We take the error type and tag. <?xml version="1.0" encoding="UTF-8"?> <rpc-reply message-id="urn:uuid:81bf8082-....-b69a-000c29e1b85c" xmlns="urn:ietf:params:netconf:base:1.0"> <rpc-error> <error-type>protocol</error-type> <error-tag>operation-failed</error-tag> <error-severity>error</error-severity> </rpc-error> </rpc-reply> :return: True if the config operation completed successfully :raises: networking_cisco.plugins.cisco.cfg_agent.cfg_exceptions. IOSXEConfigException
[ "This", "function", "checks", "the", "rpc", "response", "object", "for", "status", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cfg_agent/device_drivers/iosxe/iosxe_routing_driver.py#L600-L639
train
37,897
openstack/networking-cisco
networking_cisco/apps/saf/server/dfa_instance_api.py
DFAInstanceAPI._get_instances_for_project
def _get_instances_for_project(self, project_id): """Return all instances for a given project. :project_id: UUID of project (tenant) """ search_opts = {'marker': None, 'all_tenants': True, 'project_id': project_id} try: servers = self._novaclnt.servers.list(True, search_opts) LOG.debug('_get_instances_for_project: servers=%s', servers) return servers except nexc.Unauthorized: emsg = (_LE('Failed to get novaclient:Unauthorised ' 'project_id=%(proj)s user=%(user)s'), {'proj': self._project_id, 'user': self._user_name}) LOG.exception(emsg) raise nexc.ClientException(emsg) except nexc.AuthorizationFailure as err: emsg = (_LE("Failed to get novaclient %s")) LOG.exception(emsg, err) raise nexc.ClientException(emsg % err)
python
def _get_instances_for_project(self, project_id): """Return all instances for a given project. :project_id: UUID of project (tenant) """ search_opts = {'marker': None, 'all_tenants': True, 'project_id': project_id} try: servers = self._novaclnt.servers.list(True, search_opts) LOG.debug('_get_instances_for_project: servers=%s', servers) return servers except nexc.Unauthorized: emsg = (_LE('Failed to get novaclient:Unauthorised ' 'project_id=%(proj)s user=%(user)s'), {'proj': self._project_id, 'user': self._user_name}) LOG.exception(emsg) raise nexc.ClientException(emsg) except nexc.AuthorizationFailure as err: emsg = (_LE("Failed to get novaclient %s")) LOG.exception(emsg, err) raise nexc.ClientException(emsg % err)
[ "def", "_get_instances_for_project", "(", "self", ",", "project_id", ")", ":", "search_opts", "=", "{", "'marker'", ":", "None", ",", "'all_tenants'", ":", "True", ",", "'project_id'", ":", "project_id", "}", "try", ":", "servers", "=", "self", ".", "_novacl...
Return all instances for a given project. :project_id: UUID of project (tenant)
[ "Return", "all", "instances", "for", "a", "given", "project", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/dfa_instance_api.py#L65-L86
train
37,898
openstack/networking-cisco
networking_cisco/apps/saf/server/dfa_instance_api.py
DFAInstanceAPI.get_instance_for_uuid
def get_instance_for_uuid(self, uuid, project_id): """Return instance name for given uuid of an instance and project. :uuid: Instance's UUID :project_id: UUID of project (tenant) """ instance_name = self._inst_info_cache.get((uuid, project_id)) if instance_name: return instance_name instances = self._get_instances_for_project(project_id) for inst in instances: if inst.id.replace('-', '') == uuid: LOG.debug('get_instance_for_uuid: name=%s', inst.name) instance_name = inst.name self._inst_info_cache[(uuid, project_id)] = instance_name return instance_name return instance_name
python
def get_instance_for_uuid(self, uuid, project_id): """Return instance name for given uuid of an instance and project. :uuid: Instance's UUID :project_id: UUID of project (tenant) """ instance_name = self._inst_info_cache.get((uuid, project_id)) if instance_name: return instance_name instances = self._get_instances_for_project(project_id) for inst in instances: if inst.id.replace('-', '') == uuid: LOG.debug('get_instance_for_uuid: name=%s', inst.name) instance_name = inst.name self._inst_info_cache[(uuid, project_id)] = instance_name return instance_name return instance_name
[ "def", "get_instance_for_uuid", "(", "self", ",", "uuid", ",", "project_id", ")", ":", "instance_name", "=", "self", ".", "_inst_info_cache", ".", "get", "(", "(", "uuid", ",", "project_id", ")", ")", "if", "instance_name", ":", "return", "instance_name", "i...
Return instance name for given uuid of an instance and project. :uuid: Instance's UUID :project_id: UUID of project (tenant)
[ "Return", "instance", "name", "for", "given", "uuid", "of", "an", "instance", "and", "project", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/dfa_instance_api.py#L88-L104
train
37,899