Commit 85d8ea68 authored by Thiago Paiva's avatar Thiago Paiva
Browse files

Changing from suspend to power off

parent 8168672a
......@@ -31,6 +31,7 @@ CONF = cfg.CONF
CONF.register_opts(AUTH_OPTS, group="keystone_authtoken")
CONF.register_opts(THRESH_OPTS, group="thresholds")
SERVERS_FILE = "./servers.yml"
# Define a default handler at INFO logging level
logging.basicConfig(level=logging.DEBUG)
......@@ -113,7 +114,7 @@ class Waker(NotificationEndpoint):
self.wake_up_server(server)
def wake_up_server(self, server):
with open(servers_file, 'r') as y:
with open(SERVERS_FILE, 'r') as y:
server_data_dict = yaml.load(y)
for s_name, s_data in server_data_dict.items():
......@@ -125,7 +126,7 @@ class Waker(NotificationEndpoint):
username = s_data.get("username")
password = s_data.get("password")
cmd = ("ipmitool -I lanplus -H %s -U %s -P %s power soft"
cmd = ("ipmitool -I lanplus -H %s -U %s -P %s power on"
% (mgmt_if_addr, username, password))
os.system(cmd)
......@@ -165,9 +166,21 @@ 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)
with open(SERVERS_FILE, 'r') as y:
server_data_dict = yaml.load(y)
for s_name, s_data in server_data_dict.items():
s_data = s_data[0]
if s_data.get("hostname") != server.hypervisor_hostname:
continue
mgmt_if_addr = s_data.get("mgmt_if_addr")
username = s_data.get("username")
password = s_data.get("password")
cmd = ("ipmitool -I lanplus -H %s -U %s -P %s power off"
% (mgmt_if_addr, username, password))
os.system(cmd)
if __name__ == "__main__":
......
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