Skip to content

Commit 6b561ac

Browse files
authored
fix namespace api (#4)
1 parent 99525c0 commit 6b561ac

File tree

5 files changed

+33
-17
lines changed

5 files changed

+33
-17
lines changed

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,20 @@ from staroid import Staroid
1515

1616
star = Staroid()
1717

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

21-
# create a namespace and deploy project
21+
# Launch a project
2222
ns = star.namespace(my_cluster).create("my_app", "GITHUB/staroids/namespace:master")
23+
24+
# stop instance
25+
ns = star.namespace(my_cluster).stop("my_app")
26+
27+
# restart instance
28+
ns = star.namespace(my_cluster).start("my_app")
29+
30+
# delete instance
31+
ns = star.namespace(my_cluster).delete("my_app")
2332
```
2433

2534
## Configuration

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="staroid", # Replace with your own username
8-
version="0.0.3",
8+
version="0.0.4",
99
license='MIT',
1010
author="Staroid",
1111
author_email="support@staroid.com",

staroid/namespace.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@ def start(self, instance_name):
132132
if ns == None:
133133
return None
134134

135-
c = Commit(commit_url)
136-
137135
r = self.__staroid._api_put(
138136
"orgs/{}/vc/{}/instance/{}/resume".format(
139137
self.__staroid.get_account(),
@@ -154,8 +152,6 @@ def stop(self, instance_name):
154152
if ns == None:
155153
return None
156154

157-
c = Commit(commit_url)
158-
159155
r = self.__staroid._api_put(
160156
"orgs/{}/vc/{}/instance/{}/pause".format(
161157
self.__staroid.get_account(),
@@ -176,8 +172,6 @@ def shell_start(self, instance_name):
176172
if ns == None:
177173
return None
178174

179-
c = Commit(commit_url)
180-
181175
r = self.__staroid._api_post(
182176
"orgs/{}/vc/{}/instance/{}/shell".format(
183177
self.__staroid.get_account(),
@@ -197,8 +191,6 @@ def shell_stop(self, instance_name):
197191
if ns == None:
198192
return None
199193

200-
c = Commit(commit_url)
201-
202194
r = self.__staroid._api_delete(
203195
"orgs/{}/vc/{}/instance/{}/shell".format(
204196
self.__staroid.get_account(),
@@ -207,8 +199,7 @@ def shell_stop(self, instance_name):
207199
)
208200
)
209201
if r.status_code == 200:
210-
js = json.loads(r.text)
211-
return Namespace(js)
202+
return None
212203
else:
213-
logging.error("Can not start shell {}", r.status_code)
204+
logging.error("Can not stop shell {}", r.status_code)
214205
return None

staroid/staroid.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,14 @@ def _api_get(self, path):
135135
r = requests.get(url, headers=headers)
136136
return r
137137

138-
def _api_post(self, path, payload):
138+
def _api_post(self, path, payload=None):
139139
url = self.__get_request_url(path);
140140
headers = self.__get_request_headers()
141141

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

145-
def _api_put(self, path, payload):
145+
def _api_put(self, path, payload=None):
146146
url = self.__get_request_url(path);
147147
headers = self.__get_request_headers()
148148

tests/test_namespace.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,23 @@ def test_crud_namespace(self):
3131
wait_for_phase(ns_api, ns, "RUNNING")
3232
self.assertEqual("RUNNING", ns_api.get_by_id(ns.id()).phase())
3333

34-
# when stop a namespace
34+
# start shell
35+
ns_api.shell_start("instance1")
36+
37+
# stop shell
38+
ns_api.shell_stop("instance1")
39+
40+
# pause
41+
ns = ns_api.stop("instance1")
42+
wait_for_phase(ns_api, ns, "PAUSED")
43+
self.assertEqual("PAUSED", ns_api.get_by_id(ns.id()).phase())
44+
45+
# resume
46+
ns = ns_api.start("instance1")
47+
wait_for_phase(ns_api, ns, "RUNNING")
48+
self.assertEqual("RUNNING", ns_api.get_by_id(ns.id()).phase())
49+
50+
# when delete a namespace
3551
ns = ns_api.delete("instance1")
3652

3753
# then namespace becomes REMOVED

0 commit comments

Comments
 (0)