@@ -92,28 +92,30 @@ def update_lb_health_monitors(self, uuid, checks):
9292 def get_lbaas_uuid_id (self , identifier ):
9393 """Gets a LBaaS uuid, id. Since sometimes you need one or the other.
9494
95- :param identifier: either the LB Id, or UUID , this function will return both .
95+ :param identifier: either the LB Id, UUID or Name , this function will return UUI and LB Id .
9696 :return (uuid, id):
9797 """
98- # int objects don't have a len property.
99- if not isinstance (identifier , int ) and len (identifier ) == 36 :
100- this_lb = self .lbaas .getLoadBalancer (identifier , mask = "mask[id,uuid]" )
98+ mask = "mask[id,uuid]"
99+ if isinstance (identifier , int ):
100+ this_lb = self .lbaas .getObject (id = identifier , mask = mask )
101+ elif len (identifier ) == 36 and utils .UUID_RE .match (identifier ):
102+ this_lb = self .lbaas .getLoadBalancer (identifier , mask = mask )
101103 else :
102- this_lb = self .lbaas .getObject (id = identifier , mask = "mask[id,uuid]" )
104+ this_lb = self .get_lbaas_by_name (identifier , mask = mask )
105+
103106 return this_lb .get ('uuid' ), this_lb .get ('id' )
104107
105- def get_lbaas_by_address (self , address ):
106- """Gets a LBaaS by address .
108+ def get_lbaas_by_name (self , name , mask = None ):
109+ """Gets a LBaaS by name .
107110
108- :param address: Address of the LBaaS instance
111+ :param name: Name of the LBaaS instance
112+ :param mask:
113+ :returns: SoftLayer_Network_LBaaS_LoadBalancer or an empty dictionary if the name is not found.
109114 """
110- this_lb = {}
111- this_lbs = self .lbaas .getAllObjects ()
112- for lbaas in this_lbs :
113- if lbaas .get ('address' ) == address :
114- this_lb = lbaas
115- break
116- return this_lb
115+ object_filter = {'name' : {'operation' : name }}
116+ this_lbs = self .lbaas .getAllObjects (filter = object_filter , mask = mask )
117+
118+ return this_lbs [0 ] if this_lbs else {}
117119
118120 def delete_lb_member (self , identifier , member_id ):
119121 """Removes a member from a LBaaS instance
@@ -210,7 +212,7 @@ def order_lbaas(self, datacenter, name, desc, protocols, subnet_id, public=False
210212 'description' : desc ,
211213 'location' : datacenter ,
212214 'packageId' : package .get ('id' ),
213- 'useHourlyPricing' : True , # Required since LBaaS is an hourly service
215+ 'useHourlyPricing' : True , # Required since LBaaS is an hourly service
214216 'prices' : [{'id' : price_id } for price_id in prices ],
215217 'protocolConfigurations' : protocols ,
216218 'subnets' : [{'id' : subnet_id }],
0 commit comments