Skip to content
Open
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
5 changes: 3 additions & 2 deletions lain_cli/appversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from lain_sdk.util import warn, info
from lain_cli.auth import authorize_and_check
from lain_cli.utils import get_version_lists, lain_yaml, check_phase
from lain_cli.utils import get_version_lists, lain_yaml, check_phase, get_phase_stage


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

check_phase(phase)
yml = lain_yaml(ignore_prepare=True)
stage = get_phase_stage(phase)
yml = lain_yaml(ignore_prepare=True, stage=stage)
authorize_and_check(phase, yml.appname)

version_list = get_version_lists(phase, yml.appname)
Expand Down
5 changes: 3 additions & 2 deletions lain_cli/attach.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from entryclient import EntryClient
from lain_sdk.util import error, info
from lain_cli.auth import SSOAccess, authorize_and_check
from lain_cli.utils import check_phase, lain_yaml, get_domain
from lain_cli.utils import check_phase, lain_yaml, get_domain, get_phase_stage


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

check_phase(phase)
yml = lain_yaml(ignore_prepare=True)
stage = get_phase_stage(phase)
yml = lain_yaml(ignore_prepare=True, stage=stage)
appname = target if target else yml.appname
authorize_and_check(phase, appname)
domain = get_domain(phase)
Expand Down
26 changes: 17 additions & 9 deletions lain_cli/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from argh.decorators import arg, aliases

from lain_sdk.util import warn
from lain_cli.utils import lain_yaml_data, check_phase
from lain_cli.utils import lain_yaml_data, check_phase, get_phase_stage
from lain_cli.utils import TwoLevelCommandBase, get_domain


Expand All @@ -30,7 +30,8 @@ def jobs(cls, phase):
list backup jobs for this lain app
"""
check_phase(phase)
appname = lain_yaml_data()['appname']
stage = get_phase_stage(phase)
appname = lain_yaml_data(stage=stage)['appname']
route = "api/v2/app/%s/cron/jobs" % appname
data = cls._request('GET', phase, route, None)
if data:
Expand All @@ -46,7 +47,8 @@ def list(cls, phase, proc, path):
list files in the incremental backup direcotry
"""
check_phase(phase[0])
appname = lain_yaml_data()['appname']
stage = get_phase_stage(phase[0])
appname = lain_yaml_data(stage=stage)['appname']
route = "api/v2/app/%s/proc/%s/backups/%s?open=true" % (appname, proc[0], path[0])
data = cls._request('GET', phase[0], route, None)
if data:
Expand All @@ -63,7 +65,8 @@ def get(cls, phase, proc, volume):
get all the backups of the given proc's volume
"""
check_phase(phase[0])
appname = lain_yaml_data()['appname']
stage = get_phase_stage(phase[0])
appname = lain_yaml_data(stage=stage)['appname']
route = "api/v2/app/%s/proc/%s/backups?volume=%s" % (appname, proc[0], volume[0])
data = cls._request('GET', phase[0], route, None)
if data:
Expand All @@ -78,7 +81,8 @@ def delete(cls, phase, proc, files):
delete a backup of a proc
"""
check_phase(phase[0])
appname = lain_yaml_data()['appname']
stage = get_phase_stage(phase[0])
appname = lain_yaml_data(stage=stage)['appname']
route = "api/v2/app/%s/proc/%s/backups/actions/delete" % (appname, proc[0])
data = cls._request('POST', phase[0], route, {'files': files})
if data:
Expand All @@ -94,7 +98,8 @@ def recover(cls, phase, proc, backup, files):
recover the volume from given backup
"""
check_phase(phase[0])
appname = lain_yaml_data()['appname']
stage = get_phase_stage(phase[0])
appname = lain_yaml_data(stage=stage)['appname']
if not files:
route = "api/v2/app/%s/proc/%s/backups/%s/actions/recover" % (appname, proc[0], backup[0])
data = cls._request('POST', phase[0], route, None)
Expand All @@ -116,7 +121,8 @@ def migrate(cls, phase, proc, backup, files, volume="", to=0):
recover a instance's volume from other instance's backup
"""
check_phase(phase[0])
appname = lain_yaml_data()['appname']
stage = get_phase_stage(phase[0])
appname = lain_yaml_data(stage=stage)['appname']
if not files:
route = "api/v2/app/%s/proc/%s/backups/%s/actions/migrate" % (appname, proc[0], backup[0])
data = cls._request('POST', phase[0], route, {"volume": volume, "to": to})
Expand All @@ -135,7 +141,8 @@ def records(cls, phase, rid, num=10):
list job records of this lain app
"""
check_phase(phase[0])
appname = lain_yaml_data()['appname']
stage = get_phase_stage(phase[0])
appname = lain_yaml_data(stage=stage)['appname']
route = "api/v2/app/%s/cron/records" % appname
if rid:
route = "%s/%s" % (route, rid)
Expand All @@ -153,7 +160,8 @@ def run(cls, phase, id):
run a job right now
"""
check_phase(phase[0])
appname = lain_yaml_data()['appname']
stage = get_phase_stage(phase[0])
appname = lain_yaml_data(stage=stage)['appname']
route = "api/v2/app/%s/cron/jobs/%s/actions/run" % (appname, id[0])
data = cls._request('POST', phase[0], route, None)
if data:
Expand Down
8 changes: 5 additions & 3 deletions lain_cli/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@

import lain_sdk.mydocker as docker
from lain_sdk.util import error, warn, info
from lain_cli.utils import lain_yaml
from lain_cli.utils import lain_yaml, get_phase_stage
from lain_cli.validate import validate_only_warning


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

info("Building meta and release images ...")
validate_only_warning()
yml = lain_yaml()
stage = get_phase_stage(phase) if phase else None
yml = lain_yaml(stage=stage)
meta_version = yml.repo_meta_version()
use_prepare = docker.exist(yml.img_names['prepare'])
use_build = release and docker.exist(yml.img_names['build'])
Expand Down
7 changes: 4 additions & 3 deletions lain_cli/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from lain_sdk.util import error, info
from lain_cli.auth import SSOAccess, authorize_and_check, get_auth_header
from lain_cli.utils import check_phase, get_domain, lain_yaml, is_resource_instance
from lain_cli.utils import check_phase, get_domain, lain_yaml, is_resource_instance, get_phase_stage
from lain_cli.utils import reposit_app, get_version_lists, get_app_state
from lain_cli.utils import render_app_status, render_proc_status

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

check_phase(phase)
yml = lain_yaml(ignore_prepare=True)
stage = get_phase_stage(phase)
yml = lain_yaml(ignore_prepare=True, stage=stage)
appname = target if target else yml.appname
authorize_and_check(phase, appname)

Expand Down Expand Up @@ -62,7 +63,7 @@ def deploy_app(phase, appname, console, auth_header, version, output):
deploy_params = {"meta_version": deploy_version}
else:
deploy_version = valid_version

deploy_r = requests.put(app_url, headers=auth_header, json=deploy_params)
elif app_r.status_code == 404:
operation = "deploying"
Expand Down
5 changes: 3 additions & 2 deletions lain_cli/enter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from entryclient import EntryClient
from lain_sdk.util import error
from lain_cli.auth import SSOAccess, authorize_and_check
from lain_cli.utils import check_phase, lain_yaml, get_domain
from lain_cli.utils import check_phase, lain_yaml, get_domain, get_phase_stage

import os

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

check_phase(phase)
yml = lain_yaml(ignore_prepare=True)
stage = get_phase_stage(phase)
yml = lain_yaml(ignore_prepare=True, stage=stage)
appname = target if target else yml.appname
authorize_and_check(phase, appname)
domain = get_domain(phase)
Expand Down
2 changes: 1 addition & 1 deletion lain_cli/imagecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def _check_phase_tag(phase):


@arg('phase', help="lain phase, can be added by lain config save")
def check(phase):
def check(phase):
"""
Check current version of release and meta images in the remote registry
"""
Expand Down
2 changes: 1 addition & 1 deletion lain_cli/logout.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def logout(phase):
domain = get_domain(phase)
logout_success = SSOAccess.clear_token(phase)
if logout_success:
docker.logout('registry.%s'%domain)
docker.logout('registry.%s'%domain)
info("Logout successfully!")
else:
warn('Logout failed!')
8 changes: 4 additions & 4 deletions lain_cli/maintainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def show(cls, phase, username=None):

username: sso username
"""

check_phase(phase)
yml = lain_yaml(ignore_prepare=True)
authorize_and_check(phase, yml.appname)
Expand All @@ -44,7 +44,7 @@ def show(cls, phase, username=None):
console, yml.appname)
if username:
maintainer_url += '%s/' % username

show_response = requests.get(maintainer_url, headers=auth_header)
if show_response.status_code < 300:
info("maintainer detail:")
Expand All @@ -60,7 +60,7 @@ def add(cls, phase, username, role):
"""
add maintianer for different phase
"""

check_phase(phase)
yml = lain_yaml(ignore_prepare=True)
authorize_and_check(phase, yml.appname)
Expand Down Expand Up @@ -91,7 +91,7 @@ def delete(cls, phase, username):
authorize_and_check(phase, yml.appname)
auth_header = get_auth_header(SSOAccess.get_token(phase))
console = "console.%s" % get_domain(phase)

maintainer_url = "http://%s/api/v1/repos/%s/maintainers/%s/" % (
console, yml.appname, username)

Expand Down
5 changes: 3 additions & 2 deletions lain_cli/ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from lain_sdk.util import error
from lain_cli.auth import SSOAccess, get_auth_header, authorize_and_check
from lain_cli.utils import check_phase, get_domain, lain_yaml
from lain_cli.utils import check_phase, get_domain, lain_yaml, get_phase_stage
from lain_cli.utils import render_app_status


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

check_phase(phase)
yml = lain_yaml(ignore_prepare=True)
stage = get_phase_stage(phase)
yml = lain_yaml(ignore_prepare=True, stage=stage)
authorize_and_check(phase, yml.appname)
console = "console.%s" % get_domain(phase)

Expand Down
5 changes: 3 additions & 2 deletions lain_cli/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from lain_sdk.util import error, info
import lain_sdk.mydocker as docker
from lain_cli.utils import check_phase, lain_yaml, get_domain
from lain_cli.utils import check_phase, lain_yaml, get_domain, get_phase_stage


@arg('phase', help="lain cluster phase id, can be added by lain config save")
Expand All @@ -15,7 +15,8 @@ def push(phase):

check_phase(phase)
info("Pushing meta and release images ...")
yml = lain_yaml(ignore_prepare=True)
stage = get_phase_stage(phase)
yml = lain_yaml(ignore_prepare=True, stage=stage)
meta_version = yml.repo_meta_version()
if meta_version is None:
error("please git commit.")
Expand Down
5 changes: 3 additions & 2 deletions lain_cli/reposit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from lain_sdk.util import info
from lain_cli.auth import SSOAccess, get_auth_header, authorize_and_check
from lain_cli.utils import check_phase, lain_yaml, reposit_app, get_domain
from lain_cli.utils import check_phase, lain_yaml, reposit_app, get_domain, get_phase_stage
from lain_cli.validate import validate_only_warning


Expand All @@ -17,7 +17,8 @@ def reposit(phase):
validate_only_warning()
info("Repositing ...")

yml = lain_yaml(ignore_prepare=True)
stage = get_phase_stage(phase)
yml = lain_yaml(ignore_prepare=True, stage=stage)
authorize_and_check(phase, yml.appname)

access_token = SSOAccess.get_token(phase)
Expand Down
5 changes: 3 additions & 2 deletions lain_cli/rmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
from argh.decorators import arg

import lain_sdk.mydocker as docker
from lain_cli.utils import check_phase
from lain_cli.utils import check_phase, get_phase_stage
from lain_cli.utils import lain_yaml, get_meta_versions_from_tags, get_domain


def get_repo_tags_to_remove(phase):
yml = lain_yaml(ignore_prepare=True)
stage = get_phase_stage(phase)
yml = lain_yaml(ignore_prepare=True, stage=stage)
domain = get_domain(phase)
registry = "registry.%s" % domain
all_tags = docker.get_tag_list_in_docker_daemon(registry, yml.appname)
Expand Down
14 changes: 8 additions & 6 deletions lain_cli/scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from argh.decorators import arg

from lain_sdk.util import error, warn, info
from lain_cli.utils import check_phase, lain_yaml, get_domain, render_proc_status, get_apptype
from lain_cli.utils import check_phase, lain_yaml, get_domain, render_proc_status, get_apptype, get_phase_stage
from lain_cli.auth import SSOAccess, authorize_and_check, get_auth_header


Expand All @@ -20,7 +20,8 @@ def scale(phase, proc, target=None, cpu=None, memory=None, numinstances=None, ou
"""

check_phase(phase)
yml = lain_yaml(ignore_prepare=True)
stage = get_phase_stage(phase)
yml = lain_yaml(ignore_prepare=True, stage=stage)
appname = target if target else yml.appname
authorize_and_check(phase, appname)

Expand Down Expand Up @@ -74,7 +75,7 @@ def scale(phase, proc, target=None, cpu=None, memory=None, numinstances=None, ou
'payload': payload1,
'success': scale_r.status_code < 300
}
render_scale_result(scale_r, output)
render_scale_result(phase, scale_r, output)

if numinstances is not None:
payload2['num_instances'] = numinstances
Expand All @@ -87,7 +88,7 @@ def scale(phase, proc, target=None, cpu=None, memory=None, numinstances=None, ou
'payload': payload2,
'success': scale_r.status_code < 300
}
render_scale_result(scale_r, output)
render_scale_result(phase, scale_r, output)

info("Outline of scale result: ")
for k, v in scale_results.iteritems():
Expand Down Expand Up @@ -136,13 +137,14 @@ def validate_parameters(cpu, memory, numinstances):
return cpu, memory, numinstances


def render_scale_result(scale_result, output):
def render_scale_result(phase, scale_result, output):
stage = get_phase_stage(phase)
try:
result = scale_result.json()
msg = result.pop('msg', '')
if msg:
print msg.decode('string_escape')
info("proc status: ")
render_proc_status(result.get('proc'), get_apptype(), output=output)
render_proc_status(result.get('proc'), get_apptype(stage=stage), output=output)
except Exception:
pprint.pprint(scale_result.content)
Loading