• CLI

sdk
  1. Help Center
  2. CLI
  3. Developer Guide
  4. SDK
  5. Python
  6. ELB Python SDK Demo

ELB Python SDK Demo

Creating a Load Balancer

You can create a load balancer using the Python OpenStack SDK based on the following code:

def create_load_balancer(self, **attrs):      
    """Create a new load balancer from attributes
     
    :param dict attrs: Keyword arguments which will be used to create        a :class:`~openstack.load_balancer.v1.load_balancer.LoadBalancer`,
        comprised of the properties on the LoadBalancer class.           :returns: a asynchronous LoadBalancer job      
    :rtype: :class:`~openstack.load_balancer.v1.load_balancer.                          LoadBalancerJob`      
    """
    return self._create(_lb.LoadBalancerJob, prepend_key=False, **attrs)

Creating a Listener

You can create a listener using the Python OpenStack SDK based on the following code. A listener can be created only when a load balancer is available.

def create_listener(self, **attrs):
    """Create a new listener from attributes

    :param dict attrs: Keyword arguments which will be used to create
        a :class:`~openstack.load_balancer.v1.listener.Listener`,
        comprised of the properties on the Listener class.

    :returns: a listener instance
    :rtype: :class:`~openstack.load_balancer.v1.listener.Listener`
    """
    return self._create(_listener.Listener, prepend_key=False, **attrs)

Performing a Health Check

You can perform a health check using the Python OpenStack SDK based on the following code. The health check can be performed only when a listener is available.

def create_health_check(self, **attrs):
    """Create a new health check from attributes

    :param dict attrs: Keyword arguments which will be used to create
        a :class:`~openstack.load_balancer.v1.health_check.HealthCheck`,
        comprised of the properties on the HealthCheck class.

    :returns: A health check instance
    :rtype: `:class: ~openstack.load_balancer.v1.health_check.HealthCheck`
    """
    return self._create(_hc.HealthCheck, prepend_key=False, **attrs)

Adding Members

You can add members to a listener using the Python OpenStack SDK based on the following code:

def add_members_to_listener(self, listener, members):
    """Add backend members for a listener

    :param listener: Either the ID of a listener or an instance of
            :class:`~openstack.load_balancer.v1.listener.Listener`
    :param members: list of dicts which contain the server_id and address.
        server_id is ECS service id, address is ECS server internal IP.
        [{"server_id": "dbecb618-2259-405f-ab17-9b68c4f541b0",
          "address": "172.16.0.31"}] for example.

    :return: a operate member job
    :rtype: :class:`~openstack.load_balancer.v1.listener.OperateMemberJob`
    """
    listener = self._get_resource(_listener.Listener, listener)
    return listener.add_members(self._session, members)

Creating a Certificate

You can create a certificate using the Python OpenStack SDK based on the following code:

def create_certificate(self, **attrs):
    """Create a new certificate from attributes
    
    :param dict attrs: Keyword arguments which will be used to create        a :class:`~openstack.certificate.v1.certificate.Certificate`,        comprised of the properties on the Certificate class.        
    :returns: a certificate instance      
    :rtype: :class:`~openstack.certificate.v1.certificate.Certificate`   """
    return self._create(_cert.Certificate, prepend_key=False, **attrs)