tripleo-ha-utils/roles/stonith-config/templates/config-stonith-from-instackenv.py.j2
Raoul Scarazzini 00f82288b1 Add overcloudrc.v3 support in IHA
This commit adds the support to the stack rc file related to the version
3 of keystone. It will check for an overcloudrc.v3 file in the
working_dir of the deployment (typically /home/stack) and if it is not
able to find it it will use overclourc as usual.
The command for creating the nova-evacuate resource was changed
accordingly, adding --force to support liberty/osp8 and mitaka/osp9
because in these releases we can't provide the new requested fields
project_domain and user_domain.
The way overcloudrc was treated before has been cleaned. No need to copy
the file on the controller node. The name of the file is calculated
dynamically as before, also for v3.

Note: this commit solves also what was proposed here [1] when dealing
with overcloudrc files in which there are both OS_TENANT_NAME and
OS_PROJECT_NAME variables, taking the latter.
The stonith creation python script has been modified to support also
Ocata, for which we still have OS_TENANT_NAME but we don't support
positional arguments anymore.

Change-Id: I1a143b67850c67d6d3207c06abcf60d32f2456ff
2018-04-06 10:19:17 -04:00

95 lines
3.3 KiB
Django/Jinja

#!/bin/python
import os
import json
import sys
from keystoneauth1.identity import v2
from keystoneauth1 import session
from pprint import pprint
from novaclient import client
# JSon file as first parameter
jdata = open(sys.argv[1])
data = json.load(jdata)
# install, uninstall, none
fence_config = sys.argv[2]
# controllers, computes, all or none
fence_devices = sys.argv[3]
# Define variables to connect to nova
os_username = os.environ['OS_USERNAME']
os_password = os.environ['OS_PASSWORD']
os_auth_url = os.environ['OS_AUTH_URL']
try:
os_tenant_name = os.environ['OS_TENANT_NAME']
except:
os_project_name = os.environ['OS_PROJECT_NAME']
os_project_domain_name=os.environ['OS_PROJECT_DOMAIN_NAME']
os_user_domain_name=os.environ['OS_USER_DOMAIN_NAME']
os_compute_api_version = os.environ['COMPUTE_API_VERSION']
# If fence_devices includes controllers then we act on the overall stonith-enabled property of the cluster
if (fence_devices in ['controllers','all']):
# If we're uninstalling then we disable stonith
if (fence_config == 'uninstall'):
print('pcs property set stonith-enabled=false')
# If we're installing then we enable it
elif (fence_config == 'install'):
print('pcs property set stonith-enabled=true')
# Connect to nova
try:
# Liberty/OSP-8,Mitaka/OSP-9,Newton/OSP-10
nt = client.Client(2,
os_username,
os_password,
os_tenant_name,
os_auth_url)
nt.hypervisors.list()
except:
try:
# Ocata/OSP-11
nt = client.Client(2,
username=os_username,
password=os_password,
project_name=os_tenant_name,
auth_url=os_auth_url)
nt.hypervisors.list()
except:
# Pike/OSP-12
nt = client.Client(2,
auth_url=os_auth_url,
username=os_username,
password=os_password,
project_name=os_project_name,
project_domain_name=os_project_domain_name,
user_domain_name=os_user_domain_name)
nt.hypervisors.list()
# Parse instances
for instance in nt.servers.list():
for node in data["nodes"]:
if (node["mac"][0].lower() == instance.addresses['ctlplane'][0]['OS-EXT-IPS-MAC:mac_addr']
and
(
('controller' in instance.name and fence_devices in ['controllers','all'])
or
('compute' in instance.name and fence_devices in ['computes','all'])
)
):
if (fence_config == 'uninstall'):
print('pcs stonith delete ipmilan-{} || /bin/true'.format(instance.name))
elif (fence_config == 'install'):
try:
print('pcs stonith create ipmilan-{} fence_ipmilan pcmk_host_list="{}" ipaddr="{}" login="{}" passwd="{}" ipport={} lanplus="true" delay=20 op monitor interval=60s'
.format(instance.name,instance.name,node["pm_addr"],node["pm_user"],node["pm_password"],node["pm_port"]))
except:
print('pcs stonith create ipmilan-{} fence_ipmilan pcmk_host_list="{}" ipaddr="{}" login="{}" passwd="{}" lanplus="true" delay=20 op monitor interval=60s'
.format(instance.name,instance.name,node["pm_addr"],node["pm_user"],node["pm_password"]))
print('pcs constraint location ipmilan-{} avoids {}'
.format(instance.name,instance.name))
# Close nova connection
jdata.close()