Updating freezer-dr osclient

Change-Id: Ice3f16f2597bb999d6be433facf85df5c9687de9
This commit is contained in:
Saad Zaher 2016-11-03 12:09:13 +00:00
parent df05da676d
commit 91b034da78
9 changed files with 150 additions and 92 deletions

View File

@ -11,77 +11,88 @@
# From oslo.log
#
# Print debugging output (set logging level to DEBUG instead of default WARNING
# level). (boolean value)
# If set to true, the logging level will be set to DEBUG instead of the default
# INFO level. (boolean value)
# Note: This option can be changed without restarting.
#debug = false
# Print more verbose output (set logging level to INFO instead of default
# WARNING level). (boolean value)
#verbose = false
# DEPRECATED: If set to false, the logging level will be set to WARNING instead
# of the default INFO level. (boolean value)
# This option is deprecated for removal.
# Its value may be silently ignored in the future.
#verbose = true
# The name of a logging configuration file. This file is appended to any
# existing logging configuration files. For details about logging configuration
# files, see the Python logging module documentation. (string value)
# files, see the Python logging module documentation. Note that when logging
# configuration files are used then all logging configuration is set in the
# configuration file and other logging configuration options are ignored (for
# example, logging_context_format_string). (string value)
# Note: This option can be changed without restarting.
# Deprecated group/name - [DEFAULT]/log_config
#log_config_append = <None>
# DEPRECATED. A logging.Formatter log message format string which may use any
# of the available logging.LogRecord attributes. This option is deprecated.
# Please use logging_context_format_string and logging_default_format_string
# instead. (string value)
#log_format = <None>
# Format string for %%(asctime)s in log records. Default: %(default)s . (string
# Defines the format string for %%(asctime)s in log records. Default:
# %(default)s . This option is ignored if log_config_append is set. (string
# value)
#log_date_format = %Y-%m-%d %H:%M:%S
# (Optional) Name of log file to output to. If no default is set, logging will
# go to stdout. (string value)
# (Optional) Name of log file to send logging output to. If no default is set,
# logging will go to stderr as defined by use_stderr. This option is ignored if
# log_config_append is set. (string value)
# Deprecated group/name - [DEFAULT]/logfile
#log_file = <None>
# (Optional) The base directory used for relative --log-file paths. (string
# value)
# (Optional) The base directory used for relative log_file paths. This option
# is ignored if log_config_append is set. (string value)
# Deprecated group/name - [DEFAULT]/logdir
#log_dir = <None>
# Use syslog for logging. Existing syslog format is DEPRECATED during I, and
# will change in J to honor RFC5424. (boolean value)
# Uses logging handler designed to watch file system. When log file is moved or
# removed this handler will open a new log file with specified path
# instantaneously. It makes sense only if log_file option is specified and
# Linux platform is used. This option is ignored if log_config_append is set.
# (boolean value)
#watch_log_file = false
# Use syslog for logging. Existing syslog format is DEPRECATED and will be
# changed later to honor RFC5424. This option is ignored if log_config_append
# is set. (boolean value)
#use_syslog = false
# (Optional) Enables or disables syslog rfc5424 format for logging. If enabled,
# prefixes the MSG part of the syslog message with APP-NAME (RFC5424). The
# format without the APP-NAME is deprecated in I, and will be removed in J.
# (boolean value)
#use_syslog_rfc_format = false
# Syslog facility to receive log lines. (string value)
# Syslog facility to receive log lines. This option is ignored if
# log_config_append is set. (string value)
#syslog_log_facility = LOG_USER
# Log output to standard error. (boolean value)
#use_stderr = true
# Log output to standard error. This option is ignored if log_config_append is
# set. (boolean value)
#use_stderr = false
# Format string to use for log messages with context. (string value)
#logging_context_format_string = %(asctime)s.%(msecs)03d %(process)d %(levelname)s %(name)s [%(request_id)s %(user_identity)s] %(instance)s%(message)s
# Format string to use for log messages without context. (string value)
# Format string to use for log messages when context is undefined. (string
# value)
#logging_default_format_string = %(asctime)s.%(msecs)03d %(process)d %(levelname)s %(name)s [-] %(instance)s%(message)s
# Data to append to log format when level is DEBUG. (string value)
# Additional data to append to log message when logging level for the message
# is DEBUG. (string value)
#logging_debug_format_suffix = %(funcName)s %(pathname)s:%(lineno)d
# Prefix each line of exception output with this format. (string value)
#logging_exception_prefix = %(asctime)s.%(msecs)03d %(process)d TRACE %(name)s %(instance)s
#logging_exception_prefix = %(asctime)s.%(msecs)03d %(process)d ERROR %(name)s %(instance)s
# List of logger=LEVEL pairs. (list value)
#default_log_levels = amqp=WARN,amqplib=WARN,boto=WARN,qpid=WARN,sqlalchemy=WARN,suds=INFO,oslo.messaging=INFO,iso8601=WARN,requests.packages.urllib3.connectionpool=WARN,urllib3.connectionpool=WARN,websocket=WARN,requests.packages.urllib3.util.retry=WARN,urllib3.util.retry=WARN,keystonemiddleware=WARN,routes.middleware=WARN,stevedore=WARN
# Defines the format string for %(user_identity)s that is used in
# logging_context_format_string. (string value)
#logging_user_identity_format = %(user)s %(tenant)s %(domain)s %(user_domain)s %(project_domain)s
# List of package logging levels in logger=LEVEL pairs. This option is ignored
# if log_config_append is set. (list value)
#default_log_levels = amqp=WARN,amqplib=WARN,boto=WARN,qpid=WARN,sqlalchemy=WARN,suds=INFO,oslo.messaging=INFO,iso8601=WARN,requests.packages.urllib3.connectionpool=WARN,urllib3.connectionpool=WARN,websocket=WARN,requests.packages.urllib3.util.retry=WARN,urllib3.util.retry=WARN,keystonemiddleware=WARN,routes.middleware=WARN,stevedore=WARN,taskflow=WARN,keystoneauth=WARN,oslo.cache=INFO,dogpile.core.dogpile=INFO
# Enables or disables publication of error events. (boolean value)
#publish_errors = false
# Enables or disables fatal status of deprecations. (boolean value)
#fatal_deprecations = false
# The format for an instance that is passed with the log message. (string
# value)
#instance_format = "[instance: %(uuid)s] "
@ -90,6 +101,21 @@
# value)
#instance_uuid_format = "[instance: %(uuid)s] "
# Interval, number of seconds, of log rate limiting. (integer value)
#rate_limit_interval = 0
# Maximum number of logged messages per rate_limit_interval. (integer value)
#rate_limit_burst = 0
# Log level name used by rate limiting: CRITICAL, ERROR, INFO, WARNING, DEBUG
# or empty string. Logs with level greater or equal to rate_limit_except_level
# are not filtered. An empty string means that all levels are filtered. (string
# value)
#rate_limit_except_level = CRITICAL
# Enables or disables fatal status of deprecations. (boolean value)
#fatal_deprecations = false
[evacuation]
@ -109,6 +135,10 @@
# evacuate the node (integer value)
#retries = 1
# Set this option to True in case your compute nodes are running on a shared
# storage or False if not (boolean value)
#shared_storage = false
# Dict contains kwargs to be passed to the evacuator driver. In case you have
# additional args needs to be passed to your evacuator please, list them as
# key0:value0, key1:value1, .... (dict value)

View File

@ -34,7 +34,12 @@
{% for instance in instances %}
<tr>
<td> {{ instance.get('name') }} </td>
<td> {{ instance.get('addresses').get('internal')[0].get('addr') }} </td>
<td>
{% for key, value in instance.get('addresses').iteritems() %}
<b>{{ key }}</b> :
{{ value[0].get('addr', 'No IP') }}
{% endfor %}
</td>
</tr>
{% endfor %}
</table>

View File

@ -35,7 +35,12 @@
{% for instance in instances %}
<tr>
<td> {{ instance.get('name') }} </td>
<td> {{ instance.get('addresses').get('internal')[0].get('addr') }} </td>
<td>
{% for key, value in instance.get('addresses').iteritems() %}
<b>{{ key }}</b> :
{{ value[0].get('addr', 'No IP') }}
{% endfor %}
</td>
</tr>
{% endfor %}
</table>

View File

@ -25,7 +25,12 @@
{% for instance in instances%}
<tr>
<td> {{ instance.get('name') }} </td>
<td> {{ instance.get('addresses').get('internal')[0].get('addr') }} </td>
<td>
{% for key, value in instance.get('addresses').iteritems() %}
<b>{{ key }}</b> :
{{ value[0].get('addr', 'No IP') }}
{% endfor %}
</td>
</tr>
{% endfor %}
</table>

View File

@ -25,7 +25,12 @@
{% for instance in instances%}
<tr>
<td> {{ instance.get('name') }} </td>
<td> {{ instance.get('addresses').get('internal')[0].get('addr') }} </td>
<td>
{% for key, value in instance.get('addresses').iteritems() %}
<b>{{ key }}</b> :
{{ value[0].get('addr', 'No IP') }}
{% endfor %}
</td>
</tr>
{% endfor %}
</table>

View File

@ -18,11 +18,11 @@ from keystoneclient import session
from keystoneclient.auth.identity import v3
from keystoneclient.v3 import client as keystoneclient
from keystoneclient import client as keystoneclient
from neutronclient.v2_0 import client as neutronclient
from novaclient.v2 import client as novaclient
from novaclient import client as novaclient
from oslo_log import log
@ -46,6 +46,11 @@ class OSClient:
self.auth_session = None
self.endpoint_type = 'internalURL'
self.interface = 'internal'
self.verify = True
self.insecure = kwargs.pop('insecure', False)
if self.insecure:
self.verify = not bool(self.insecure)
if authmethod == 'password':
if 'endpoint_type' in kwargs:
self.endpoint_type = kwargs.pop('endpoint_type', 'internalURL')
@ -70,13 +75,30 @@ class OSClient:
def auth(self):
"""Create a session."""
auth = v3.Password(auth_url=self.authurl,
auth = v3.Password(auth_url=self.authurl, reauthenticate=True,
**self.kwargs)
self.auth_session = session.Session(auth=auth)
self.auth_session = session.Session(auth=auth, verify=self.verify)
def get_novaclient(self):
if not hasattr(self, 'nova'):
self.auth()
self.nova = novaclient.Client('2', session=self.auth_session,
endpoint_type=self.endpoint_type,
insecure=self.insecure)
return self.nova
def get_neutronclient(self):
if not hasattr(self, 'neutron'):
self.auth()
self.neutron = neutronclient.Client(
session=self.auth_session,
endpoint_type=self.endpoint_type,
insecure=self.insecure
)
return self.neutron
def novacomputes(self):
nova = novaclient.Client(session=self.auth_session,
endpoint_type=self.endpoint_type)
nova = self.get_novaclient()
services = nova.services.list()
compute_nodes = []
compute_hosts = []
@ -89,8 +111,7 @@ class OSClient:
return compute_nodes
def novahypervisors(self):
nova = novaclient.Client(session=self.auth_session,
endpoint_type=self.endpoint_type)
nova = self.get_novaclient()
hypervisors = nova.hypervisors.list()
nova_hypervisors = []
@ -101,10 +122,7 @@ class OSClient:
def neutronagents(self, hosts=[]):
if not hosts:
hosts = self.compute_hosts
auth_session = session.Session(auth=self.auth_session.auth)
neutron = neutronclient.Client(session=auth_session,
endpoint_type=self.endpoint_type)
self.auth_session = auth_session
neutron = self.get_neutronclient()
agents = neutron.list_agents()
neutron_agents = []
for agent in agents.get('agents'):
@ -123,10 +141,7 @@ class OSClient:
under shared storage and False otherwise
:return: List of nodes with VMs that were running on that node
"""
auth_session = session.Session(auth=self.auth_session.auth)
nova = novaclient.Client(session=auth_session,
endpoint_type=self.endpoint_type)
self.auth_session = auth_session
nova = self.get_novaclient()
evacuated_nodes = []
for node in nodes:
hypervisors = nova.hypervisors.search(node.get('host'), True)
@ -146,10 +161,7 @@ class OSClient:
def set_in_maintenance(self, nodes):
"""Set compute nodes in maintenance mode."""
auth_session = session.Session(auth=self.auth_session.auth)
nova = novaclient.Client(session=auth_session,
endpoint_type=self.endpoint_type)
self.auth_session = auth_session
nova = self.get_novaclient()
for node in nodes:
output = []
host = nova.hosts.get(node)[0]
@ -162,7 +174,8 @@ class OSClient:
def get_session(self):
"""Get the authentication section."""
auth_session = session.Session(auth=self.auth_session.auth)
auth_session = session.Session(auth=self.auth_session.auth,
verify=self.verify)
return auth_session
def get_node_status(self, node):
@ -172,8 +185,7 @@ class OSClient:
:return: True or False. True => node disabled, False => node is enabled
or unknow status !
"""
nova = novaclient.Client(session=self.auth_session,
endpoint_type=self.endpoint_type)
nova = self.get_novaclient()
try:
node_service = nova.services.find(host=node.get('host'))
del nova
@ -190,9 +202,7 @@ class OSClient:
def disable_node(self, node):
"""Disable nova on the failing node."""
auth_session = session.Session(auth=self.auth_session.auth)
nova = novaclient.Client(session=auth_session,
endpoint_type=self.endpoint_type)
nova = self.get_novaclient()
try:
node_service = nova.services.find(host=node.get('host'))
except Exception as e:
@ -219,9 +229,7 @@ class OSClient:
def get_hypervisor_instances(self, node):
"""Get instances from an hypervisor."""
auth_session = session.Session(auth=self.auth_session.auth)
nova = novaclient.Client(session=auth_session,
endpoint_type=self.endpoint_type)
nova = self.get_novaclient()
hypervisors = nova.hypervisors.search(node.get('host'), True)
if not hypervisors:
return []
@ -233,9 +241,7 @@ class OSClient:
:param node: dict contains host index
:return: Hypervisor
"""
auth_session = session.Session(auth=self.auth_session.auth)
nova = novaclient.Client(session=auth_session,
endpoint_type=self.endpoint_type)
nova = self.get_novaclient()
hypervisors = nova.hypervisors.search(node.get('host'), True)
if not hypervisors:
return None
@ -243,9 +249,7 @@ class OSClient:
def get_instances_list(self, node):
"""Get instances running on a node for all tenants."""
auth_session = session.Session(auth=self.auth_session.auth)
nova = novaclient.Client(session=auth_session,
endpoint_type=self.endpoint_type)
nova = self.get_novaclient()
servers = nova.servers.list(detailed=True,
search_opts={'host': node.get('host'),
'all_tenants': True})
@ -273,10 +277,12 @@ class OSClient:
def users_on_tenant(self, tenant):
"""List user per project."""
auth_session = session.Session(auth=self.auth_session.auth)
auth_session = session.Session(auth=self.auth_session.auth,
verify=self.verify)
keystone = keystoneclient.Client(session=auth_session,
endpoint_type=self.endpoint_type,
interface='internal')
interface='internal',
insecure=self.insecure)
users = []
try:
users = keystone.users.list(default_project=tenant)
@ -290,17 +296,13 @@ class OSClient:
def get_hypervisors_stats(self):
"""Get stats for all hypervisors."""
auth_session = session.Session(auth=self.auth_session.auth)
nova = novaclient.Client(session=auth_session,
endpoint_type=self.endpoint_type)
nova = self.get_novaclient()
stats = nova.hypervisor_stats.statistics()
return stats.to_dict()
def get_hypervisor_details(self, node):
"""Get details about hypervisor running on the provided node."""
auth_session = session.Session(auth=self.auth_session.auth)
nova = novaclient.Client(session=auth_session,
endpoint_type=self.endpoint_type)
nova = self.get_novaclient()
hypervisors = nova.hypervisors.list(detailed=True)
for hypervisor in hypervisors:
hypervisor = hypervisor.to_dict()

View File

@ -79,13 +79,14 @@ class EvacuationManager(object):
nodes = succeeded_nodes
"""
# Start evacuation calls ...
for i in range(0, 10):
evacuated_nodes = []
for i in range(0, self.retires):
try:
sleep(30)
evacuated_nodes = self.driver.evacuate_nodes(nodes)
print "Try Number: ", i
print evacuated_nodes
sleep(self.wait)
nodes = self.driver.evacuate_nodes(nodes)
if not nodes:
return evacuated_nodes
evacuated_nodes = nodes
except Exception as e:
LOG.error(e)
return evacuated_nodes

View File

@ -16,7 +16,9 @@ from freezer_dr.monitors.common.driver import MonitorBaseDriver
from time import sleep
from oslo_config import cfg
from oslo_log import log
from httplib import HTTPConnection, socket
from httplib import HTTPConnection
from httplib import HTTPSConnection
from httplib import socket
from urlparse import urlparse
CONF = cfg.CONF
@ -82,8 +84,12 @@ class StandardDriver(MonitorBaseDriver):
def is_alive(self):
url = urlparse(self.endpoint)
if url.scheme == 'https':
http_connector = HTTPSConnection
else:
http_connector = HTTPConnection
try:
connection = HTTPConnection(host=url.netloc)
connection = http_connector(host=url.netloc)
connection.request('HEAD', url=url.path)
response = connection.getresponse()
except socket.error:

View File

@ -55,7 +55,6 @@ class StandardEmail(NotifierBaseDriver):
for user in tenant.get('users'):
if 'email' in user:
subject = '[' + status + '] Evacuation Status'
print tenant.get('instances')
template_vars = {
'name': user.get('name'),
'tenant': tenant.get('id'),