Service API prototype
This commit is contained in:
parent
9724ce8af7
commit
e89a1aefce
@ -5,5 +5,9 @@ class Client(object):
|
|||||||
__metaclass__ = abc.ABCMeta
|
__metaclass__ = abc.ABCMeta
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def get_cloud(self):
|
def get_nodes(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abc.abstractmethod
|
||||||
|
def get_services(self, name):
|
||||||
pass
|
pass
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
import abc
|
import abc
|
||||||
|
|
||||||
|
|
||||||
class Node(object):
|
class NodeCollection(object):
|
||||||
__metaclass__ = abc.ABCMeta
|
__metaclass__ = abc.ABCMeta
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def kill_process(self, group):
|
def kill_process(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def oom(self, group):
|
def oom(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def reboot(self, group):
|
def reboot(self):
|
||||||
pass
|
pass
|
||||||
|
13
os_failures/api/service_collection.py
Normal file
13
os_failures/api/service_collection.py
Normal 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
|
@ -1,6 +1,9 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
from os_failures.ansible import runner
|
from os_failures.ansible import runner
|
||||||
from os_failures.api import client
|
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 = {
|
ROLE_MAPPING = {
|
||||||
@ -8,13 +11,35 @@ ROLE_MAPPING = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class FuelCloud(cloud.Cloud):
|
class FuelNodes(node.NodeCollection):
|
||||||
|
def __init__(self, client=None, collection=None):
|
||||||
def __init__(self, client):
|
|
||||||
self.client = client
|
self.client = client
|
||||||
|
|
||||||
def get_nodes(self, role):
|
def reboot(self):
|
||||||
fuel_role = ROLE_MAPPING[role]
|
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):
|
class FuelClient(client.Client):
|
||||||
@ -27,7 +52,8 @@ class FuelClient(client.Client):
|
|||||||
remote_user=self.username)
|
remote_user=self.username)
|
||||||
|
|
||||||
task = {'command': 'fuel2 node list -f json'}
|
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)
|
print(nodes)
|
||||||
|
|
||||||
self.ansible_executor = runner.AnsibleRunner(
|
self.ansible_executor = runner.AnsibleRunner(
|
||||||
@ -36,5 +62,14 @@ class FuelClient(client.Client):
|
|||||||
task = {'command': 'hostname'}
|
task = {'command': 'hostname'}
|
||||||
print(self.ansible_executor.execute(['10.20.0.3', '10.20.0.4'], task))
|
print(self.ansible_executor.execute(['10.20.0.3', '10.20.0.4'], task))
|
||||||
|
|
||||||
def get_cloud(self):
|
def get_fuel_nodes(self):
|
||||||
return FuelCloud(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)
|
||||||
|
@ -30,8 +30,9 @@ def main():
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
client = os_failures.build_client(cloud_config)
|
client = os_failures.build_client(cloud_config)
|
||||||
cloud = client.get_cloud()
|
services = client.get_services(name='keystone-api')
|
||||||
keystone_nodes = cloud.get_nodes(role='keystone-api')
|
print(services)
|
||||||
|
services.get_nodes().reboot()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user