projects
/
osm
/
N2VC.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Bug 1980 fixed
[osm/N2VC.git]
/
n2vc
/
k8s_juju_conn.py
diff --git
a/n2vc/k8s_juju_conn.py
b/n2vc/k8s_juju_conn.py
index
f8ed0e0
..
c27449b
100644
(file)
--- a/
n2vc/k8s_juju_conn.py
+++ b/
n2vc/k8s_juju_conn.py
@@
-13,6
+13,7
@@
# limitations under the License.
import asyncio
# limitations under the License.
import asyncio
+from typing import Union
import os
import uuid
import yaml
import os
import uuid
import yaml
@@
-122,14
+123,16
@@
class K8sJujuConnector(K8sConnector):
# if it fails in the middle of the process
cleanup_data = []
try:
# if it fails in the middle of the process
cleanup_data = []
try:
+ self.log.debug("Initializing K8s cluster for juju")
kubectl.create_cluster_role(
name=metadata_name,
labels=labels,
)
kubectl.create_cluster_role(
name=metadata_name,
labels=labels,
)
+ self.log.debug("Cluster role created")
cleanup_data.append(
{
"delete": kubectl.delete_cluster_role,
cleanup_data.append(
{
"delete": kubectl.delete_cluster_role,
- "args": (metadata_name),
+ "args": (metadata_name
,
),
}
)
}
)
@@
-137,10
+140,11
@@
class K8sJujuConnector(K8sConnector):
name=metadata_name,
labels=labels,
)
name=metadata_name,
labels=labels,
)
+ self.log.debug("Service account created")
cleanup_data.append(
{
"delete": kubectl.delete_service_account,
cleanup_data.append(
{
"delete": kubectl.delete_service_account,
- "args": (metadata_name),
+ "args": (metadata_name
,
),
}
)
}
)
@@
-148,10
+152,11
@@
class K8sJujuConnector(K8sConnector):
name=metadata_name,
labels=labels,
)
name=metadata_name,
labels=labels,
)
+ self.log.debug("Role binding created")
cleanup_data.append(
{
"delete": kubectl.delete_service_account,
cleanup_data.append(
{
"delete": kubectl.delete_service_account,
- "args": (metadata_name),
+ "args": (metadata_name
,
),
}
)
token, client_cert_data = await kubectl.get_secret_data(
}
)
token, client_cert_data = await kubectl.get_secret_data(
@@
-159,6
+164,7
@@
class K8sJujuConnector(K8sConnector):
)
default_storage_class = kubectl.get_default_storage_class()
)
default_storage_class = kubectl.get_default_storage_class()
+ self.log.debug("Default storage class: {}".format(default_storage_class))
await libjuju.add_k8s(
name=cluster_uuid,
rbac_id=rbac_id,
await libjuju.add_k8s(
name=cluster_uuid,
rbac_id=rbac_id,
@@
-168,9
+174,10
@@
class K8sJujuConnector(K8sConnector):
storage_class=default_storage_class,
credential_name=self._get_credential_name(cluster_uuid),
)
storage_class=default_storage_class,
credential_name=self._get_credential_name(cluster_uuid),
)
+ self.log.debug("K8s cluster added to juju controller")
return cluster_uuid, True
except Exception as e:
return cluster_uuid, True
except Exception as e:
- self.log.error("Error initializing k8scluster: {}".format(e))
+ self.log.error("Error initializing k8scluster: {}".format(e)
, exc_info=True
)
if len(cleanup_data) > 0:
self.log.debug("Cleaning up created resources in k8s cluster...")
for item in cleanup_data:
if len(cleanup_data) > 0:
self.log.debug("Cleaning up created resources in k8s cluster...")
for item in cleanup_data:
@@
-187,6
+194,9
@@
class K8sJujuConnector(K8sConnector):
name: str,
url: str,
_type: str = "charm",
name: str,
url: str,
_type: str = "charm",
+ cert: str = None,
+ user: str = None,
+ password: str = None,
):
raise MethodNotImplemented()
):
raise MethodNotImplemented()
@@
-303,6
+313,10
@@
class K8sJujuConnector(K8sConnector):
raise K8sException("bundle must be set")
if bundle.startswith("cs:"):
raise K8sException("bundle must be set")
if bundle.startswith("cs:"):
+ # For Juju Bundles provided by the Charm Store
+ pass
+ elif bundle.startswith("ch:"):
+ # For Juju Bundles provided by the Charm Hub (this only works for juju version >= 2.9)
pass
elif bundle.startswith("http"):
# Download the file
pass
elif bundle.startswith("http"):
# Download the file
@@
-360,8
+374,8
@@
class K8sJujuConnector(K8sConnector):
"""Scale an application in a model
:param: kdu_instance str: KDU instance name
"""Scale an application in a model
:param: kdu_instance str: KDU instance name
- :param: scale int: Scale to which to set th
is
application
- :param: resource_name str:
Resource name (Application name)
+ :param: scale int: Scale to which to set th
e
application
+ :param: resource_name str:
The application name in the Juju Bundle
:param: timeout float: The time, in seconds, to wait for the install
to finish
:param kwargs: Additional parameters
:param: timeout float: The time, in seconds, to wait for the install
to finish
:param kwargs: Additional parameters
@@
-394,12
+408,13
@@
class K8sJujuConnector(K8sConnector):
) -> int:
"""Get an application scale count
) -> int:
"""Get an application scale count
- :param: resource_name str:
Resource name (Application name)
+ :param: resource_name str:
The application name in the Juju Bundle
:param: kdu_instance str: KDU instance name
:param kwargs: Additional parameters
vca_id (str): VCA ID
:return: Return application instance count
"""
:param: kdu_instance str: KDU instance name
:param kwargs: Additional parameters
vca_id (str): VCA ID
:return: Return application instance count
"""
+
try:
libjuju = await self._get_libjuju(kwargs.get("vca_id"))
status = await libjuju.get_model_status(kdu_instance)
try:
libjuju = await self._get_libjuju(kwargs.get("vca_id"))
status = await libjuju.get_model_status(kdu_instance)
@@
-642,7
+657,7
@@
class K8sJujuConnector(K8sConnector):
complete_status: bool = False,
yaml_format: bool = False,
**kwargs,
complete_status: bool = False,
yaml_format: bool = False,
**kwargs,
- ) ->
dict
:
+ ) ->
Union[str, dict]
:
"""Get the status of the KDU
Get the current status of the KDU instance.
"""Get the status of the KDU
Get the current status of the KDU instance.