def create_server_image(server_instance_id): base_auth_info = BaseAuthInfo() req_path = '/server/v2/createMemberServerImage?serverInstanceNo={0}&responseFormatType=json'. \ format(server_instance_id) base_auth_info.set_req_path(req_path) sender = APISender(base_auth_info) response = sender.request() res_list = response.read() print(json.loads(res_list.decode('utf-8')))
def block_storage_list(): base_auth_info = BaseAuthInfo() req_path = '/server/v2/getBlockStorageInstanceList?responseFormatType=json' base_auth_info.set_req_path(req_path) sender = APISender(base_auth_info) response = sender.request() if response.getcode() == 200: res_list = response.read() return res_list else: print("" + response)
def create_block_storage_snapshot(storage_instance_id): base_auth_info = BaseAuthInfo() req_path = '/server/v2/createBlockStorageSnapshotInstance?blockStorageInstanceNo={0}&responseFormatType=json'.\ format(storage_instance_id) base_auth_info.set_req_path(req_path) sender = APISender(base_auth_info) response = sender.request() if response.getcode() == 200: print(">> snapshot success : " + storage_instance_id) else: print(""+response)
def server_instance_list(instance_no): base_auth_info = BaseAuthInfo() req_path = '/server/v2/getServerInstanceList?serverInstanceNoList.1='+instance_no+'&responseFormatType=json' base_auth_info.set_req_path(req_path) sender = APISender(base_auth_info) response = sender.request() if response.getcode() == 200: res_list = response.read() return res_list else: print("" + response)
def create_block_storage_snapshot(storage_instance_id): base_auth_info = BaseAuthInfo() req_path = '/vserver/v2/createBlockStorageSnapshotInstance?originalBlockStorageInstanceNo={0}&responseFormatType=json'.\ format(storage_instance_id) base_auth_info.set_req_path(req_path) sender = APISender(base_auth_info) response = sender.request() rescode = response.status_code if rescode == 200: print("snapshot success") else: print("Error Code:" + response.text)
def stop_server(server_instance_id): base_auth_info = BaseAuthInfo() req_path = '/vserver/v2/stopServerInstances?serverInstanceNoList.1={0}&responseFormatType=json'. \ format(server_instance_id) base_auth_info.set_req_path(req_path) sender = APISender(base_auth_info) response = sender.request() rescode = response.status_code if rescode == 200: print(response.text) else: print("Error : " + response.text)
def server_instance_list(instance_no): base_auth_info = BaseAuthInfo() print(">>>>>>>>> " + instance_no) req_path = '/vserver/v2/getServerInstanceList?serverInstanceNoList.1=' + instance_no + '&responseFormatType=json' base_auth_info.set_req_path(req_path) sender = APISender(base_auth_info) response = sender.request() rescode = response.status_code if rescode == 200: print(response.text) instance_info = response.text return instance_info else: print("Error Code:" + rescode)
def block_storage_list(): base_auth_info = BaseAuthInfo() req_path = '/vserver/v2/getBlockStorageInstanceList?responseFormatType=json' base_auth_info.set_req_path(req_path) sender = APISender(base_auth_info) response = sender.request() rescode = response.status_code if rescode == 200: print(response.text) res_list = response.text return res_list else: print("Error Code:" + rescode)
def main(): try: if request.json['type'] != 'message_new': return 'ok' if 'CONFIG' in os.environ: config = get_config(os.environ['CONFIG']) else: print 'No config provided' print 'Args', request.args print 'Got JSON', request.json json = request.json['object'] vk = VKSender(config.VK.PATH, config.VK.TOKEN, config.VK.API_VERSION, json['user_id']) api = APISender(config.API.PATH, json['user_id']) command = json['body'].strip().lower() message = 'test' attachments = None if ' ' in command: command, args = command.split(' ', 1) print 'COMMAND', command good_command = any(command == def_command for def_command in config.commands) if not good_command or command == '/help': message = get_help_message(config.commands) elif command in ['/show_courses', '/leave']: courses = api.get_courses() message = create_courses_list(courses) elif command == '/take_course': course_id = args resp = api.get_lesson(course_id) print 'take', resp message = prepare_lesson(resp['body']) if resp['body']['attachments']: attachments = ','.join([ '{}-{}_{}'.format(obj['type'], abs(int(obj['owner'])), obj['media']) for obj in resp['body']['attachments'] ]) api.update_state(resp['course_id'], resp['lesson_id']) print 'afte all' elif command in ['/next', '/prev']: direction = command[1:] resp = api.get_last_lesson(direction) is_end = resp['do_update'] print 'IS_END', is_end print 'RESP', resp message = prepare_lesson(resp['body'], is_end, direction) if isinstance(resp['body'], dict) and resp['body']['attachments']: attachments = ','.join([ '{}-{}_{}'.format(obj['type'], obj['owner'], obj['media']) for obj in resp['body']['attachments'] ]) print attachments api.update_state(resp['course_id'], resp['lesson_id']) elif command == '/comment': resp = api.get_last_lesson() is_end = resp['do_update'] if is_end == 2: api.send_review(args, resp['course_id']) message = 'Спасибо за ваш отзыв' else: message = ('Вы не можете оставить отзыв о курсе, т.к. ещё не ' 'прошли последний урок') elif command == '/overview': titles = api.get_titles(args) message = prepare_overview(titles) elif command == '/progress': progress = api.get_progress() message = 'Текущий прогресс по вашим курсам\n'.join(progress) elif command == '/answer': message = api.send_quiz(args) elif command == '/start': message = get_man_message() vk.send_message(message, attachments) except Exception as e: print e.message print e finally: return 'ok'
from api_sender import APISender from sio import SIO from config import Config from pathlib import Path from state_manager import StateManager import threading CONF_DIRECTORY = str(Path.home()) + "\\aircom\\conf.ini" BACKEND_URL = "http://api.myaircom.co.kr" config = Config(CONF_DIRECTORY) sender = APISender(BACKEND_URL) if __name__ == "__main__": uuid = config.getValue('id', 'uuid') if (not uuid): auth_token = input("홈페이지에서 발급받은 인증코드를 입력하세요 : ") ip = input("공인 ip를 입력하세요 : ") ports = input("포트포워딩된 포트를 입력하세요(7개, 공백으로 구분) : ").split() uuid = sender.register(auth_token, ip, ports) if uuid: print("등록 완료!") config.setValue("id", "uuid", uuid) else: print("authorized failed") exit() state_mgr = StateManager() mgr_thread = threading.Thread(target=state_mgr.manage_run) mgr_thread.start() SIO(BACKEND_URL, uuid, state_mgr)