-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Akshat Akshat <[email protected]>
- Loading branch information
1 parent
15f7064
commit 36da01a
Showing
23 changed files
with
2,085 additions
and
39 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from chaoslib.types import Configuration, Secrets | ||
from oci.load_balancer import LoadBalancerClient | ||
|
||
from chaosoci import oci_client | ||
from chaosoci.types import OCIResponse | ||
|
||
__all__ = ["delete_backend_server", "delete_backend_set", | ||
"delete_hostname", "delete_listener", | ||
"delete_load_balancer", "delete_routing_policy", | ||
"delete_path_route_set"] | ||
|
||
|
||
# Compute Client Actions | ||
|
||
def delete_backend_server(load_balancer_id: str, | ||
backend_set_name: str, | ||
backend_name: str, | ||
configuration: Configuration = None, | ||
secrets: Secrets = None) -> OCIResponse: | ||
"""Delete a given backend server""" | ||
|
||
client = oci_client(LoadBalancerClient, configuration, secrets, | ||
skip_deserialization=True) | ||
delete_backend_response = client.delete_backend(load_balancer_id, backend_name, backend_set_name).data | ||
|
||
return delete_backend_response | ||
|
||
|
||
def delete_backend_set(load_balancer_id: str, | ||
backend_set_name: str, | ||
configuration: Configuration = None, | ||
secrets: Secrets = None) -> OCIResponse: | ||
"""Delete a given backend set""" | ||
client = oci_client(LoadBalancerClient, configuration, secrets, | ||
skip_deserialization=False) | ||
|
||
delete_backend_set_response = client.delete_backend_set(load_balancer_id, backend_set_name).data | ||
|
||
return delete_backend_set_response | ||
|
||
|
||
# Compute Client Management Actions | ||
|
||
def delete_hostname(load_balancer_id: str, | ||
load_balancer_name: str, | ||
configuration: Configuration = None, | ||
secrets: Secrets = None) -> OCIResponse: | ||
"""Delete a given hostname""" | ||
|
||
client = oci_client(LoadBalancerClient, configuration, secrets, | ||
skip_deserialization=True) | ||
|
||
delete_hostname_response = client.delete_hostname(load_balancer_id, load_balancer_name).data | ||
|
||
return delete_hostname_response | ||
|
||
|
||
def delete_listener(listener_id: str, | ||
listener_name: str, | ||
configuration: Configuration = None, | ||
secrets: Secrets = None) -> OCIResponse: | ||
"""Delete a given LB Listener""" | ||
|
||
client = oci_client(LoadBalancerClient, configuration, secrets, | ||
skip_deserialization=True) | ||
|
||
delete_listener_response = client.delete_listener(listener_id, listener_name).data | ||
|
||
return delete_listener_response | ||
|
||
|
||
def delete_load_balancer(load_balancer_id: str, | ||
configuration: Configuration = None, | ||
secrets: Secrets = None) -> OCIResponse: | ||
"""Delete a given Load Balancer""" | ||
|
||
client = oci_client(LoadBalancerClient, configuration, secrets, | ||
skip_deserialization=True) | ||
|
||
delete_load_balancer_response = client.delete_load_balancer(load_balancer_id).data | ||
|
||
return delete_load_balancer_response | ||
|
||
|
||
def delete_path_route_set(load_balancer_id: str, | ||
path_route_set_name: str, | ||
configuration: Configuration = None, | ||
secrets: Secrets = None) -> OCIResponse: | ||
"""Delete a given set path route""" | ||
|
||
client = oci_client(LoadBalancerClient, configuration, secrets, | ||
skip_deserialization=True) | ||
|
||
delete_path_route_set_response = client.delete_path_route_set(load_balancer_id, path_route_set_name).data | ||
|
||
return delete_path_route_set_response | ||
|
||
|
||
def delete_routing_policy(load_balancer_id: str, | ||
routing_policy_name: str, | ||
configuration: Configuration = None, | ||
secrets: Secrets = None) -> OCIResponse: | ||
"""Delete a given routing policy""" | ||
|
||
client = oci_client(LoadBalancerClient, configuration, secrets, | ||
skip_deserialization=True) | ||
|
||
delete_routing_policy_response = client.delete_routing_policy(load_balancer_id, routing_policy_name).data | ||
|
||
return delete_routing_policy_response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# -*- coding: utf-8 -*- | ||
__all__ = ["get_load_balancers", "filter_load_balancers", "get_backend_sets"] | ||
|
||
from typing import Any, Dict, List | ||
|
||
from chaoslib.exceptions import ActivityFailed | ||
|
||
from logzero import logger | ||
|
||
from oci.core import ComputeClient, ComputeManagementClient | ||
from oci.core.models import Instance, InstancePool | ||
from oci.load_balancer import LoadBalancerClient | ||
from oci.load_balancer.models import LoadBalancer | ||
|
||
|
||
def get_load_balancers(client: LoadBalancerClient = None, | ||
compartment_id: str = None) -> List[Instance]: | ||
"""Return a complete, unfiltered list of instances in the compartment.""" | ||
load_bals = [] | ||
|
||
load_bals_raw = client.list_load_balancers(compartment_id=compartment_id) | ||
load_bals.extend(load_bals_raw.data) | ||
while load_bals_raw.has_next_page: | ||
load_bals_raw = client.list_load_balancers(compartment_id=compartment_id, | ||
page=load_bals_raw.next_page) | ||
load_bals.extend(load_bals_raw.data) | ||
|
||
return load_bals | ||
|
||
|
||
def filter_load_balancers(load_bals: List[LoadBalancer] = None, | ||
filters: Dict[str, Any] = None) -> List[LoadBalancer]: | ||
"""Return only those load_bals that match the filters provided.""" | ||
load_bals = load_bals or None | ||
|
||
if load_bals is None: | ||
raise ActivityFailed('No load_bals were found.') | ||
|
||
filters_set = {x for x in filters} | ||
available_filters_set = {x for x in load_bals[0].attribute_map} | ||
|
||
# Partial filtering may return load_bals we do not want. We avoid it. | ||
if not filters_set.issubset(available_filters_set): | ||
raise ActivityFailed('Some of the chosen filters were not found,' | ||
' we cannot continue.') | ||
|
||
# Walk the load_bals and find those that match the given filters. | ||
filtered = [] | ||
for load_bal in load_bals: | ||
sentinel = True | ||
for attr, val in filters.items(): | ||
if val != getattr(load_bal, attr, None): | ||
sentinel = False | ||
break | ||
|
||
if sentinel: | ||
filtered.append(load_bal) | ||
|
||
return filtered | ||
|
||
|
||
def get_backend_sets(client: LoadBalancerClient = None, | ||
loadbalancer_id: str = None) -> List[Instance]: | ||
"""Return a complete, unfiltered list of instances in the compartment.""" | ||
backend_set = [] | ||
|
||
backend_set_raw = client.list_backend_sets(load_balancer_id=loadbalancer_id) | ||
backend_set.extend(backend_set_raw.data) | ||
while backend_set_raw.has_next_page: | ||
backend_set_raw = client.list_backend_sets(load_balancer_id=loadbalancer_id, | ||
page=backend_set_raw.next_page) | ||
backend_set.extend(backend_set_raw.data) | ||
|
||
return backend_set |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# -*- coding: utf-8 -*- | ||
from typing import Any, Dict, List | ||
|
||
from chaoslib.exceptions import ActivityFailed | ||
from chaoslib.types import Configuration, Secrets | ||
|
||
from oci.config import from_file | ||
from oci.core import ComputeClient, ComputeManagementClient | ||
|
||
from chaosoci import oci_client | ||
|
||
from .common import get_load_balancers, get_backend_sets, filter_load_balancers | ||
|
||
__all__ = ['count_load_bal', 'count_backend_sets'] | ||
|
||
|
||
def count_load_bal(filters: List[Dict[str, Any]], compartment_id: str = None, | ||
configuration: Configuration = None, | ||
secrets: Secrets = None) -> int: | ||
""" | ||
Return the number of instances in accordance with the given filters. | ||
Please refer to: https://oracle-cloud-infrastructure-python-sdk.readthedocs.io/en/latest/api/core/models/oci.core.models.Instance.html#oci.core.models.Instance | ||
for details on the available filters under the 'parameters' section. | ||
""" # noqa: E501 | ||
compartment_id = compartment_id or from_file().get('compartment') | ||
|
||
if compartment_id is None: | ||
raise ActivityFailed('We have not been able to find a compartment,' | ||
' without one, we cannot continue.') | ||
|
||
client = oci_client(ComputeClient, configuration, secrets, | ||
skip_deserialization=False) | ||
|
||
filters = filters or None | ||
instances = get_load_balancers(client, compartment_id) | ||
|
||
if filters is not None: | ||
return len(filter_load_balancers(instances, filters=filters)) | ||
|
||
return len(instances) | ||
|
||
|
||
def count_backend_sets(filters: List[Dict[str, Any]], loadbalancer_id: str = None, | ||
configuration: Configuration = None, | ||
secrets: Secrets = None) -> int: | ||
|
||
loadbalancer_id = loadbalancer_id or from_file().get('load_balancer') | ||
|
||
if loadbalancer_id is None: | ||
raise ActivityFailed('We have not been able to find a compartment,' | ||
' without one, we cannot continue.') | ||
|
||
client = oci_client(ComputeClient, configuration, secrets, | ||
skip_deserialization=False) | ||
|
||
filters = filters or None | ||
backend_sets = get_backend_sets(client, loadbalancer_id) | ||
|
||
if filters is not None: | ||
return len(filter_load_balancers(backend_sets, filters=filters)) | ||
|
||
return len(backend_sets) |
Oops, something went wrong.