Skip to content

Commit

Permalink
Merge "[CE-285] The Cluster part of kubernetes agent"
Browse files Browse the repository at this point in the history
  • Loading branch information
yeasy authored and Gerrit Code Review committed Apr 13, 2018
2 parents 69d9748 + 8ecc686 commit 99f3793
Show file tree
Hide file tree
Showing 32 changed files with 694 additions and 62 deletions.
6 changes: 4 additions & 2 deletions src/agent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
compose_up, compose_clean, compose_start, compose_stop, compose_restart, \
setup_container_host, cleanup_host, reset_container_host

from .vsphere.host_operations import VsphereOperation

from .docker.host import DockerHost
from .docker.cluster import ClusterOnDocker

from .k8s.cluster_operations import K8sClusterOperation
from .k8s.host_operations import KubernetesOperation
from .k8s.cluster import ClusterOnKubernetes
from .k8s.host import KubernetesHost

from .vsphere.host_operations import VsphereOperation
from .vsphere.host import VsphereHost
from .vsphere.cluster import ClusterOnVsphere
5 changes: 3 additions & 2 deletions src/agent/k8s/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright IBM Corp, All Rights Reserved.
# Copyright 2018 (c) VMware, Inc. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
# This is for agent that interacts with Kubernetes platform
# This is for agent that interacts with Kubernetes platform using
# cello-k8s-operator, see github.com/hyperledger/cello-k8s-operator.
91 changes: 91 additions & 0 deletions src/agent/k8s/cluster.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Copyright 2018 (c) VMware, Inc. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

import logging
import os
import sys

from agent import K8sClusterOperation

sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))
from common import log_handler, LOG_LEVEL

from agent import compose_up, compose_clean, compose_start, compose_stop, \
compose_restart

from common import NETWORK_TYPES, CONSENSUS_PLUGINS_FABRIC_V1, \
CONSENSUS_MODES, NETWORK_SIZE_FABRIC_PRE_V1

from ..cluster_base import ClusterBase


logger = logging.getLogger(__name__)
logger.setLevel(LOG_LEVEL)
logger.addHandler(log_handler)


class ClusterOnKubernetes(ClusterBase):
""" Main handler to operate the cluster in Kubernetes
"""
def __init__(self):
pass

def create(self, kube_config, cluster_name, ports_index, nfsServer_ip):
try:
operation = K8sClusterOperation(kube_config)
containers = operation.deploy_cluster(cluster_name,
ports_index,
nfsServer_ip)
except Exception as e:
logger.error("Failed to create Kubernetes Cluster: {}".format(e))
return None
return containers

def delete(self, kube_config, cluster_name, ports_index, nfsServer_ip):
try:
operation = K8sClusterOperation(kube_config)
operation.delete_cluster(cluster_name, ports_index, nfsServer_ip)
except Exception as e:
logger.error("Failed to delete Kubernetes Cluster: {}".format(e))
return False
return True

def get_services_urls(self, kube_config, cluster_name):
try:
operation = K8sClusterOperation(kube_config)
services_urls = operation.get_services_urls(cluster_name)
except Exception as e:
logger.error("Failed to get Kubernetes services's urls: {}"
.format(e))
return None
return services_urls

def start(self, kube_config, cluster_name, ports_index, nfsServer_ip):
try:
operation = K8sClusterOperation(kube_config)
containers = operation.start_cluster(cluster_name, ports_index,
nfsServer_ip)
except Exception as e:
logger.error("Failed to start Kubernetes Cluster: {}".format(e))
return None
return containers

def stop(self, kube_config, cluster_name, ports_index, nfsServer_ip):
try:
operation = K8sClusterOperation(kube_config)
operation.stop_cluster(cluster_name, ports_index, nfsServer_ip)
except Exception as e:
logger.error("Failed to stop Kubernetes Cluster: {}".format(e))
return False
return True

def restart(self, kube_config, cluster_name, ports_index, nfsServer_ip):
result = self.stop(kube_config, cluster_name, ports_index,
nfsServer_ip)
if result:
return self.start(kube_config, cluster_name, ports_index,
nfsServer_ip)
else:
logger.error("Failed to Restart Kubernetes Cluster")
return None
Loading

0 comments on commit 99f3793

Please sign in to comment.