Ejemplo n.º 1
0
    def add_health_monitor(self, lb: LoadBalancer):
        """Adds a Health monitor to a Pool with default settings

        Args:
            lb (LoadBalancer): An OSLoadBalancer instance.
        """

        if not self.id:
            raise ValidationError("need pool id to create health monitor")
        self.verify()
        lb.add_health_monitor(self.id, f"{self.name}-health")
Ejemplo n.º 2
0
def test_loadbalancer_with_invalid_subnet():
    lb = LoadBalancer(CONFIG, MagicMock())
    assert lb.subnet_name == CONFIG['private_net']['subnet']['name']

    config = copy.deepcopy(CONFIG)
    del config['private_net']
    print(config)
    lb = LoadBalancer(config, MagicMock())

    assert lb
    assert lb.subnet_name is None
Ejemplo n.º 3
0
    def add_members(self, lb: LoadBalancer):
        """Adds Members to a Pool.

        Args:
            lb (LoadBalancer): An OSLoadBalancer instance.
        """

        if not self.id:
            raise ValidationError("need pool id to add members")
        self.verify()

        for ip in self.members:
            lb.add_member(self.id, ip, self.port)
Ejemplo n.º 4
0
def test_create_loadbalancer():
    conn = get_connection()

    # All good
    lb = LoadBalancer(CONFIG, conn)
    assert lb
    assert isinstance(lb, LoadBalancer)
Ejemplo n.º 5
0
def test_create_loadbalancer_with_floating():
    """ test loadbalancer with floating ip """
    config = copy.deepcopy(CONFIG)
    fip = "1.2.3.4"
    config['loadbalancer'] = {"floatingip": fip}
    lb = LoadBalancer(config, MagicMock())
    assert lb
    assert lb.floatingip == fip
Ejemplo n.º 6
0
    def create(self, lb: LoadBalancer, listener_id):
        """Creates a Pool and adds it to a Listener.

        This function will set the attributes ``pool`` and ``id``.

        Args:
            lb (LoadBalancer): An OSLoadBalancer instance.
            listener_id (str): The Listener ID this pool should be added to.
        """

        self.verify()
        pool = lb.add_pool(listener_id=listener_id,
                           lb_algorithm=self.algorithm,
                           protocol=self.protocol,
                           name=self.name)
        self.id = pool.id
        self.pool = pool
Ejemplo n.º 7
0
def remove_cluster(config, nova, neutron, cinder, conn):
    """Delete a cluster from OpenStack"""

    cluster_info = OSClusterInfo(nova, neutron, cinder, config, conn)
    masters = cluster_info.get_instances("node")
    workers = cluster_info.get_instances("master")

    tasks = [host.delete(neutron) for host in masters if host]
    tasks += [host.delete(neutron) for host in workers if host]
    if tasks:
        LOGGER.debug("Deleting Instances ...")
        loop = asyncio.get_event_loop()
        loop.run_until_complete(asyncio.wait(tasks))
        loop.close()

    LoadBalancer(config, conn).delete()

    sg_name = '%s-sec-group' % config['cluster-name']
    secg = conn.list_security_groups({"name": sg_name})
    if secg:
        LOGGER.debug("Deleting SecurityGroup %s ...", sg_name)
        for sg in secg:
            for rule in sg.security_group_rules:
                conn.delete_security_group_rule(rule['id'])

            for port in conn.list_ports():
                if sg.id in port.security_groups:
                    conn.delete_port(port.id)
    conn.delete_security_group(sg_name)

    # This needs to be replaced with OpenStackAPI in the future
    for vol in cinder.volumes.list():
        try:
            if config['cluster-name'] in vol.name and vol.status != 'in-use':
                try:
                    vol.delete()
                except (BadRequest, NotFound):
                    pass

        except TypeError:
            continue

    # delete the cluster key pair
    conn.delete_keypair(config['cluster-name'])
Ejemplo n.º 8
0
def get_os(scope="function"):
    conn = MagicMock()
    lb = LoadBalancer(CONFIG, conn)
    lb._data = default_data()
    lb._id = lb._data.id
    return conn, lb
Ejemplo n.º 9
0
def test_create_loadbalancer_no_floating():
    """ test loadbalancer without floating ip """
    lb = LoadBalancer(CONFIG, MagicMock())
    assert lb
    assert lb.floatingip is None
        'name': 'koris-test-net',
        'subnet': {
            'name': 'test-subnet',
            'cidr': '192.168.0.0/16'
        }
    },
    'loadbalancer': {
        'floatingip': False
    }
}

CONN = OpenStackAPI.connect()
NET = OSNetwork(config, CONN).get_or_create()
SUBNET = OSSubnet(CLIENT, NET['id'], config).get_or_create()
OSRouter(CLIENT, NET['id'], SUBNET, config).get_or_create()
LB = LoadBalancer(config, CONN)


def create_and_configure():
    """
    create and configure a load-balancer in oneshot, in real life
    we postpone the configuration to a later stage.
    """

    loop = asyncio.get_event_loop()
    LB.create()

    master_ips = ['192.168.0.103', '192.168.0.104', '192.168.0.105']
    node_ips = ['192.168.0.120', '192.168.0.121']

    configure_lb_task = loop.create_task(LB.configure(master_ips))