in libcloud/loadbalancer/drivers/rackspace.py [0:0]
def _to_balancer(self, el):
ip = None
port = None
sourceAddresses = {}
if "port" in el:
port = el["port"]
if "sourceAddresses" in el:
sourceAddresses = el["sourceAddresses"]
extra = {
"ipv6PublicSource": sourceAddresses.get("ipv6Public"),
"ipv4PublicSource": sourceAddresses.get("ipv4Public"),
"ipv4PrivateSource": sourceAddresses.get("ipv4Servicenet"),
"service_name": self.connection.get_service_name(),
"uri": "https://%s%s/loadbalancers/%s"
% (self.connection.host, self.connection.request_path, el["id"]),
}
if "virtualIps" in el:
ip = el["virtualIps"][0]["address"]
extra["virtualIps"] = el["virtualIps"]
if "protocol" in el:
extra["protocol"] = el["protocol"]
if "algorithm" in el and el["algorithm"] in self._VALUE_TO_ALGORITHM_MAP:
extra["algorithm"] = self._value_to_algorithm(el["algorithm"])
if "healthMonitor" in el:
health_monitor = self._to_health_monitor(el)
if health_monitor:
extra["healthMonitor"] = health_monitor
if "connectionThrottle" in el:
extra["connectionThrottle"] = self._to_connection_throttle(el)
if "sessionPersistence" in el:
persistence = el["sessionPersistence"]
extra["sessionPersistenceType"] = persistence.get("persistenceType")
if "connectionLogging" in el:
logging = el["connectionLogging"]
extra["connectionLoggingEnabled"] = logging.get("enabled")
if "nodes" in el:
extra["members"] = self._to_members(el)
if "created" in el:
extra["created"] = self._iso_to_datetime(el["created"]["time"])
if "updated" in el:
extra["updated"] = self._iso_to_datetime(el["updated"]["time"])
if "accessList" in el:
extra["accessList"] = [self._to_access_rule(rule) for rule in el["accessList"]]
return LoadBalancer(
id=el["id"],
name=el["name"],
state=self.LB_STATE_MAP.get(el["status"], State.UNKNOWN),
ip=ip,
port=port,
driver=self.connection.driver,
extra=extra,
)