1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
import tempfile
import datetime
from ..models import Cluster, WrInstallSchedule, WrBatch, Namespace
from django.conf import settings
from .helpers import Address, Jinja
from .ansibleservice import AnsibleService
import logging
logger = logging.getLogger("caas")
class WrInstallNowService(AnsibleService):
"""
target == ilo_host_address, later becomes cluster_name
"""
def __init__(self, ansible_queue, target, git, branch, playbook, zmq):
super().__init__(ansible_queue, target, git, branch, playbook, zmq)
def get_wrbatch(self):
if self.ansible_queue == "wr":
wrbatch_kwargs = {"ilo_host_address": self.target}
elif self.ansible_queue in ("wr_remediate", "wr_wipedisk", "wr_ptp", "wr_ptp_config", "wr_unlock", "wr_wrap"):
wrbatch_kwargs = {"cluster_name": self.target}
elif self.ansible_queue == "wr_reboot":
wrbatch_kwargs = {"namespace_name": self.target}
try:
wrbatch = WrBatch.objects.get(**wrbatch_kwargs)
except WrBatch.DoesNotExist:
logger.error("FAILED: while scheduling Wind River installation: cannot find wrbatch with identifier: %s" % self.target)
raise
return wrbatch
def deploy(self):
logger.debug("%s Enter" % self.target)
wrbatch = self.get_wrbatch()
self.do_deploy(wrbatch)
def remediate(self):
logger.debug("%s Enter" % self.target)
wrbatch = self.get_wrbatch()
self.do_deploy(wrbatch)
def do_deploy(self, wrbatch):
try:
cluster_kwargs = {"pk": wrbatch.cluster_id}
cluster = Cluster.objects.get(**cluster_kwargs)
except Cluster.DoesNotExist:
logger.error("FAILED: while scheduling Wind River installation: cannot find cluster associated with wrbatch with identifier: %s" % wrbatch.ilo_host_address)
raise
# one playbook per cluster
self.target = cluster.cluster_name
self.maint_window_p = wrbatch.maint_window_p
# host_vars file
hostvars_config = {"wr_vendor_name": wrbatch.vendor_name,
"wr_region_name": cluster.cluster_name,
"wr_bmc_controller_0_address": wrbatch.ilo_host_address,
"wr_mgmt_controller_0_mac": wrbatch.pxe_mac_address,
"wr_oam_floating_address": wrbatch.oam_vip_address,
"wr_oam_node_0_address": wrbatch.oam_host_address,
"wr_oam_gateway_address": wrbatch.oam_default_gateway,
"wr_mgmt_start_address": wrbatch.mgmt_address_range_start,
"wr_mgmt_end_address": wrbatch.mgmt_address_range_end,
"wr_mgmt_gateway_address": wrbatch.mgmt_default_gateway,
"wr_mgmt_subnet": Address.gateway_to_subnet(wrbatch.mgmt_subnet, numquads = 4),
"wr_central_mgmt_start_address": wrbatch.parent_mgmt_address_range_start,
"wr_central_mgmt_default_gateway": wrbatch.parent_mgmt_default_gateway,
"wr_central_mgmt_subnet": Address.gateway_to_subnet(wrbatch.parent_mgmt_subnet, numquads = 4),
"wr_host_vlan": wrbatch.host_vlan,
"wr_oam_vlan": wrbatch.oam_vlan,
"wr_mgmt_vlan": wrbatch.mgmt_vlan,
"wr_bmc_username": wrbatch.bmc_username,
"wr_bmc_password": wrbatch.bmc_password,
"wr_dns_servers": settings.DNS_SERVERS,
"wr_ntp_servers": settings.NTP_SERVERS,
"wr_registry_server": settings.WR_REGISTRY_SERVER,
"wr_registry_username": settings.WR_REGISTRY_USERNAME,
"wr_registry_password": settings.WR_REGISTRY_PASSWORD,
"wr_webdav_server": settings.WR_WEBDAV_SERVER,
"wr_webdav_username": settings.WR_WEBDAV_USERNAME,
"wr_webdav_password": settings.WR_WEBDAV_PASSWORD,
"wr_middleware_endpoint": settings.CAAS_MIDDLEWARE_ENDPOINT,
"wr_middleware_username": settings.CAAS_MIDDLEWARE_USERNAME,
"wr_middleware_password": settings.CAAS_MIDDLEWARE_PASSWORD,
"wr_docker_http_proxy": settings.WR_DOCKER_HTTP_PROXY,
"wr_docker_https_proxy": settings.WR_DOCKER_HTTPS_PROXY,
"wr_docker_no_proxy": settings.WR_DOCKER_NO_PROXY,
"wr_ssl_ca_cert": settings.WR_SSL_CA_CERT}
# revisit for NVPA-279
# if len(servers) > 1:
# wr_config["wr_bmc_controller_1_address"] = servers[1].ilo_host_address
# wr_config["wr_mgmt_controller_1_mac"] = servers[1].pxe_mac_address
# wr_config["wr_oam_node_1_address"] = servers[1].oam_host_address
hostvars_content = Jinja.render("wr_host_vars.j2", **hostvars_config)
hostvars = wrbatch.oam_hostname
# inventory file
inventory_config = {"central_target": wrbatch.parent_cluster_name,
"central_target_ip": wrbatch.parent_oam_vip_address,
"remote_target": wrbatch.oam_hostname,
"remote_target_ip": wrbatch.oam_vip_address}
inventory_content = Jinja.render("wr_inventory.j2", **inventory_config)
inventory = "%s.yaml" % self.target
logger.debug("%s Sending playbook to queue" % self.target)
self.run_playbook(inventory, inventory_content, hostvars, hostvars_content, extra_args = {"clusterName": wrbatch.parent_cluster_name})
logger.debug("%s Sent playbook to queue" % self.target)
return 0
|