Service API prototype

This commit is contained in:
Ilya Shakhat 2016-08-09 11:04:09 +03:00
parent 9724ce8af7
commit e89a1aefce
5 changed files with 69 additions and 16 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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__':