Skip to content

Commit e242cd8

Browse files
committed
Support stage yaml
1 parent 23bbd68 commit e242cd8

File tree

18 files changed

+103
-63
lines changed

18 files changed

+103
-63
lines changed

lain_cli/appversion.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from lain_sdk.util import warn, info
55
from lain_cli.auth import authorize_and_check
6-
from lain_cli.utils import get_version_lists, lain_yaml, check_phase
6+
from lain_cli.utils import get_version_lists, lain_yaml, check_phase, get_phase_stage
77

88

99
@arg('phase', help="lain cluster phase id, can be added by lain config save")
@@ -13,7 +13,8 @@ def appversion(phase):
1313
"""
1414

1515
check_phase(phase)
16-
yml = lain_yaml(ignore_prepare=True)
16+
stage = get_phase_stage(phase)
17+
yml = lain_yaml(ignore_prepare=True, stage=stage)
1718
authorize_and_check(phase, yml.appname)
1819

1920
version_list = get_version_lists(phase, yml.appname)

lain_cli/attach.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from entryclient import EntryClient
44
from lain_sdk.util import error, info
55
from lain_cli.auth import SSOAccess, authorize_and_check
6-
from lain_cli.utils import check_phase, lain_yaml, get_domain
6+
from lain_cli.utils import check_phase, lain_yaml, get_domain, get_phase_stage
77

88

99
@arg('phase', help="lain cluster phase id, can be added by lain config save")
@@ -14,7 +14,8 @@ def attach(phase, proc_name, instance_no, target=None):
1414
"""
1515

1616
check_phase(phase)
17-
yml = lain_yaml(ignore_prepare=True)
17+
stage = get_phase_stage(phase)
18+
yml = lain_yaml(ignore_prepare=True, stage=stage)
1819
appname = target if target else yml.appname
1920
authorize_and_check(phase, appname)
2021
domain = get_domain(phase)

lain_cli/backup.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from argh.decorators import arg, aliases
66

77
from lain_sdk.util import warn
8-
from lain_cli.utils import lain_yaml_data, check_phase
8+
from lain_cli.utils import lain_yaml_data, check_phase, get_phase_stage
99
from lain_cli.utils import TwoLevelCommandBase, get_domain
1010

1111

@@ -30,7 +30,8 @@ def jobs(cls, phase):
3030
list backup jobs for this lain app
3131
"""
3232
check_phase(phase)
33-
appname = lain_yaml_data()['appname']
33+
stage = get_phase_stage(phase)
34+
appname = lain_yaml_data(stage=stage)['appname']
3435
route = "api/v2/app/%s/cron/jobs" % appname
3536
data = cls._request('GET', phase, route, None)
3637
if data:
@@ -46,7 +47,8 @@ def list(cls, phase, proc, path):
4647
list files in the incremental backup direcotry
4748
"""
4849
check_phase(phase[0])
49-
appname = lain_yaml_data()['appname']
50+
stage = get_phase_stage(phase[0])
51+
appname = lain_yaml_data(stage=stage)['appname']
5052
route = "api/v2/app/%s/proc/%s/backups/%s?open=true" % (appname, proc[0], path[0])
5153
data = cls._request('GET', phase[0], route, None)
5254
if data:
@@ -63,7 +65,8 @@ def get(cls, phase, proc, volume):
6365
get all the backups of the given proc's volume
6466
"""
6567
check_phase(phase[0])
66-
appname = lain_yaml_data()['appname']
68+
stage = get_phase_stage(phase[0])
69+
appname = lain_yaml_data(stage=stage)['appname']
6770
route = "api/v2/app/%s/proc/%s/backups?volume=%s" % (appname, proc[0], volume[0])
6871
data = cls._request('GET', phase[0], route, None)
6972
if data:
@@ -78,7 +81,8 @@ def delete(cls, phase, proc, files):
7881
delete a backup of a proc
7982
"""
8083
check_phase(phase[0])
81-
appname = lain_yaml_data()['appname']
84+
stage = get_phase_stage(phase[0])
85+
appname = lain_yaml_data(stage=stage)['appname']
8286
route = "api/v2/app/%s/proc/%s/backups/actions/delete" % (appname, proc[0])
8387
data = cls._request('POST', phase[0], route, {'files': files})
8488
if data:
@@ -94,7 +98,8 @@ def recover(cls, phase, proc, backup, files):
9498
recover the volume from given backup
9599
"""
96100
check_phase(phase[0])
97-
appname = lain_yaml_data()['appname']
101+
stage = get_phase_stage(phase[0])
102+
appname = lain_yaml_data(stage=stage)['appname']
98103
if not files:
99104
route = "api/v2/app/%s/proc/%s/backups/%s/actions/recover" % (appname, proc[0], backup[0])
100105
data = cls._request('POST', phase[0], route, None)
@@ -116,7 +121,8 @@ def migrate(cls, phase, proc, backup, files, volume="", to=0):
116121
recover a instance's volume from other instance's backup
117122
"""
118123
check_phase(phase[0])
119-
appname = lain_yaml_data()['appname']
124+
stage = get_phase_stage(phase[0])
125+
appname = lain_yaml_data(stage=stage)['appname']
120126
if not files:
121127
route = "api/v2/app/%s/proc/%s/backups/%s/actions/migrate" % (appname, proc[0], backup[0])
122128
data = cls._request('POST', phase[0], route, {"volume": volume, "to": to})
@@ -135,7 +141,8 @@ def records(cls, phase, rid, num=10):
135141
list job records of this lain app
136142
"""
137143
check_phase(phase[0])
138-
appname = lain_yaml_data()['appname']
144+
stage = get_phase_stage(phase[0])
145+
appname = lain_yaml_data(stage=stage)['appname']
139146
route = "api/v2/app/%s/cron/records" % appname
140147
if rid:
141148
route = "%s/%s" % (route, rid)
@@ -153,7 +160,8 @@ def run(cls, phase, id):
153160
run a job right now
154161
"""
155162
check_phase(phase[0])
156-
appname = lain_yaml_data()['appname']
163+
stage = get_phase_stage(phase[0])
164+
appname = lain_yaml_data(stage=stage)['appname']
157165
route = "api/v2/app/%s/cron/jobs/%s/actions/run" % (appname, id[0])
158166
data = cls._request('POST', phase[0], route, None)
159167
if data:

lain_cli/build.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,22 @@
44

55
import lain_sdk.mydocker as docker
66
from lain_sdk.util import error, warn, info
7-
from lain_cli.utils import lain_yaml
7+
from lain_cli.utils import lain_yaml, get_phase_stage
88
from lain_cli.validate import validate_only_warning
99

1010

1111
@arg('--release', help="build from build image if it exists")
1212
@arg('--push', help="tag release and meta image with version and push to registry")
13-
def build(push=False, release=False):
13+
@arg('--phase', help="lain cluster phase id, can be added by lain config save")
14+
def build(phase=None, push=False, release=False):
1415
"""
1516
Build release and meta images
1617
"""
1718

1819
info("Building meta and release images ...")
1920
validate_only_warning()
20-
yml = lain_yaml()
21+
stage = get_phase_stage(phase) if phase else None
22+
yml = lain_yaml(stage=stage)
2123
meta_version = yml.repo_meta_version()
2224
use_prepare = docker.exist(yml.img_names['prepare'])
2325
use_build = release and docker.exist(yml.img_names['build'])
@@ -38,4 +40,4 @@ def build(push=False, release=False):
3840
tag_meta_name = yml.tag_meta_version(meta_name)
3941
docker.tag(meta_name, tag_meta_name)
4042
docker.push(tag_meta_name)
41-
info("Done lain build.")
43+
info("Done lain build.")

lain_cli/deploy.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from lain_sdk.util import error, info
1010
from lain_cli.auth import SSOAccess, authorize_and_check, get_auth_header
11-
from lain_cli.utils import check_phase, get_domain, lain_yaml, is_resource_instance
11+
from lain_cli.utils import check_phase, get_domain, lain_yaml, is_resource_instance, get_phase_stage
1212
from lain_cli.utils import reposit_app, get_version_lists, get_app_state
1313
from lain_cli.utils import render_app_status, render_proc_status
1414

@@ -24,7 +24,8 @@ def deploy(phase, version=None, target=None, proc=None, output='pretty'):
2424
"""
2525

2626
check_phase(phase)
27-
yml = lain_yaml(ignore_prepare=True)
27+
stage = get_phase_stage(phase)
28+
yml = lain_yaml(ignore_prepare=True, stage=stage)
2829
appname = target if target else yml.appname
2930
authorize_and_check(phase, appname)
3031

@@ -62,7 +63,7 @@ def deploy_app(phase, appname, console, auth_header, version, output):
6263
deploy_params = {"meta_version": deploy_version}
6364
else:
6465
deploy_version = valid_version
65-
66+
6667
deploy_r = requests.put(app_url, headers=auth_header, json=deploy_params)
6768
elif app_r.status_code == 404:
6869
operation = "deploying"

lain_cli/enter.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from entryclient import EntryClient
44
from lain_sdk.util import error
55
from lain_cli.auth import SSOAccess, authorize_and_check
6-
from lain_cli.utils import check_phase, lain_yaml, get_domain
6+
from lain_cli.utils import check_phase, lain_yaml, get_domain, get_phase_stage
77

88
import os
99

@@ -16,7 +16,8 @@ def enter(phase, proc_name, instance_no, target=None):
1616
"""
1717

1818
check_phase(phase)
19-
yml = lain_yaml(ignore_prepare=True)
19+
stage = get_phase_stage(phase)
20+
yml = lain_yaml(ignore_prepare=True, stage=stage)
2021
appname = target if target else yml.appname
2122
authorize_and_check(phase, appname)
2223
domain = get_domain(phase)

lain_cli/imagecheck.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def _check_phase_tag(phase):
3232

3333

3434
@arg('phase', help="lain phase, can be added by lain config save")
35-
def check(phase):
35+
def check(phase):
3636
"""
3737
Check current version of release and meta images in the remote registry
3838
"""

lain_cli/logout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def logout(phase):
1717
domain = get_domain(phase)
1818
logout_success = SSOAccess.clear_token(phase)
1919
if logout_success:
20-
docker.logout('registry.%s'%domain)
20+
docker.logout('registry.%s'%domain)
2121
info("Logout successfully!")
2222
else:
2323
warn('Logout failed!')

lain_cli/maintainer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def show(cls, phase, username=None):
3333
3434
username: sso username
3535
"""
36-
36+
3737
check_phase(phase)
3838
yml = lain_yaml(ignore_prepare=True)
3939
authorize_and_check(phase, yml.appname)
@@ -44,7 +44,7 @@ def show(cls, phase, username=None):
4444
console, yml.appname)
4545
if username:
4646
maintainer_url += '%s/' % username
47-
47+
4848
show_response = requests.get(maintainer_url, headers=auth_header)
4949
if show_response.status_code < 300:
5050
info("maintainer detail:")
@@ -60,7 +60,7 @@ def add(cls, phase, username, role):
6060
"""
6161
add maintianer for different phase
6262
"""
63-
63+
6464
check_phase(phase)
6565
yml = lain_yaml(ignore_prepare=True)
6666
authorize_and_check(phase, yml.appname)
@@ -91,7 +91,7 @@ def delete(cls, phase, username):
9191
authorize_and_check(phase, yml.appname)
9292
auth_header = get_auth_header(SSOAccess.get_token(phase))
9393
console = "console.%s" % get_domain(phase)
94-
94+
9595
maintainer_url = "http://%s/api/v1/repos/%s/maintainers/%s/" % (
9696
console, yml.appname, username)
9797

lain_cli/ps.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from lain_sdk.util import error
77
from lain_cli.auth import SSOAccess, get_auth_header, authorize_and_check
8-
from lain_cli.utils import check_phase, get_domain, lain_yaml
8+
from lain_cli.utils import check_phase, get_domain, lain_yaml, get_phase_stage
99
from lain_cli.utils import render_app_status
1010

1111

@@ -17,7 +17,8 @@ def ps(phase, output='pretty'):
1717
"""
1818

1919
check_phase(phase)
20-
yml = lain_yaml(ignore_prepare=True)
20+
stage = get_phase_stage(phase)
21+
yml = lain_yaml(ignore_prepare=True, stage=stage)
2122
authorize_and_check(phase, yml.appname)
2223
console = "console.%s" % get_domain(phase)
2324

0 commit comments

Comments
 (0)