diff --git a/os_failures/api/client.py b/os_failures/api/client.py index 6d19576..b799722 100644 --- a/os_failures/api/client.py +++ b/os_failures/api/client.py @@ -5,5 +5,9 @@ class Client(object): __metaclass__ = abc.ABCMeta @abc.abstractmethod - def get_cloud(self): + def get_nodes(self): + pass + + @abc.abstractmethod + def get_services(self, name): pass diff --git a/os_failures/api/node.py b/os_failures/api/node.py index 2249a54..705fe14 100644 --- a/os_failures/api/node.py +++ b/os_failures/api/node.py @@ -1,17 +1,17 @@ import abc -class Node(object): +class NodeCollection(object): __metaclass__ = abc.ABCMeta @abc.abstractmethod - def kill_process(self, group): + def kill_process(self): pass @abc.abstractmethod - def oom(self, group): + def oom(self): pass @abc.abstractmethod - def reboot(self, group): + def reboot(self): pass diff --git a/os_failures/api/service_collection.py b/os_failures/api/service_collection.py new file mode 100644 index 0000000..47b7af3 --- /dev/null +++ b/os_failures/api/service_collection.py @@ -0,0 +1,13 @@ +import abc + + +class ServiceCollection(object): + __metaclass__ = abc.ABCMeta + + @abc.abstractmethod + def get_nodes(self): + pass + + @abc.abstractmethod + def stop(self): + pass diff --git a/os_failures/drivers/fuel.py b/os_failures/drivers/fuel.py index 2679dee..97b3a2e 100644 --- a/os_failures/drivers/fuel.py +++ b/os_failures/drivers/fuel.py @@ -1,6 +1,9 @@ +import json + from os_failures.ansible import runner from os_failures.api import client -from os_failures.api import cloud +from os_failures.api import node +from os_failures.api import service_collection ROLE_MAPPING = { @@ -8,13 +11,35 @@ ROLE_MAPPING = { } -class FuelCloud(cloud.Cloud): - - def __init__(self, client): +class FuelNodes(node.NodeCollection): + def __init__(self, client=None, collection=None): self.client = client - def get_nodes(self, role): - fuel_role = ROLE_MAPPING[role] + def reboot(self): + print('Reboot!') + + def oom(self): + print('OOM!') + + def kill_process(self): + print('PS') + + +class FuelService(service_collection.ServiceCollection): + + def __init__(self, client=None, name=None): + self.client = client + self.name = name + + def get_nodes(self): + if self.name == 'keystone-api': + nodes = self.client.get_fuel_nodes() + controllers = [n for n in nodes if 'controller' in n['roles']] + return FuelNodes(client=self.client, collection=controllers) + pass + + def stop(self): + super(FuelService, self).stop() class FuelClient(client.Client): @@ -27,7 +52,8 @@ class FuelClient(client.Client): remote_user=self.username) task = {'command': 'fuel2 node list -f json'} - nodes = self.ansible_executor.execute([self.ip], task) + nodes_s = self.ansible_executor.execute([self.ip], task) + nodes = json.loads(nodes_s[0]['payload']['stdout']) print(nodes) self.ansible_executor = runner.AnsibleRunner( @@ -36,5 +62,14 @@ class FuelClient(client.Client): task = {'command': 'hostname'} print(self.ansible_executor.execute(['10.20.0.3', '10.20.0.4'], task)) - def get_cloud(self): - return FuelCloud(self) + def get_fuel_nodes(self): + task = {'command': 'fuel2 node list -f json'} + nodes_s = self.ansible_executor.execute([self.ip], task) + nodes = json.loads(nodes_s[0]['payload']['stdout']) + return nodes + + def get_nodes(self): + pass + + def get_services(self, name): + return FuelService(client=self, name=name) diff --git a/os_failures/tests/sample.py b/os_failures/tests/sample.py index 48545f8..2424f54 100644 --- a/os_failures/tests/sample.py +++ b/os_failures/tests/sample.py @@ -30,8 +30,9 @@ def main(): } } client = os_failures.build_client(cloud_config) - cloud = client.get_cloud() - keystone_nodes = cloud.get_nodes(role='keystone-api') + services = client.get_services(name='keystone-api') + print(services) + services.get_nodes().reboot() if __name__ == '__main__':