Skip to content
This repository was archived by the owner on Mar 17, 2024. It is now read-only.

Commit c7aa19e

Browse files
authored
Merge pull request #157 from scaleoutsystems/release/v0.2.0
STACKn v0.2.0
2 parents 5e44f3a + 9f3c637 commit c7aa19e

File tree

101 files changed

+3150
-947
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+3150
-947
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# Byte-compiled / optimized / DLL files
2-
migrations/
32
.idea/
43
.DS_Store
54
__pycache__/
@@ -29,6 +28,8 @@ share/python-wheels/
2928
.installed.cfg
3029
*.egg
3130
MANIFEST
31+
Pipfile
32+
Pipfile.lock
3233

3334
# PyInstaller
3435
# Usually these files are written by a python script from a template
@@ -135,3 +136,4 @@ media/generators/
135136
media/visualisers/
136137

137138
tele_settings.py
139+
tele_settings_worker.py

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
![alt text](https://thumb.tildacdn.com/tild3162-6435-4365-a230-656137616436/-/resize/560x/-/format/webp/stacknlogo3.png)
2+
13
<a href="#what-is-stackn">What is STACKn</a><br>
24
<a href="#why-use-stackn">Why use STACKn</a><br>
35
<a href="#core-features">Core features</a><br>
@@ -160,6 +162,9 @@ https://github.com/scaleoutsystems/aml-example-project
160162

161163
Contributions are welcome. Please see [CONTRIBUTING.md](CONTRIBUTING.md).
162164

165+
# Where is STACKn used?
166+
STACKn is used in various places, examples include [SciLifeLab Data Center](https://www.scilifelab.se/data) and within the EU-funded project [EOSC-Nordics](https://www.eosc-nordic.eu/).
167+
163168
# Maintainers
164169
**Scaleout Systems AB** is the main contributing organization behind this project.
165170
- morganekmefjord

cli/MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include scaleout/cli/default-project.tar.gz

cli/scaleout/auth.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,21 @@
1111

1212
logger = logging.getLogger('cli')
1313

14-
def keycloak_user_auth(username, password, keycloak_url, client_id='studio-api', realm='STACKn'):
15-
discovery_url = '{}/auth/realms/{}'.format(keycloak_url, realm)
16-
res = requests.get(discovery_url)
14+
def keycloak_user_auth(username, password, keycloak_url, client_id='studio-api', realm='STACKn', secure=True):
15+
discovery_url = os.path.join(keycloak_url, 'auth/realms/{}'.format(realm))
16+
res = requests.get(discovery_url, verify=secure)
1717
if res:
1818
realm_info = res.json()
1919
public_key = realm_info['public_key']
2020
else:
2121
print('Failed to discover realm settings: '+realm)
2222
return None
23-
24-
token_url = '{}/auth/realms/{}/protocol/openid-connect/token'.format(keycloak_url, realm)
23+
token_url = os.path.join(keycloak_url, 'auth/realms/{}/protocol/openid-connect/token'.format(realm))
2524
req = {'client_id': client_id,
2625
'grant_type': 'password',
2726
'username': username,
2827
'password': password}
29-
res = requests.post(token_url, data=req)
28+
res = requests.post(token_url, data=req, verify=secure)
3029
if res:
3130
res = res.json()
3231
else:
@@ -70,7 +69,7 @@ def write_tokens(deployment, token, refresh_token, public_key, keycloak_host, st
7069
if not status:
7170
logger.info('Could not write tokens -- failed to write to file.')
7271

73-
def get_stackn_config():
72+
def get_stackn_config(secure=True):
7473
# if not os.path.exists(os.path.expanduser('~/.scaleout/stackn.json')):
7574
# print('You need to setup STACKn first.')
7675
# login()
@@ -79,7 +78,7 @@ def get_stackn_config():
7978
if not load_status:
8079
print('Failed to load stackn config file.')
8180
print('You need to setup STACKn first.')
82-
login()
81+
login(secure=secure)
8382
stackn_config, load_status = load_from_file('stackn', os.path.expanduser('~/.scaleout'))
8483
# return None
8584

@@ -100,7 +99,7 @@ def get_remote_config():
10099
print('No active project: Create a new project or set an existing project.')
101100
return [], False
102101

103-
def get_token(client_id='studio-api', realm='STACKn'):
102+
def get_token(client_id='studio-api', realm='STACKn', secure=True):
104103
# stackn_config, load_status = load_from_file('stackn', os.path.expanduser('~/.scaleout/'))
105104
# if not load_status:
106105
# print('Failed to load stackn config file.')
@@ -124,11 +123,11 @@ def get_token(client_id='studio-api', realm='STACKn'):
124123
# print('Token valid for user '+access_token_json['preferred_username'])
125124
except:
126125
# Try to refresh token
127-
token_url = '{}/auth/realms/{}/protocol/openid-connect/token'.format(token_config['keycloak_url'], realm)
126+
token_url = os.path.join(token_config['keycloak_url'], 'auth/realms/{}/protocol/openid-connect/token'.format(realm))
128127
req = {'grant_type': 'refresh_token',
129128
'client_id': client_id,
130129
'refresh_token': token_config['refresh_token']}
131-
res = requests.post(token_url, data=req)
130+
res = requests.post(token_url, data=req, verify=secure)
132131
resp = res.json()
133132
if 'access_token' in resp:
134133
access_token = resp['access_token']
@@ -149,7 +148,7 @@ def get_token(client_id='studio-api', realm='STACKn'):
149148

150149

151150

152-
def login(client_id='studio-api', realm='STACKn', deployment=[], keycloak_host=[], studio_host=[]):
151+
def login(client_id='studio-api', realm='STACKn', deployment=[], keycloak_host=[], studio_host=[], secure=True):
153152
""" Login to Studio services. """
154153
if not deployment:
155154
deployment = input('Name: ')
@@ -159,7 +158,7 @@ def login(client_id='studio-api', realm='STACKn', deployment=[], keycloak_host=[
159158
studio_host = input('Studio host: ')
160159
username = input('Username: ')
161160
password = getpass()
162-
access_token, refresh_token, public_key = keycloak_user_auth(username, password, keycloak_host)
161+
access_token, refresh_token, public_key = keycloak_user_auth(username, password, keycloak_host, secure=secure)
163162
# dirname = base64.urlsafe_b64encode(host.encode("utf-8")).decode("utf-8")
164163
dirpath = os.path.expanduser('~/.scaleout/'+deployment)
165164
if not os.path.exists(dirpath):

cli/scaleout/cli/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from .create_cmd import create_cmd
55
from .get_cmd import get_cmd
66
from .delete_cmd import delete_cmd
7-
from .login_cmd import setup_cmd, status_cmd
7+
from .stackn_cmd import setup_cmd, status_cmd, predict_cmd
88
from .set_cmd import set_cmd
9-
from .update_cmd import update_cmd
9+
from .update_cmd import update_cmd
10+
from .init_cmd import init_cmd

cli/scaleout/cli/create_cmd.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def create_cmd(ctx, daemon):
1919
print('{} NYI should run as daemon...'.format(__file__))
2020

2121
@create_cmd.command('model')
22-
@click.option('-f', '--model-file', required=True)
22+
@click.option('-f', '--model-file', required=False, default="")
2323
@click.option('-n', '--model-name', required=True)
2424
@click.option('-r', '--release-type', required=False)
2525
@click.option('-d', '--description', required=False,default="")
@@ -43,10 +43,11 @@ def create_deployment_definition(ctx, name, filepath, path_predict=''):
4343
@click.option('-m', '--model', required=True)
4444
@click.option('-v', '--model-version', default='latest')
4545
@click.option('-d', '--deploymentdefinition', required=True)
46+
@click.option('-s', '--settings', required=False)
4647
@click.pass_context
47-
def create_deployment_cmd(ctx, model, deploymentdefinition, model_version=[]):
48+
def create_deployment_cmd(ctx, model, deploymentdefinition, model_version=[], settings=[]):
4849
client = ctx.obj['CLIENT']
49-
client.deploy_model(model, model_version, deploymentdefinition)
50+
client.deploy_model(model, model_version, deploymentdefinition, settings)
5051

5152

5253
# Create project
@@ -59,4 +60,29 @@ def create_project_cmd(ctx, name, description='', repository=''):
5960
client = ctx.obj['CLIENT']
6061
client.create_project(name, description, repository)
6162

62-
# Create dataset
63+
@create_cmd.command('lab')
64+
@click.option('-f', '--flavor', required=True)
65+
@click.option('-e', '--environment', required=True)
66+
@click.pass_context
67+
def create_session(ctx, flavor, environment):
68+
client = ctx.obj['CLIENT']
69+
client.create_session(flavor_slug=flavor, environment_slug=environment)
70+
71+
72+
# Create dataset
73+
74+
75+
@create_cmd.command('dataset')
76+
@click.option('-n', '--name', required=True)
77+
@click.option('-f', '--filenames', required=False)
78+
@click.option('-d', '--directory', required=False)
79+
@click.option('-r', '--release_type', required=False, default='minor')
80+
@click.pass_context
81+
def create_dataset(ctx, name, directory=[], filenames=[], release_type='minor', description='', bucket='dataset'):
82+
client = ctx.obj['CLIENT']
83+
client.create_dataset(name,
84+
release_type,
85+
filenames,
86+
directory,
87+
description=description,
88+
bucket=bucket)
1.85 KB
Binary file not shown.

cli/scaleout/cli/delete_cmd.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ def delete_deployment_cmd(ctx, name, version=None):
3535
client = ctx.obj['CLIENT']
3636
client.delete_deployment(name, version)
3737

38+
@delete_cmd.command('dataset')
39+
@click.option('-n', '--name', required=True)
40+
@click.option('-v', '--version', required=True)
41+
@click.pass_context
42+
def delete_dataset_cmd(ctx, name, version=None):
43+
""" Delete a model """
44+
client = ctx.obj['CLIENT']
45+
client.delete_dataset(name, version)
46+
3847
# @delete_cmd.command('deployments')
3948
# @click.pass_context
4049
# def delete_deployment_cmd(ctx):

cli/scaleout/cli/get_cmd.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,29 @@ def get_projects_cmd(ctx):
4848
keys = ["name", "created_at", "updated_at"]
4949
create_table(ctx, "projects", names, keys)
5050

51+
@get_cmd.command('labs')
52+
@click.pass_context
53+
def lab_list_all_cmd(ctx):
54+
""" List all Lab Sessions. """
55+
names = ["Name", "Flavor", "Environment", "Status", "Created"]
56+
keys = ["name", "flavor_slug", "environment_slug", "status", "created_at"]
57+
create_table(ctx, "labs", names, keys)
58+
59+
@get_cmd.command('members')
60+
@click.pass_context
61+
def members_list_cmd(ctx):
62+
""" List all project members. """
63+
names = ["Username"]
64+
keys = ["username"]
65+
create_table(ctx, "members", names, keys)
66+
67+
@get_cmd.command('dataset')
68+
@click.pass_context
69+
def dataset_list_cmd(ctx):
70+
""" List all project members. """
71+
names = ["Name", "Version", "Release", "Project", "Created", "Created by"]
72+
keys = ["name", "version", "release_type", "project_slug", "created_on", "created_by"]
73+
create_table(ctx, "dataset", names, keys)
5174

5275
# alliance
5376

cli/scaleout/cli/init_cmd.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import click
2+
from .main import main
3+
import requests
4+
import os
5+
import tarfile
6+
7+
@main.command('init')
8+
9+
@click.pass_context
10+
def init_cmd(ctx):
11+
dir_path = os.path.dirname(os.path.realpath(__file__))
12+
file_path = os.path.join(dir_path, 'default-project.tar.gz')
13+
import tarfile
14+
tf = tarfile.open(file_path)
15+
tf.extractall()

0 commit comments

Comments
 (0)