Commit 0f71407a authored by Thiago Paiva's avatar Thiago Paiva
Browse files

PEP8 fixes

parent b4dc5b52
......@@ -41,7 +41,7 @@ class NotificationEndpoint(object):
super(NotificationEndpoint, self).__init__()
self.nova_client = nova_client.Client(
'2',
auth_url=CONF.keystone_authtoken.auth_url ,
auth_url=CONF.keystone_authtoken.auth_url,
username=CONF.keystone_authtoken.username,
password=CONF.keystone_authtoken.password,
project_name=CONF.keystone_authtoken.project_name,
......@@ -83,6 +83,7 @@ class Waker(NotificationEndpoint):
# publisher_id='^compute.*',
event_type='^compute\.instance\.create\.end$',
)
def info(self, ctxt, publisher_id, event_type, payload, metadata):
LOG.debug("\n\nINFO")
LOG.debug(publisher_id)
......@@ -90,9 +91,11 @@ class Waker(NotificationEndpoint):
LOG.debug(payload)
if self.cloud_over_thresholds():
hypervisors = self.nova_client.hypervisors.list()
empty_servers = [hyp for hyp in hypervisors if hyp.running_vms == 0 and
hyp.state == "up" and
hyp.status == "enabled"]
empty_servers = [
hyp for hyp in hypervisors if hyp.running_vms == 0 and
hyp.state == "up" and
hyp.status == "enabled"
]
for server in empty_servers:
stats = self.nova_client.hypervisors.statistics()
new_vcpus = stats.vcpus - server.vcpus
......@@ -125,9 +128,12 @@ class Morpheus(NotificationEndpoint):
LOG.debug(payload)
if not self.cloud_over_thresholds():
hypervisors = self.nova_client.hypervisors.list()
empty_servers = [hyp for hyp in hypervisors if hyp.running_vms == 0 and
hyp.state == "up" and
hyp.status == "enabled"]
empty_servers = [
hyp for hyp in hypervisors
if hyp.running_vms == 0 and
hyp.state == "up" and
hyp.status == "enabled"
]
for server in empty_servers:
stats = self.nova_client.hypervisors.statistics()
new_vcpus = stats.vcpus - server.vcpus
......@@ -144,31 +150,9 @@ class Morpheus(NotificationEndpoint):
self.sleep_server(server)
def sleep_server(self, server):
LOG.info("Suspending %s [ip: %s]" %(server.hypervisor_hostname, server.host_ip))
os.system("systemctl --host=root@%s suspend" %server.host_ip)
class OpenStackClient:
def __init__(self, os_auth_url, os_username, os_password, os_tenant_name):
self.session = None
self.os_auth_url = os_auth_url
self.os_username = os_username
self.os_password = os_password
self.os_tenant_name = os_tenant_name
def get_session(self):
if self.session is None:
loader = loading.get_plugin_loader('password')
auth = loader.load_from_options()
self.session = session.Session(auth=auth, verify=False)
return self.session
def nova(self):
sess = self.get_session()
return nova
LOG.info("Suspending %s [ip: %s]" % (server.hypervisor_hostname,
server.host_ip))
os.system("systemctl --host=root@%s suspend" % server.host_ip)
if __name__ == "__main__":
......@@ -176,20 +160,26 @@ if __name__ == "__main__":
transport = oslo_messaging.get_notification_transport(CONF)
targets = [
oslo_messaging.Target(topic='notifications', exchange="/nova"),
oslo_messaging.Target(topic='versioned_notifications', exchange="/nova"),
oslo_messaging.Target(
topic='notifications',
exchange="/nova"
),
oslo_messaging.Target(
topic='versioned_notifications',
exchange="/nova"
),
]
endpoints = [
Morpheus(),
Waker(),
]
pool = "autonomic-listener"
server = oslo_messaging.get_notification_listener(
transport,
transport,
targets,
endpoints,
executor='threading',
executor='threading',
# pool=pool
)
server.start()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment