def restart():
clear_flag("ro-k8s.configured")
-@when_not("kafka.ready")
-@when_not("ro-k8s.configured")
-@when("leadership.is_leader")
-def waiting_for_kafka():
- layer.status.waiting("Waiting for kafka to be ready")
-
-@when_not("mongo.ready")
+@when_not("mysql.available")
@when_not("ro-k8s.configured")
@when("leadership.is_leader")
-def waiting_for_mongo():
- layer.status.waiting("Waiting for mongo to be ready")
+def waiting_for_mysql():
+ layer.status.waiting("Waiting for mysql to be ready")
-@when("kafka.ready", "mongo.ready")
+@when("mysql.available")
@when_not("ro-k8s.configured")
@when("leadership.is_leader")
def configure():
layer.status.maintenance("Configuring ro container")
try:
- kafka = endpoint_from_flag("kafka.ready")
- mongo = endpoint_from_flag("mongo.ready")
-
- if kafka and mongo:
- kafka_units = kafka.kafkas()
- kafka_unit = kafka_units[0]
-
- mongo_uri = mongo.connection_string()
- log("Mongo URI: {}".format(mongo_uri))
-
- if (
- mongo_uri
- and kafka_unit["host"]
- and kafka_unit["port"]
- and ro_unit["host"]
- and ro_unit["port"]
- ):
- spec = make_pod_spec(
- kafka_unit["host"],
- kafka_unit["port"],
- mongo_uri,
- )
-
- log("set pod spec:\n{}".format(spec))
- pod_spec_set(spec)
- layer.status.active("creating container")
- set_flag("ro-k8s.configured")
+ mysql = endpoint_from_flag("mysql.available")
+
+ if mysql.host() is not None:
+ spec = make_pod_spec(
+ mysql.host(),
+ mysql.port(),
+ mysql.user(),
+ mysql.password(),
+ mysql.root_password(),
+ )
+
+ log("set pod spec:\n{}".format(spec))
+ pod_spec_set(spec)
+ layer.status.active("creating container")
+ set_flag("ro-k8s.configured")
except Exception as e:
layer.status.blocked("k8s spec failed to deploy: {}".format(e))
-@when("kafka.ready", "mongo.ready")
+@when("mysql.available")
@when_not("leadership.is_leader")
def non_leaders_active():
layer.status.active("ready")
log("Fail sending RO configuration: {}".format(e))
-def make_pod_spec(kafka_host, kafka_port, mongo_uri):
+def make_pod_spec(
+ mysql_host, mysql_port, mysql_user, mysql_password, mysql_root_password
+):
"""Make pod specification for Kubernetes
Args:
- kafka_host (str): Kafka hostname or IP
- kafka_port (int): Kafka port
- mongo_uri (str): Mongo URI
+ mysql_name (str): RO DB name
+ mysql_host (str): RO DB host
+ mysql_port (int): RO DB port
+ mysql_user (str): RO DB user
+ mysql_password (str): RO DB password
Returns:
pod_spec: Pod specification for Kubernetes
"""
with open("reactive/spec_template.yaml") as spec_file:
pod_spec_template = spec_file.read()
- cfg = config()
md = metadata()
+ cfg = config()
data = {
"name": md.get("name"),
- "kafka_host": kafka_host,
- "kafka_port": kafka_port,
- "mongo_uri": mongo_uri,
+ "mysql_host": mysql_host,
+ "mysql_port": mysql_port,
+ "mysql_user": mysql_user,
+ "mysql_password": mysql_password,
+ "mysql_root_password": mysql_root_password,
}
data.update(cfg)
protocol: TCP
config:
ALLOW_ANONYMOUS_LOGIN: 'yes'
-
- OSMRO_MESSAGE_DRIVER: kafka
- OSMRO_MESSAGE_HOST: %(kafka_host)s
- OSMRO_MESSAGE_PORT: %(kafka_port)s
-
- OSMRO_DATABASE_DRIVER: mongo
- OSMRO_DATABASE_URI: %(mongo_uri)s
- OSMRO_DATABASE_COMMONKEY: %(DATABASE_COMMONKEY)s
-
+ RO_DB_HOST: %(mysql_host)s
+ RO_DB_PORT: %(mysql_port)s
+ RO_DB_NAME: %(ro_database)s
+ RO_DB_USER: %(mysql_user)s
+ RO_DB_ROOT_PASSWORD: %(mysql_root_password)s
+ RO_DB_PASSWORD: %(mysql_password)s
+ RO_DB_OVIM_PASSWORD: %(mysql_password)s
+ RO_DB_OVIM_HOST: %(mysql_host)s
+ RO_DB_OVIM_PORT: %(mysql_port)s
+ RO_DB_OVIM_USER: %(mysql_user)s
+ RO_DB_OVIM_ROOT_PASSWORD: %(mysql_root_password)s
+ RO_DB_OVIM_NAME: %(vim_database)s
+ OPENMANO_TENANT: %(OPENMANO_TENANT)s