-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
496 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
"""A wrapper around the kubectl commandline client""" | ||
import shutil | ||
from . import helpers | ||
|
||
|
||
class KubernetesService(object): | ||
"""Marker interface for CloudMan services""" | ||
def __init__(self, client): | ||
self._client = client | ||
|
||
def client(self): | ||
return self._client | ||
|
||
|
||
class KubernetesClient(KubernetesService): | ||
|
||
def __init__(self): | ||
self._check_environment() | ||
super(KubernetesClient, self).__init__(self) | ||
self._namespace_svc = KubernetesNamespaceService(self) | ||
|
||
@staticmethod | ||
def _check_environment(): | ||
if not shutil.which("kubectl"): | ||
raise Exception("Could not find kubectl executable in path") | ||
|
||
@property | ||
def namespaces(self): | ||
return self._namespace_svc | ||
|
||
|
||
class KubernetesNamespaceService(KubernetesService): | ||
|
||
def __init__(self, client): | ||
super(KubernetesNamespaceService, self).__init__(client) | ||
|
||
def list(self): | ||
data = helpers.run_list_command(["kubectl", "get", "namespaces"], | ||
delimiter=" ", skipinitialspace=True) | ||
return data | ||
|
||
# def _list_names(self): | ||
# data = self.list() | ||
# output = [each.get('NAME') for each in data] | ||
# return output | ||
|
||
def create(self, namespace_name): | ||
return helpers.run_command(["kubectl", "create", | ||
"namespace", namespace_name]) | ||
|
||
# def _create_if_not_exists(self, namespace_name): | ||
# if namespace_name not in self._list_names(): | ||
# return self.create(namespace_name) | ||
|
||
def delete(self, namespace_name): | ||
return helpers.run_command(["kubectl", "delete", | ||
"namespace", namespace_name]) |
Oops, something went wrong.