def create_cntr(cntr_name, gpu, sol_name, sol_img, isWait): def_header = sites.getGpuDefaultHeader(gpu) a = solutions() cntrs = dict([(cntr['name'], cntr['id']) for cntr in a.list() if not cntr['id'] in block_set and cntr['name']==sol_name]) if len(cntrs)>0: sol_id = cntrs[sol_name] else: raise ValueError("Solution name '{0}' for '{1}' is not valid.".format(sol_img, sol_name)) b = sites(debug=False) imgs = b.getAvblImg(sol_id, sol_name, latest_first=True) if type(sol_img) == type(None) or len(sol_name)==0: def_header['x-extra-property-image'] = imgs[0] else: if sol_img in imgs: def_header['x-extra-property-image'] = sol_img else: raise ValueError("Container image '{0}' for '{1}' is not valid.".format(sol_img, sol_name)) res = b.create(cntr_name, sol_id, def_header) if 'id' not in res.keys(): if 'message' in res: raise ValueError("Can't find id, please check error message : {}".format(res['message'])) if 'detail' in res: raise ValueError("Can't find id, please check error message : {}".format(res['detail'])) else: print("Site id: {0} is created.".format(res['id'])) if isWait: doSiteReady(res['id']) return int(res['id'])
def doSiteReady(site_id): b = sites(debug=False) wait_ready = False while not wait_ready: print("Waiting for container to be Ready.") if b.isReady(site_id): wait_ready = True time.sleep(5) return site_id
def del_cntr(con_ids): a = sites() if type(con_ids) == type(1): con_ids = [con_ids] if len(list(con_ids)) > 0: for con_id in con_ids: a.delete(con_id) print("Successfully remove {}".format(con_id)) else: print("Need to enter Container ID")
def list_all_img(): print("NOTE: This operation will take 1~2 mins.") a = solutions() cntrs = [(cntr['name'], cntr['id']) for cntr in a.list() if not cntr['id'] in block_set] sol_list = sites.getSolList(name_only=True) base_site = sites(debug=False) output = [] for (sol_name, sol_id) in cntrs: output.append({ "sol_name": sol_name, "sol_id": sol_id, "images": base_site.getAvblImg(sol_id, sol_name) }) table_layout("img", output, ['sol_name', 'sol_id', 'images'])
def create_commit(): a = sites() isAll = True; if type(a.list(isAll=isAll)) is dict and 'detail' in a.list(isAll=isAll).keys(): isAll = False my_sites = a.list(isAll=isAll) if len(my_sites)>0: col_name = ['id','name', 'create_time', 'status'] table_layout('sites', my_sites, caption_row=col_name) site_id = get_input(u'Please Input the site ID which you would like to commit: ') tag = get_input(u'Please Input the image tag ') image = get_input(u'Please Input the image name: ') c = image_commit() print(c.createCommit(site_id, tag, image))
def list_cntr(site_id, isTable,isAll): if not type(site_id)==type(1): raise ValueError("Site number: '{0}' error.".format(site_id)) if not isTable: gen_cntr(site_id) else: a = sites() if type(a.list(isAll=isAll)) is dict and 'detail' in a.list(isAll=isAll).keys(): isAll = False # raise ValueError("{}, please change to Admin key".format(a.list(isAll=isAll)['detail'])) if site_id==0: my_sites = a.list(isAll=isAll) if len(my_sites)>0: col_name = ['id','name', 'create_time', 'status'] table_layout('sites', my_sites, caption_row=col_name) else: res = a.queryById(site_id) col_name = ['id','name', 'create_time', 'status', 'status_reason'] table_layout('sites: %s'%site_id, res, caption_row=col_name)
def list_s3(): b = sites() print(b.getAvblS3())
def gen_cntr(s_id): print("This is container information for connection. ") b = sites() site_id = s_id conn_info = b.getConnInfo(site_id) print (conn_info)
def get_site_detail(site_id): a = sites() return a.getDetail(site_id)
def get_all_info(): a = sites() return [ site_info for site_info in a.list(isAll=True)]
def del_all(): a = sites() [ a.delete(site_info['id']) for site_info in a.list()]