Refactor ensure database in utils
Change-Id: I3a669122a6012783d227034aed7edb73546961d6
This commit is contained in:
@@ -19,7 +19,6 @@ the appropriate deployments, Mcrouter, pod monitors and Prometheus rules.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
from openstack_operator import database
|
|
||||||
from openstack_operator import identity
|
from openstack_operator import identity
|
||||||
from openstack_operator import utils
|
from openstack_operator import utils
|
||||||
|
|
||||||
@@ -31,7 +30,7 @@ def create_or_resume(name, spec, **_):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# deploy mysql for barbican
|
# deploy mysql for barbican
|
||||||
database.ensure_mysql_cluster("barbican", spec=spec["mysql"])
|
utils.ensure_mysql_cluster("barbican", spec["mysql"])
|
||||||
|
|
||||||
# deploy barbican api
|
# deploy barbican api
|
||||||
utils.create_or_update('barbican/daemonset.yml.j2',
|
utils.create_or_update('barbican/daemonset.yml.j2',
|
||||||
|
@@ -17,7 +17,6 @@
|
|||||||
This module maintains the operator for Cinder.
|
This module maintains the operator for Cinder.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from openstack_operator import database
|
|
||||||
from openstack_operator import identity
|
from openstack_operator import identity
|
||||||
from openstack_operator import utils
|
from openstack_operator import utils
|
||||||
|
|
||||||
@@ -32,7 +31,7 @@ def create_or_resume(name, spec, **_):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# deploy mysql for cinder
|
# deploy mysql for cinder
|
||||||
database.ensure_mysql_cluster("cinder", spec=spec["mysql"])
|
utils.ensure_mysql_cluster("cinder", spec=spec["mysql"])
|
||||||
|
|
||||||
# deploy rabbitmq
|
# deploy rabbitmq
|
||||||
utils.deploy_rabbitmq("cinder")
|
utils.deploy_rabbitmq("cinder")
|
||||||
|
@@ -1,54 +0,0 @@
|
|||||||
# Copyright 2020 VEXXHOST, Inc.
|
|
||||||
#
|
|
||||||
# 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.
|
|
||||||
|
|
||||||
"""database Operator
|
|
||||||
|
|
||||||
This module contains a few common functions for database management
|
|
||||||
"""
|
|
||||||
|
|
||||||
from openstack_operator import utils
|
|
||||||
|
|
||||||
|
|
||||||
def ensure_mysql_cluster(name, user=None, database=None, spec=None):
|
|
||||||
"""Create or update mysql cluster"""
|
|
||||||
|
|
||||||
if spec is None:
|
|
||||||
spec = {}
|
|
||||||
|
|
||||||
if database is None:
|
|
||||||
database = name
|
|
||||||
if user is None:
|
|
||||||
user = database
|
|
||||||
|
|
||||||
config = utils.get_secret("openstack", name + "-mysql")
|
|
||||||
if config is None:
|
|
||||||
root_password = utils.generate_password()
|
|
||||||
password = utils.generate_password()
|
|
||||||
utils.create_or_update('mysqlcluster/secret-mysqlcluster.yml.j2',
|
|
||||||
name=name, user=user,
|
|
||||||
database=database, password=password,
|
|
||||||
rootPassword=root_password)
|
|
||||||
config = utils.get_secret("openstack", name + "-mysql")
|
|
||||||
|
|
||||||
config['connection'] = \
|
|
||||||
"mysql+pymysql://%s:%s@%s-mysql-master/%s?charset=utf8" % (
|
|
||||||
config["USER"],
|
|
||||||
config["PASSWORD"],
|
|
||||||
name,
|
|
||||||
config["DATABASE"]
|
|
||||||
)
|
|
||||||
|
|
||||||
utils.create_or_update('mysqlcluster/mysqlcluster.yml.j2',
|
|
||||||
server_side=False, name=name, spec=spec)
|
|
||||||
return config
|
|
@@ -19,7 +19,6 @@ the appropriate deployments, Mcrouter, pod monitors and Prometheus rules.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
from openstack_operator import database
|
|
||||||
from openstack_operator import identity
|
from openstack_operator import identity
|
||||||
from openstack_operator import utils
|
from openstack_operator import utils
|
||||||
|
|
||||||
@@ -34,7 +33,7 @@ def create_or_resume(name, spec, **_):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# deploy mysql for glance
|
# deploy mysql for glance
|
||||||
database.ensure_mysql_cluster("glance", spec=spec["mysql"])
|
utils.ensure_mysql_cluster("glance", spec["mysql"])
|
||||||
|
|
||||||
# deploy glance api
|
# deploy glance api
|
||||||
utils.create_or_update('glance/daemonset.yml.j2',
|
utils.create_or_update('glance/daemonset.yml.j2',
|
||||||
|
@@ -20,7 +20,6 @@ server for the installation.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
from openstack_operator import database
|
|
||||||
from openstack_operator import identity
|
from openstack_operator import identity
|
||||||
from openstack_operator import utils
|
from openstack_operator import utils
|
||||||
|
|
||||||
@@ -31,7 +30,7 @@ def create_or_resume(name, spec, **_):
|
|||||||
"""Create and re-sync any Heat instances
|
"""Create and re-sync any Heat instances
|
||||||
"""
|
"""
|
||||||
|
|
||||||
database.ensure_mysql_cluster("heat", spec=spec["mysql"])
|
utils.ensure_mysql_cluster("heat", spec["mysql"])
|
||||||
|
|
||||||
# deploy rabbitmq
|
# deploy rabbitmq
|
||||||
utils.deploy_rabbitmq("heat")
|
utils.deploy_rabbitmq("heat")
|
||||||
|
@@ -23,7 +23,6 @@ import kopf
|
|||||||
|
|
||||||
from cryptography import fernet
|
from cryptography import fernet
|
||||||
|
|
||||||
from openstack_operator import database
|
|
||||||
from openstack_operator import filters
|
from openstack_operator import filters
|
||||||
from openstack_operator import utils
|
from openstack_operator import utils
|
||||||
|
|
||||||
@@ -110,7 +109,7 @@ def create_or_resume(name, spec, **_):
|
|||||||
# (TODO)Replace the current admin url
|
# (TODO)Replace the current admin url
|
||||||
|
|
||||||
# deploy mysql
|
# deploy mysql
|
||||||
db_config = database.ensure_mysql_cluster("keystone", spec=spec["mysql"])
|
db_config = utils.ensure_mysql_cluster("keystone", spec["mysql"])
|
||||||
|
|
||||||
# deploy memcached
|
# deploy memcached
|
||||||
|
|
||||||
|
@@ -19,7 +19,6 @@ the appropriate deployments, an instance of Memcache, RabbitMQ and a database
|
|||||||
server for the installation.
|
server for the installation.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from openstack_operator import database
|
|
||||||
from openstack_operator import identity
|
from openstack_operator import identity
|
||||||
from openstack_operator import utils
|
from openstack_operator import utils
|
||||||
|
|
||||||
@@ -33,7 +32,7 @@ def create_or_resume(name, spec, **_):
|
|||||||
start the service up for the first time.
|
start the service up for the first time.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
database.ensure_mysql_cluster("magnum", spec=spec["mysql"])
|
utils.ensure_mysql_cluster("magnum", spec["mysql"])
|
||||||
|
|
||||||
# deploy rabbitmq
|
# deploy rabbitmq
|
||||||
utils.deploy_rabbitmq("magnum")
|
utils.deploy_rabbitmq("magnum")
|
||||||
|
@@ -19,7 +19,6 @@ This code takes care of doing the operations of the OpenStack Neutron API
|
|||||||
service.
|
service.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from openstack_operator import database
|
|
||||||
from openstack_operator import identity
|
from openstack_operator import identity
|
||||||
from openstack_operator import utils
|
from openstack_operator import utils
|
||||||
|
|
||||||
@@ -32,9 +31,7 @@ def create_or_resume(spec, **_):
|
|||||||
This function is called when a new resource is created but also when we
|
This function is called when a new resource is created but also when we
|
||||||
start the service up for the first time.
|
start the service up for the first time.
|
||||||
"""
|
"""
|
||||||
|
utils.ensure_mysql_cluster("neutron", spec["mysql"])
|
||||||
database.ensure_mysql_cluster("neutron", spec=spec["mysql"])
|
|
||||||
|
|
||||||
utils.deploy_rabbitmq("neutron")
|
utils.deploy_rabbitmq("neutron")
|
||||||
utils.create_or_update('neutron/daemonset-server.yml.j2', spec=spec)
|
utils.create_or_update('neutron/daemonset-server.yml.j2', spec=spec)
|
||||||
utils.create_or_update('neutron/daemonset-openvswitch-agent.yml.j2',
|
utils.create_or_update('neutron/daemonset-openvswitch-agent.yml.j2',
|
||||||
|
@@ -21,7 +21,6 @@ service.
|
|||||||
|
|
||||||
import kopf
|
import kopf
|
||||||
|
|
||||||
from openstack_operator import database
|
|
||||||
from openstack_operator import identity
|
from openstack_operator import identity
|
||||||
from openstack_operator import utils
|
from openstack_operator import utils
|
||||||
|
|
||||||
@@ -45,12 +44,12 @@ def create_or_resume(spec, **_):
|
|||||||
|
|
||||||
identity.ensure_application_credential(name="nova")
|
identity.ensure_application_credential(name="nova")
|
||||||
|
|
||||||
databases['api'] = database.ensure_mysql_cluster(
|
databases['api'] = utils.ensure_mysql_cluster(
|
||||||
"nova-api", database="nova_api"
|
"nova-api", database="nova_api"
|
||||||
)
|
)
|
||||||
|
|
||||||
for cell in CELLS:
|
for cell in CELLS:
|
||||||
databases[cell] = database.ensure_mysql_cluster(
|
databases[cell] = utils.ensure_mysql_cluster(
|
||||||
"nova-%s" % cell, database="nova_%s" % cell)
|
"nova-%s" % cell, database="nova_%s" % cell)
|
||||||
|
|
||||||
# NOTE(mnaser): cell0 does not need a message queue
|
# NOTE(mnaser): cell0 does not need a message queue
|
||||||
@@ -97,6 +96,6 @@ def run_database_migrations(**_):
|
|||||||
deployment and triggers a database migrations
|
deployment and triggers a database migrations
|
||||||
"""
|
"""
|
||||||
|
|
||||||
cell0 = database.ensure_mysql_cluster("nova-cell0")
|
cell0 = utils.ensure_mysql_cluster("nova-cell0")
|
||||||
utils.create_or_update('nova/conductor/job.yml.j2', adopt=True,
|
utils.create_or_update('nova/conductor/job.yml.j2', adopt=True,
|
||||||
cell0_db=cell0['connection'])
|
cell0_db=cell0['connection'])
|
||||||
|
@@ -144,7 +144,11 @@ def set_service_config(all_config, service_name):
|
|||||||
|
|
||||||
# Inject the operator level config to service level
|
# Inject the operator level config to service level
|
||||||
# Backup config for mysql
|
# Backup config for mysql
|
||||||
all_config["backup"]["schedule"] = utils.get_backup_schedule(service_name)
|
if "backup" in all_config:
|
||||||
|
all_config["backup"]["schedule"] = \
|
||||||
|
utils.get_backup_schedule(service_name)
|
||||||
|
else:
|
||||||
|
all_config["backup"] = {}
|
||||||
if "mysql" in spec:
|
if "mysql" in spec:
|
||||||
spec["mysql"].update(all_config["backup"])
|
spec["mysql"].update(all_config["backup"])
|
||||||
else:
|
else:
|
||||||
|
@@ -19,7 +19,6 @@ This code takes care of doing the operations of the OpenStack Placement API
|
|||||||
service.
|
service.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from openstack_operator import database
|
|
||||||
from openstack_operator import identity
|
from openstack_operator import identity
|
||||||
from openstack_operator import utils
|
from openstack_operator import utils
|
||||||
|
|
||||||
@@ -34,7 +33,7 @@ def create_or_resume(name, spec, **_):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# deploy mysql for placement
|
# deploy mysql for placement
|
||||||
database.ensure_mysql_cluster("placement", spec=spec["mysql"])
|
utils.ensure_mysql_cluster("placement", spec["mysql"])
|
||||||
|
|
||||||
# deploy placement api
|
# deploy placement api
|
||||||
utils.create_or_update('placement/daemonset.yml.j2', spec=spec)
|
utils.create_or_update('placement/daemonset.yml.j2', spec=spec)
|
||||||
|
@@ -318,3 +318,37 @@ def deploy_rabbitmq(name, **_):
|
|||||||
create_or_update('operator/secret-rabbitmq.yml.j2',
|
create_or_update('operator/secret-rabbitmq.yml.j2',
|
||||||
name=name, password=generate_password())
|
name=name, password=generate_password())
|
||||||
create_or_update('operator/rabbitmq.yml.j2', name=name)
|
create_or_update('operator/rabbitmq.yml.j2', name=name)
|
||||||
|
|
||||||
|
|
||||||
|
def ensure_mysql_cluster(name, spec=None, user=None, database=None):
|
||||||
|
"""Create or update mysql cluster"""
|
||||||
|
|
||||||
|
if spec is None:
|
||||||
|
spec = {}
|
||||||
|
|
||||||
|
if database is None:
|
||||||
|
database = name
|
||||||
|
if user is None:
|
||||||
|
user = database
|
||||||
|
|
||||||
|
config = get_secret("openstack", name + "-mysql")
|
||||||
|
if config is None:
|
||||||
|
root_password = generate_password()
|
||||||
|
password = generate_password()
|
||||||
|
create_or_update('mysqlcluster/secret-mysqlcluster.yml.j2',
|
||||||
|
name=name, user=user,
|
||||||
|
database=database, password=password,
|
||||||
|
rootPassword=root_password)
|
||||||
|
config = get_secret("openstack", name + "-mysql")
|
||||||
|
|
||||||
|
config['connection'] = \
|
||||||
|
"mysql+pymysql://%s:%s@%s-mysql-master/%s?charset=utf8" % (
|
||||||
|
config["USER"],
|
||||||
|
config["PASSWORD"],
|
||||||
|
name,
|
||||||
|
config["DATABASE"]
|
||||||
|
)
|
||||||
|
|
||||||
|
create_or_update('mysqlcluster/mysqlcluster.yml.j2',
|
||||||
|
server_side=False, name=name, spec=spec)
|
||||||
|
return config
|
||||||
|
Reference in New Issue
Block a user