From: Sumit Naiksatam Date: Sat, 20 Aug 2011 05:02:16 +0000 (-0700) Subject: pylint and pep8 fixes. X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=cd405409b4c765782f4e22f8085dc239fcf3ce47;p=openstack-build%2Fneutron-build.git pylint and pep8 fixes. --- diff --git a/quantum/plugins/cisco/l2network_plugin_configuration.py b/quantum/plugins/cisco/l2network_plugin_configuration.py index acbca503b..45eadd172 100644 --- a/quantum/plugins/cisco/l2network_plugin_configuration.py +++ b/quantum/plugins/cisco/l2network_plugin_configuration.py @@ -46,6 +46,9 @@ MAX_NETWORKS = SECTION_CONF['max_networks'] SECTION_CONF = CONF_PARSER_OBJ['MODEL'] MODEL_CLASS = SECTION_CONF['model_class'] +SECTION_CONF = CONF_PARSER_OBJ['SEGMENTATION'] +MANAGER_CLASS = SECTION_CONF['manager_class'] + CONF_FILE = "conf/plugins.ini" CONF_PARSER_OBJ = confp.\ diff --git a/quantum/plugins/cisco/l2network_segmentation_base.py b/quantum/plugins/cisco/l2network_segmentation_base.py index d7b4378b8..081d50fdf 100644 --- a/quantum/plugins/cisco/l2network_segmentation_base.py +++ b/quantum/plugins/cisco/l2network_segmentation_base.py @@ -56,7 +56,7 @@ class L2NetworkSegmentationMgrBase(object): marked with the abstractmethod decorator is provided by the plugin class. """ - if cls is L2NetworkSegementationMgrBase: + if cls is L2NetworkSegmentationMgrBase: for method in cls.__abstractmethods__: method_ok = False for base in klass.__mro__: diff --git a/quantum/plugins/cisco/models/l2network_multi_blade.py b/quantum/plugins/cisco/models/l2network_multi_blade.py index c5ba157d2..fb68c5ec5 100644 --- a/quantum/plugins/cisco/models/l2network_multi_blade.py +++ b/quantum/plugins/cisco/models/l2network_multi_blade.py @@ -21,12 +21,13 @@ import inspect import logging as LOG +import platform from quantum.common import utils from quantum.plugins.cisco.l2network_model_base import L2NetworkModelBase from quantum.plugins.cisco import l2network_plugin_configuration as conf from quantum.plugins.cisco.common import cisco_constants as const -from quantum.plugins.cisco.ucs import cisco_ucs_inventory as ucsinv +from quantum.plugins.cisco.ucs import cisco_ucs_inventory as ucsinv LOG.basicConfig(level=LOG.WARN) LOG.getLogger(const.LOGGER_COMPONENT_NAME) @@ -130,8 +131,8 @@ class L2NetworkMultiBlade(L2NetworkModelBase): device_params = \ {const.DEVICE_IP: rsvd_info[const.UCSM_IP], const.UCS_INVENTORY: self._ucs_inventory, - const.CHASSIS_ID: rsvd_info[const.const.CHASSIS_ID], - const.BLADE_ID: rsvd_info[const.const.BLADE_ID], + const.CHASSIS_ID: rsvd_info[const.CHASSIS_ID], + const.BLADE_ID: rsvd_info[const.BLADE_ID], const.BLADE_INTF_DN: rsvd_info[const.BLADE_INTF_DN]} self._invoke_ucs_plugin(self._func_name(), args, device_params) @@ -167,4 +168,3 @@ class L2NetworkMultiBlade(L2NetworkModelBase): vif_desc = {const.VIF_DESC: {const.DEVICENAME: "eth2", const.UCSPROFILE: "default"}} return vif_desc - diff --git a/quantum/plugins/cisco/models/l2network_single_blade.py b/quantum/plugins/cisco/models/l2network_single_blade.py index 286f5c7dd..b4277af1a 100644 --- a/quantum/plugins/cisco/models/l2network_single_blade.py +++ b/quantum/plugins/cisco/models/l2network_single_blade.py @@ -21,6 +21,7 @@ import inspect import logging as LOG +import platform from quantum.common import utils from quantum.plugins.cisco.l2network_model_base import L2NetworkModelBase @@ -136,4 +137,3 @@ class L2NetworkSinlgeBlade(L2NetworkModelBase): vif_desc = {const.VIF_DESC: {const.DEVICENAME: "eth2", const.UCSPROFILE: "default"}} return vif_desc - diff --git a/quantum/plugins/cisco/segmentation/l2network_vlan_mgr.py b/quantum/plugins/cisco/segmentation/l2network_vlan_mgr.py index 427ab690f..533b488d5 100644 --- a/quantum/plugins/cisco/segmentation/l2network_vlan_mgr.py +++ b/quantum/plugins/cisco/segmentation/l2network_vlan_mgr.py @@ -21,7 +21,6 @@ import logging as LOG -from quantum.common import utils from quantum.plugins.cisco.common import cisco_constants as const from quantum.plugins.cisco.db import l2network_db as cdb from quantum.plugins.cisco.l2network_segmentation_base \ @@ -30,6 +29,7 @@ from quantum.plugins.cisco.l2network_segmentation_base \ LOG.basicConfig(level=LOG.WARN) LOG.getLogger(const.LOGGER_COMPONENT_NAME) + class L2NetworkVLANMgr(L2NetworkSegmentationMgrBase): """ VLAN Manager which gets VLAN ID from DB @@ -39,9 +39,7 @@ class L2NetworkVLANMgr(L2NetworkSegmentationMgrBase): """Get an available VLAN ID""" return cdb.reserve_vlanid() - def release_segmentation_id(self, tenant_id, net_id, **kwargs): """Release the ID""" vlan_binding = cdb.get_vlan_binding(net_id) return cdb.release_vlanid(vlan_binding[const.VLANID]) - diff --git a/quantum/plugins/cisco/ucs/cisco_ucs_inventory.py b/quantum/plugins/cisco/ucs/cisco_ucs_inventory.py index a272c0ae0..ddc5eff3c 100644 --- a/quantum/plugins/cisco/ucs/cisco_ucs_inventory.py +++ b/quantum/plugins/cisco/ucs/cisco_ucs_inventory.py @@ -1,3 +1,4 @@ +""" # vim: tabstop=4 shiftwidth=4 softtabstop=4 # # Copyright 2011 Cisco Systems, Inc. All rights reserved. @@ -16,7 +17,7 @@ # # @author: Sumit Naiksatam, Cisco Systems, Inc. # - +""" import logging as LOG from quantum.common import exceptions as exc @@ -38,7 +39,12 @@ The _inventory data strcuture contains a nested disctioary: } """ + class UCSInventory(object): + """ + Manages the state of all the UCS chasses, and blades in + the system + """ _inventory = {} _host_names = {} @@ -102,13 +108,13 @@ class UCSInventory(object): return blade_data def get_all_ucsms(self): + """Get the IPs of all the UCSMs in the system""" return self._inventory.keys() def reload_inventory(self): """Reload the inventory from a conf file""" self._load_inventory() - pass - + def build_inventory_state(self): """Populate the state of all the blades""" for ucsm_ip in self._inventory.keys(): @@ -195,7 +201,8 @@ class UCSInventory(object): const.BLADE_INTF_RESERVED blade_intf_data[blade_intf][const.TENANTID] = tenant_id blade_intf_data[blade_intf][const.PORTID] = port_id - blade_intf_data[blade_intf][const.PROFILEID] = portprofile_name + blade_intf_data[blade_intf][const.PROFILE_ID] = \ + portprofile_name blade_intf_data[blade_intf][const.INSTANCE_ID] = None dev_eth_name = blade_intf_data[blade_intf] \ [const.BLADE_INTF_RHEL_DEVICE_NAME] @@ -253,14 +260,14 @@ class UCSInventory(object): blade_intf_info = {const.UCSM_IP: ucsm_ip, const.CHASSIS_ID: chassis_id, const.BLADE_ID: blade_id, - const.BLADE_INTF_DN: + const.BLADE_INTF_DN: interface_dn} return blade_intf_info return None def get_host_name(self, tenant_id, instance_id): """ - Return the hostname of the blade with a reserved instance + Return the hostname of the blade with a reserved instance for this tenant """ for ucsm_ip in self._inventory_state.keys(): @@ -324,7 +331,8 @@ def main(): print "No more unreserved blades\n" break - least_reserved_blade_ucsm = reserved_blade_dict[const.LEAST_RSVD_BLADE_UCSM] + least_reserved_blade_ucsm = \ + reserved_blade_dict[const.LEAST_RSVD_BLADE_UCSM] least_reserved_blade_chassis = \ reserved_blade_dict[const.LEAST_RSVD_BLADE_CHASSIS] least_reserved_blade_id = \ @@ -336,7 +344,7 @@ def main(): least_reserved_blade_chassis, least_reserved_blade_id, least_reserved_blade_data, - "demo") + "demo", "12345", "profilename") if reserved_nic_dict: reserved_intf_nic_info = {const.RESERVED_INTERFACE_UCSM: least_reserved_blade_ucsm, diff --git a/quantum/plugins/cisco/ucs/cisco_ucs_network_driver.py b/quantum/plugins/cisco/ucs/cisco_ucs_network_driver.py index dfb7839f2..2a1e38042 100644 --- a/quantum/plugins/cisco/ucs/cisco_ucs_network_driver.py +++ b/quantum/plugins/cisco/ucs/cisco_ucs_network_driver.py @@ -125,7 +125,7 @@ GET_BLADE_INTERFACE = "" + \ " " + \ " " @@ -218,88 +218,61 @@ class CiscoUCSMDriver(): data = DELETE_PROFILE.replace(PROFILE_NAME, profile_name) return data - def _get_next_dynamic_nic(self): - """Get an avaialble dynamic nic on the host""" - dynamic_nic_id = gvif.get_next_dynic() - if len(dynamic_nic_id) > 0: - return dynamic_nic_id - else: - raise cexc.NoMoreNics() - def _get_blade_interfaces_post_data(self, chassis_number, blade_number): + """Create command""" data = GET_BLADE_INTERFACES.replace(CHASSIS_VALUE, chassis_number) data = data.replace(BLADE_VALUE, blade_number) return data - - def _get_blade_interface_state_post_data(self, blade_dn): + + def _get_blade_intf_st_post_data(self, blade_dn): + """Create command""" data = GET_BLADE_INTERFACE_STATE.replace(BLADE_DN_VALUE, blade_dn) return data - + def _get_blade_interfaces(self, chassis_number, blade_number, ucsm_ip, ucsm_username, ucsm_password): + """Create command""" data = self._get_blade_interfaces_post_data(chassis_number, blade_number) response = self._post_data(ucsm_ip, ucsm_username, ucsm_password, data) - """ - print("***Sumit: ucsmp_ip %s ucsm_username %s ucsm_password %s data %s \ - response %s") % (ucsm_ip, ucsm_username, ucsm_password, data, - response) - """ elements = \ et.XML(response).find("outConfigs").findall("adaptorHostEthIf") - bladeInterfaces = {} + blade_interfaces = {} for element in elements: - dn = element.get("dn", default=None) - if dn: + dist_name = element.get("dn", default=None) + if dist_name: order = element.get("order", default=None) - bladeInterface = {const.BLADE_INTF_DN: dn, + blade_interface = {const.BLADE_INTF_DN: dist_name, const.BLADE_INTF_ORDER: order, const.BLADE_INTF_LINK_STATE: None, const.BLADE_INTF_OPER_STATE: None, const.BLADE_INTF_INST_TYPE: None, const.BLADE_INTF_RHEL_DEVICE_NAME: self._get_rhel_device_name(order)} - bladeInterfaces[dn] = bladeInterface + blade_interfaces[dist_name] = blade_interface - return bladeInterfaces + return blade_interfaces - def _get_blade_interface_state(self, bladeIntf, ucsm_ip, + def _get_blade_interface_state(self, blade_intf, ucsm_ip, ucsm_username, ucsm_password): + """Create command""" data = \ - self._get_blade_interface_state_post_data(bladeIntf[const.BLADE_INTF_DN]) + self._get_blade_intf_st_post_data(blade_intf[const.BLADE_INTF_DN]) response = self._post_data(ucsm_ip, ucsm_username, ucsm_password, data) elements = \ et.XML(response).find("outConfigs").findall("dcxVIf") for element in elements: - bladeIntf[const.BLADE_INTF_LINK_STATE] = element.get("linkState", + blade_intf[const.BLADE_INTF_LINK_STATE] = element.get("linkState", default=None) - bladeIntf[const.BLADE_INTF_OPER_STATE] = element.get("operState", + blade_intf[const.BLADE_INTF_OPER_STATE] = element.get("operState", default=None) - bladeIntf[const.BLADE_INTF_INST_TYPE] = element.get("instType", + blade_intf[const.BLADE_INTF_INST_TYPE] = element.get("instType", default=None) def _get_rhel_device_name(self, order): - deviceName = const.RHEL_DEVICE_NAME_REPFIX + str(int(order) - 1) - return deviceName - - def _get_dynamic_interface(self, chassis_number, blade_number, - ucsm_ip,ucsm_username, - ucsm_password): - bladeInterfaces = client._get_blade_interfaces(chassis_number, - blade_number, - ucsm_ip, - ucsm_username, - ucsm_password) - for bladeIntf in bladeInterfaces.values(): - client._get_blade_interface_state(bladeIntf, ucsm_ip, - ucsm_username, ucsm_password) - if bladeIntf[const.BLADE_INTF_INST_TYPE] == \ - const.BLADE_INTF_DYNAMIC and \ - bladeIntf[const.BLADE_INTF_LINK_STATE] == \ - const.BLADE_INTF_STATE_UNKNOWN and \ - bladeIntf[const.BLADE_INTF_OPER_STATE] == \ - const.BLADE_INTF_STATE_UNKNOWN: - return bladeIntf + """Get the device name as on the RHEL host""" + device_name = const.RHEL_DEVICE_NAME_REPFIX + str(int(order) - 1) + return device_name def create_vlan(self, vlan_name, vlan_id, ucsm_ip, ucsm_username, ucsm_password): @@ -325,39 +298,26 @@ class CiscoUCSMDriver(): new_vlan_name) self._post_data(ucsm_ip, ucsm_username, ucsm_password, data) - def get_dynamic_nic(self, host): - """Get an avaialble dynamic nic on the host""" - # TODO (Sumit): Check availability per host - # TODO (Sumit): If not available raise exception - # TODO (Sumit): This simple logic assumes that create-port and - # spawn-VM happens in lock-step - # But we should support multiple create-port calls, - # followed by spawn-VM calls - # That would require managing a pool of available - # dynamic vnics per host - dynamic_nic_name = self._get_next_dynamic_nic() - LOG.debug("Reserving dynamic nic %s" % dynamic_nic_name) - return dynamic_nic_name - def get_blade_data(self, chassis_number, blade_number, - ucsm_ip,ucsm_username, + ucsm_ip, ucsm_username, ucsm_password): """ Returns only the dynamic interfaces on the blade """ - bladeInterfaces = self._get_blade_interfaces(chassis_number, + blade_interfaces = self._get_blade_interfaces(chassis_number, blade_number, ucsm_ip, ucsm_username, ucsm_password) - for bladeIntf in bladeInterfaces.keys(): - self._get_blade_interface_state(bladeInterfaces[bladeIntf], ucsm_ip, - ucsm_username, ucsm_password) - if bladeInterfaces[bladeIntf][const.BLADE_INTF_INST_TYPE] != \ + for blade_intf in blade_interfaces.keys(): + self._get_blade_interface_state(blade_interfaces[blade_intf], + ucsm_ip, ucsm_username, + ucsm_password) + if blade_interfaces[blade_intf][const.BLADE_INTF_INST_TYPE] != \ const.BLADE_INTF_DYNAMIC: - bladeInterfaces.pop(bladeIntf) + blade_interfaces.pop(blade_intf) - return bladeInterfaces + return blade_interfaces def delete_vlan(self, vlan_name, ucsm_ip, ucsm_username, ucsm_password): """Create request for UCSM""" @@ -369,8 +329,3 @@ class CiscoUCSMDriver(): """Create request for UCSM""" data = self._delete_profile_post_data(profile_name) self._post_data(ucsm_ip, ucsm_username, ucsm_password, data) - - def release_dynamic_nic(self, host): - """Release a reserved dynamic nic on the host""" - # TODO (Sumit): Release on a specific host - pass diff --git a/quantum/plugins/cisco/ucs/cisco_ucs_plugin.py b/quantum/plugins/cisco/ucs/cisco_ucs_plugin.py index d2f85fef7..3268fbcb3 100644 --- a/quantum/plugins/cisco/ucs/cisco_ucs_plugin.py +++ b/quantum/plugins/cisco/ucs/cisco_ucs_plugin.py @@ -150,7 +150,7 @@ class UCSVICPlugin(L2DevicePluginBase): ucs_inventory.reserve_blade_interface(self._ucsm_ip, chassis_id, blade_id, blade_data_dict, tenant_id, port_id, - portprofile_name) + profile_name) return new_port_dict def delete_port(self, tenant_id, net_id, port_id, **kwargs): @@ -163,8 +163,8 @@ class UCSVICPlugin(L2DevicePluginBase): LOG.debug("UCSVICPlugin:delete_port() called\n") self._set_ucsm(kwargs[const.DEVICE_IP]) ucs_inventory = kwargs[const.UCS_INVENTORY] - chassis_id = kwargs[const.const.CHASSIS_ID] - blade_id = kwargs[const.const.BLADE_ID] + chassis_id = kwargs[const.CHASSIS_ID] + blade_id = kwargs[const.BLADE_ID] interface_dn = kwargs[const.BLADE_INTF_DN] port = self._get_port(tenant_id, net_id, port_id) if port[const.ATTACHMENT]: @@ -179,7 +179,7 @@ class UCSVICPlugin(L2DevicePluginBase): port_profile[const.PROFILE_NAME]) net = self._get_network(tenant_id, net_id) net[const.NET_PORTS].pop(port_id) - ucs_inventory.unreserve_blade_interface(ucsm_ip, chassis_id, + ucs_inventory.unreserve_blade_interface(self._ucsm_ip, chassis_id, blade_id, interface_dn) except KeyError: raise exc.PortNotFound(net_id=net_id, port_id=port_id) @@ -321,7 +321,7 @@ class UCSVICPlugin(L2DevicePluginBase): self._port_profile_counter -= 1 def _set_ucsm(self, ucsm_ip): + """Set the UCSM IP, username, and password""" self._ucsm_ip = ucsm_ip self._ucsm_username = cred.Store.getUsername(conf.UCSM_IP_ADDRESS) self._ucsm_password = cred.Store.getPassword(conf.UCSM_IP_ADDRESS) -