def create(self, name, port, protocol, nodes, virtualIps): """ Create a new loadbalancer. #TODO: Args """ if not protocol in LB_PROTOCOLS: raise InvalidProtocol("''%s'' is not a valid protocol" % \ (protocol)) nodeDico = [x.toDict() for x in nodes] vipDico = [{ 'id': x.id } if getattr(x, 'id', None) != None else { 'type': x.type } for x in virtualIps] if len(name) > 128: raise InvalidLoadBalancerName("LB name is too long.") body = {"loadBalancer": { "name": name, "port": base.getid(port), "protocol": protocol, "nodes": nodeDico, "virtualIps": vipDico, }} return self._create("/loadbalancers", body, "loadBalancer")
def create(self, name, port, protocol, nodes, virtualIps): """ Create a new loadbalancer. #TODO: Args """ if not protocol in LB_PROTOCOLS: raise InvalidProtocol("''%s'' is not a valid protocol" % \ (protocol)) nodeDico = [x.toDict() for x in nodes] vipDico = [{ 'id': x.id } if getattr(x, 'id', None) != None else { 'type': x.type } for x in virtualIps] if len(name) > 128: raise InvalidLoadBalancerName("LB name is too long.") body = { "loadBalancer": { "name": name, "port": base.getid(port), "protocol": protocol, "nodes": nodeDico, "virtualIps": vipDico, } } return self._create("/loadbalancers", body, "loadBalancer")
def create(self, name, port, protocol, nodes, virtualIps, algorithm='RANDOM'): """ Create a new loadbalancer. #TODO: Args """ if not protocol in LB_PROTOCOLS: raise InvalidProtocol("''%s'' is not a valid protocol" % \ (protocol)) nodeDico = [x.toDict() for x in nodes] vipDico = [x.toDict() for x in virtualIps] if len(name) > 128: raise InvalidLoadBalancerName("LB name is too long.") body = {"loadBalancer": { "name": name, "port": base.getid(port), "protocol": protocol, "nodes": nodeDico, "virtualIps": vipDico, "algorithm": algorithm, }} return self._create("/loadbalancers", body, "loadBalancer")
def create(self, name, port, protocol, nodes, virtualIps, algorithm='RANDOM'): """ Create a new loadbalancer. #TODO: Args """ if not protocol in LB_PROTOCOLS: raise InvalidProtocol("''%s'' is not a valid protocol" % \ (protocol)) nodeDico = [x.toDict() for x in nodes] vipDico = [x.toDict() for x in virtualIps] if len(name) > 128: raise InvalidLoadBalancerName("LB name is too long.") body = { "loadBalancer": { "name": name, "port": base.getid(port), "protocol": protocol, "nodes": nodeDico, "virtualIps": vipDico, "algorithm": algorithm, } } return self._create("/loadbalancers", body, "loadBalancer")
def get_usage(self, startTime=None, endTime=None): startTime = startTime and startTime.isoformat() endTime = endTime and endTime.isoformat() ret = get_usage(self.manager.api.client, lbId=base.getid(self), startTime=startTime, endTime=endTime) return ret
def delete(self, loadbalancerid): """ Delete load balancer. :param loadbalancerid: ID of the :class:`LoadBalancer` to get. :rtype: :class:`LoadBalancer` """ self._delete("/loadbalancers/%s" % base.getid(loadbalancerid))
def get(self, loadbalancerid): """ Get a Load Balancer. :param loadbalancerid: ID of the :class:`LoadBalancer` to get. :rtype: :class:`LoadBalancer` """ return self._get("/loadbalancers/%s.json" % \ base.getid(loadbalancerid), "loadBalancer")
def update(self, lb, originalInfo, info): ret = {} for k in LB_ATTRIBUTES_MODIFIABLE: if k in originalInfo and info[k] != originalInfo[k]: ret[k] = info[k] if 'protocol' in ret.keys() and ret['protocol'] not in LB_PROTOCOLS: raise InvalidProtocol("''%s'' is not a valid protocol" % \ (ret['protocol'])) if not ret: #TODO: proper Exceptions: raise Exception("Nothing to update.") self.api.client.put('/loadbalancers/%s' % base.getid(lb), body=ret)
def update(self, lb, originalInfo, info): ret = {} for k in LB_ATTRIBUTES_MODIFIABLE: if k in info and info[k] != originalInfo.get(k): ret[k] = info[k] if 'protocol' in ret.keys() and ret['protocol'] not in LB_PROTOCOLS: raise InvalidProtocol("''%s'' is not a valid protocol" % \ (ret['protocol'])) if not ret: #TODO: proper Exceptions: raise Exception("Nothing to update.") self.api.client.put('/loadbalancers/%s' % base.getid(lb), body=ret)
def create(self, name, port, protocol, nodes, virtualIps, algorithm='RANDOM', timeout=30, **kwargs): """ Create a new loadbalancer. :param name: Name of the LB to create :param port: Port number for the service you are load balancing :param protocol: Protocol of the service which is being load balanced :param nodes: List of nodes to be added to the LB :param virtualIps: Type of vIP to add with creation of LB :param algorithm: Algorithm that defines how traffic should be directed :param timeout: Timeout (seconds) for unresponsive backend nodes :param kwargs: Name-based arguments for optional LB parameters (such as metadata) :rtype: :class:'LoadBalancer' """ if not protocol in LB_PROTOCOLS: raise InvalidProtocol("''%s'' is not a valid protocol" % \ (protocol)) nodeDico = [x.toDict() for x in nodes] vipDico = [x.toDict() for x in virtualIps] if len(name) > 128: raise InvalidLoadBalancerName("LB name is too long.") body = { "loadBalancer": { "name": name, "port": base.getid(port), "protocol": protocol, "nodes": nodeDico, "virtualIps": vipDico, "algorithm": algorithm, "timeout": timeout } } if kwargs: for key in kwargs: body["loadBalancer"][key] = kwargs[key] return self._create("/loadbalancers", body, "loadBalancer")
def create(self, name, port, protocol, nodes, virtualIps, algorithm='RANDOM', timeout=30, **kwargs): """ Create a new loadbalancer. :param name: Name of the LB to create :param port: Port number for the service you are load balancing :param protocol: Protocol of the service which is being load balanced :param nodes: List of nodes to be added to the LB :param virtualIps: Type of vIP to add with creation of LB :param algorithm: Algorithm that defines how traffic should be directed :param timeout: Timeout (seconds) for unresponsive backend nodes :param kwargs: Name-based arguments for optional LB parameters (such as metadata) :rtype: :class:'LoadBalancer' """ if not protocol in LB_PROTOCOLS: raise InvalidProtocol("''%s'' is not a valid protocol" % \ (protocol)) nodeDico = [x.toDict() for x in nodes] vipDico = [x.toDict() for x in virtualIps] if len(name) > 128: raise InvalidLoadBalancerName("LB name is too long.") body = {"loadBalancer": { "name": name, "port": base.getid(port), "protocol": protocol, "nodes": nodeDico, "virtualIps": vipDico, "algorithm": algorithm, "timeout": timeout }} if kwargs: for key in kwargs: body["loadBalancer"][key] = kwargs[key] return self._create("/loadbalancers", body, "loadBalancer")
def delete_node(self, loadBalancerId, nodeId): self.api.client.delete('/loadbalancers/%d/nodes/%d' % ( base.getid(loadBalancerId), base.getid(nodeId), ))
def add_nodes(self, loadBalancerId, nodes): nodeDico = [x.toDict() for x in nodes] resp, body = self.api.client.post('/loadbalancers/%d/nodes' % ( base.getid(loadBalancerId) ), body={"nodes": nodeDico}) return (resp, body)
def add_nodes(self, loadBalancerId, nodes): nodeDico = [x.toDict() for x in nodes] resp, body = self.api.client.post('/loadbalancers/%d/nodes' % (base.getid(loadBalancerId)), body={"nodes": nodeDico}) return (resp, body)
def get_stats(self): stats = Stats(self.manager.api.client, base.getid(self)) return stats.get()
def ssl_termination(self): sslt = SSLTermination(self.manager.api.client, base.getid(self)) return sslt
def errorpage(self): errorpage = ErrorPage(self.manager.api.client, base.getid(self)) return errorpage
def session_persistence(self): sm = SessionPersistenceManager( self.manager.api.client, base.getid(self)) return sm
def connection_logging(self): cm = ConnectionLogging( self.manager.api.client, base.getid(self)) return cm
def accesslist(self): accesslist = AccessList(self.manager.api.client, base.getid(self)) return accesslist
def add_nodes(self, loadbalancerId, nodes): nodeDico = [x.toDict() for x in nodes] self._action('nodes', "%d/nodes" % base.getid(loadbalancerId), \ nodeDico)
def update_node(self, loadBalancerId, nodeId, dico): self.api.client.put('/loadbalancers/%d/nodes/%d' % ( base.getid(loadBalancerId), base.getid(nodeId), ), body={"node": dico})
def healthmonitor(self): hm = HealthMonitorManager(self.manager.api.client, base.getid(self)) return hm
def session_persistence(self): sm = SessionPersistenceManager(self.manager.api.client, base.getid(self)) return sm
def connection_logging(self): cm = ConnectionLogging(self.manager.api.client, base.getid(self)) return cm
def connection_throttling(self): ctm = ConnectionThrottleManager( self.manager.api.client, base.getid(self), ) return ctm