Commit 958a5f58 authored by Thiago Paiva's avatar Thiago Paiva
Browse files

PEP8 fixes + package structure

parent 7e9c2645
venv
actuator.conf
servers.yml
*.pyc
/venv
/lib
/local
/include
/pip-selfcheck.json
dist/
build/
*.egg-info/
.tox/
.eggs/
.coverage
*.swp
.idea*
.project
.pydevproject
myhost1.lsd.ufcg.edu.br:
- hostname: myhost1
mgmt_if_addr: 10.0.0.1
username: myuser
password: mypass
myhost2.lsd.ufcg.edu.br:
- hostname: myhost2
mgmt_if_addr: 10.0.0.2
username: myuser
password: "myquotedpassspeci@llyifthereispecialchar$"
#notusingthishost.lsd.ufcg.edu.br:
# - hostname: notusingthishost
# mgmt_if_addr: 10.0.0.254
# username: myuser
# password: UPPERCASECHARSAREOK
\ No newline at end of file
[metadata]
name = autonomic-actuator
summary = Lenovo Autonomic Datacenter Actuator
description-file =
README.md
author = Autonomic Lenovo
author-email = thiagop@lsd.ufcg.edu.br
home-page = https://git.lsd.ufcg.edu.br/lenovo-autonomic/autonomic-actuator
classifier =
Intended Audience :: Developers
License :: OSI Approved :: BSD License
Operating System :: POSIX :: Linux
Development Status :: 4 - Beta',
Programming Language :: Python',
Programming Language :: Python :: 2
Programming Language :: Python :: 3
Topic :: Software Development :: Libraries :: Python Modules
[files]
packages =
src
[pbr]
warnerrors = True
[wheel]
universal = 1
# Copyright 2017 Universidade Federal de Campina Grande
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""
Project to execute experiments and get data from them.
"""
import setuptools
# In python < 2.7.4, a lazy loading of package `pbr` will break
# setuptools if some other modules registered functions in `atexit`.
# solution from: http://bugs.python.org/issue15881#msg170215
try:
import multiprocessing # noqa
except ImportError:
pass
setuptools.setup(
setup_requires=['pbr'],
pbr=True)
import json
# Copyright 2017 Universidade Federal de Campina Grande
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import logging
import os
import yaml
from novaclient import client as nova_client
from oslo_config import cfg
import oslo_messaging
import yaml
LOG = logging.getLogger(__name__)
......@@ -79,11 +93,10 @@ class NotificationEndpoint(object):
stats.vcpus -= server.vcpus
stats.free_ram_mb -= server.free_ram_mb
stats.free_disk_gb -= server.free_disk_gb
LOG.info("Corrected stats: %s" %str(stats.__dict__))
return stats
LOG.info("Corrected stats: %s" % str(stats.__dict__))
return stats
def cloud_over_thresholds(self):
stats = self.get_corrected_stats()
......@@ -115,7 +128,7 @@ class Waker(NotificationEndpoint):
if not self.cloud_over_thresholds():
LOG.info("Starting wake up procedure...")
slept_servers = self.nova_client.hypervisors.findall(
state= "down",
state="down",
status="enabled"
)
......@@ -135,7 +148,8 @@ class Waker(NotificationEndpoint):
LOG.info("")
LOG.info("")
LOG.info("======================================")
LOG.info("Waking up server: %s" % server.hypervisor_hostname)
LOG.info("Waking up server: %s"
% server.hypervisor_hostname)
LOG.info("new_vcpus: %s" % new_vcpus)
LOG.info("new_free_ram_mb: %s" % new_free_ram_mb)
LOG.info("new_free_disk_gb: %s" % new_free_disk_gb)
......@@ -145,24 +159,26 @@ class Waker(NotificationEndpoint):
self.wake_up_server(server)
def wake_up_server(self, server):
LOG.info("'%s' selected for wake up." %server.hypervisor_hostname)
LOG.info("'%s' selected for wake up." % server.hypervisor_hostname)
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_name != server.hypervisor_hostname:
LOG.info("IPMI config for '%s' not found on servers.yml" %server.hypervisor_hostname)
LOG.info("IPMI config for '%s' not found on servers.yml"
% server.hypervisor_hostname)
continue
LOG.info("Found IPMI conf for '%s'" %server.hypervisor_hostname)
LOG.info("Found IPMI conf for '%s'"
% server.hypervisor_hostname)
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 on"
% (mgmt_if_addr, username, password))
LOG.info("Powering on '%s'" %server.hypervisor_hostname)
LOG.info("Powering on '%s'" % server.hypervisor_hostname)
os.system(cmd)
......@@ -181,10 +197,10 @@ class Morpheus(NotificationEndpoint):
LOG.info("Start looking for servers to shutdown...")
empty_servers = self.nova_client.hypervisors.findall(
running_vms=0,
state= "up",
state="up",
status="enabled"
)
for server in empty_servers:
stats = self.get_corrected_stats()
new_vcpus = stats.vcpus - stats.vcpus_used - server.vcpus
......@@ -201,7 +217,8 @@ class Morpheus(NotificationEndpoint):
LOG.info("")
LOG.info("")
LOG.info("======================================")
LOG.info("Shutting down server: %s" % server.hypervisor_hostname)
LOG.info("Shutting down server: %s"
% server.hypervisor_hostname)
LOG.info("new_vcpus: %s" % new_vcpus)
LOG.info("new_free_ram_mb: %s" % new_free_ram_mb)
LOG.info("new_free_disk_gb: %s" % new_free_disk_gb)
......@@ -212,23 +229,26 @@ class Morpheus(NotificationEndpoint):
def sleep_server(self, server):
with open(SERVERS_FILE, 'r') as y:
LOG.info("'%s' selected for shutdown." %server.hypervisor_hostname)
LOG.info("'%s' selected for shutdown."
% server.hypervisor_hostname)
server_data_dict = yaml.load(y)
for s_name, s_data in server_data_dict.items():
s_data = s_data[0]
if s_name != server.hypervisor_hostname:
LOG.info("IPMI config for '%s' not found on servers.yml" %server.hypervisor_hostname)
LOG.info("IPMI config for '%s' not found on servers.yml"
% server.hypervisor_hostname)
continue
LOG.info("Found IPMI conf for '%s'" %server.hypervisor_hostname)
LOG.info("Found IPMI conf for '%s'"
% server.hypervisor_hostname)
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))
LOG.info("Shutting down '%s'" %server.hypervisor_hostname)
LOG.info("Shutting down '%s'" % server.hypervisor_hostname)
os.system(cmd)
......
flake8>=2.5.4,<2.6.0 # MIT
flake8-import-order==0.11 # LGPLv3
'''
Created on 19/12/2017
@author: thiagop
'''
import unittest
class TestNotificationEndpoint(unittest.TestCase):
def test_cloud_over_thresholds(self):
self.fail("TODO")
def test_get_corrected_stats(self):
self.fail("TODO")
class TestWaker(unittest.TestCase):
def test_wake_up_server(self):
self.fail("TODO")
class TestMorpheus(unittest.TestCase):
def test_sleep_server(self):
self.fail("TODO")
[tox]
minversion = 1.6
#envlist = py35,pep8
envlist = py35,py27,pep8
skipsdist = True
[testenv]
usedevelop = True
install_command = pip install -U {opts} {packages}
setenv =
VIRTUAL_ENV={envdir}
LANGUAGE=en_US
TESTS_DIR=./tests/unit
deps =
-r{toxinidir}/test-requirements.txt
-r{toxinidir}/requirements.txt
commands = python setup.py test
#commands = python setup.py test --slowest --testr-args='{posargs}'
[testenv:pep8]
commands = flake8
[testenv:cover]
commands = python setup.py test --coverage --testr-args='{posargs}'
[flake8]
show-source = True
ignore = E123,E125
builtins = _
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build
import-order-style = pep8
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