Skip to content

fix namespace api #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,20 @@ from staroid import Staroid

star = Staroid()

# create a ske kubernetes cluster
# Create a ske kubernetes cluster
my_cluster = star.cluster().create("my cluster", "gcp us-west1")

# create a namespace and deploy project
# Launch a project
ns = star.namespace(my_cluster).create("my_app", "GITHUB/staroids/namespace:master")

# stop instance
ns = star.namespace(my_cluster).stop("my_app")

# restart instance
ns = star.namespace(my_cluster).start("my_app")

# delete instance
ns = star.namespace(my_cluster).delete("my_app")
```

## Configuration
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="staroid", # Replace with your own username
version="0.0.3",
version="0.0.4",
license='MIT',
author="Staroid",
author_email="support@staroid.com",
Expand Down
13 changes: 2 additions & 11 deletions staroid/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ def start(self, instance_name):
if ns == None:
return None

c = Commit(commit_url)

r = self.__staroid._api_put(
"orgs/{}/vc/{}/instance/{}/resume".format(
self.__staroid.get_account(),
Expand All @@ -154,8 +152,6 @@ def stop(self, instance_name):
if ns == None:
return None

c = Commit(commit_url)

r = self.__staroid._api_put(
"orgs/{}/vc/{}/instance/{}/pause".format(
self.__staroid.get_account(),
Expand All @@ -176,8 +172,6 @@ def shell_start(self, instance_name):
if ns == None:
return None

c = Commit(commit_url)

r = self.__staroid._api_post(
"orgs/{}/vc/{}/instance/{}/shell".format(
self.__staroid.get_account(),
Expand All @@ -197,8 +191,6 @@ def shell_stop(self, instance_name):
if ns == None:
return None

c = Commit(commit_url)

r = self.__staroid._api_delete(
"orgs/{}/vc/{}/instance/{}/shell".format(
self.__staroid.get_account(),
Expand All @@ -207,8 +199,7 @@ def shell_stop(self, instance_name):
)
)
if r.status_code == 200:
js = json.loads(r.text)
return Namespace(js)
return None
else:
logging.error("Can not start shell {}", r.status_code)
logging.error("Can not stop shell {}", r.status_code)
return None
4 changes: 2 additions & 2 deletions staroid/staroid.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,14 @@ def _api_get(self, path):
r = requests.get(url, headers=headers)
return r

def _api_post(self, path, payload):
def _api_post(self, path, payload=None):
url = self.__get_request_url(path);
headers = self.__get_request_headers()

r = requests.post(url, headers=headers, data=json.dumps(payload))
return r

def _api_put(self, path, payload):
def _api_put(self, path, payload=None):
url = self.__get_request_url(path);
headers = self.__get_request_headers()

Expand Down
18 changes: 17 additions & 1 deletion tests/test_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,23 @@ def test_crud_namespace(self):
wait_for_phase(ns_api, ns, "RUNNING")
self.assertEqual("RUNNING", ns_api.get_by_id(ns.id()).phase())

# when stop a namespace
# start shell
ns_api.shell_start("instance1")

# stop shell
ns_api.shell_stop("instance1")

# pause
ns = ns_api.stop("instance1")
wait_for_phase(ns_api, ns, "PAUSED")
self.assertEqual("PAUSED", ns_api.get_by_id(ns.id()).phase())

# resume
ns = ns_api.start("instance1")
wait_for_phase(ns_api, ns, "RUNNING")
self.assertEqual("RUNNING", ns_api.get_by_id(ns.id()).phase())

# when delete a namespace
ns = ns_api.delete("instance1")

# then namespace becomes REMOVED
Expand Down