def get_token(self): panacube_ip = "http://" + GetModel.panacube_ip() url = '{}/v1/management/login/'.format(panacube_ip) username, password = GetModel.account() current_app.logger.info('panacube登录username={}, password={}'.format( username, password)) if username and password: try: resp = requests.post(url, data={ "username": username, "password": password }, verify=False) except Exception as e: raise e current_app.logger.info(resp.json()) return resp.json().get('data').get('token') current_app.logger.error('参数有误--->username={}, password={}'.format( username, password)) return { 'code': 1, 'message': '参数有误--->username={}, password={}'.format(username, password) }
def block(): if str(GetModel.deploy_type()) == 'kvm': if os.path.exists('/usr/local/udsafe/automatedkvm.txt'): with open('/usr/local/udsafe/automatedkvm.txt', 'r') as f: kvm_ip = f.read() return json.dumps({'ip': kvm_ip}) else: w_kvm = { 'ip': GetModel.kvm_ip() } os.system('mkdir -p /usr/local/udsafe/') with open('/usr/local/udsafe/automatedkvm.txt', 'wb') as f: f.write(GetModel.kvm_ip()) return json.dumps(w_kvm) else: return json.dumps({'ip': GetModel.panacube_ip()})
def get_node(self): panacube_ip = "http://" + GetModel.panacube_ip() ip_data = [] url = '{}/v1/monitor/undefined/TubePhyHost/'.format(panacube_ip) get_token = self.get_token() if 'code' in get_token and get_token['code'] == 1: return get_token resp = requests.get( url, headers={"Authorization": 'TOKEN ' + self.get_token()}, verify=False) current_app.logger.info("get nodes info: {}".format(resp.json())) for i in resp.json()['data']: ip_data.append({ "node-name": i['hostName'], "ip": i['hostInfo']['ips']['br_mgmt'] }) return ip_data
def push_message(): """ 消息推送 :return: """ URL = 'http://{}/awstack-user/v1/params'.format(GetModel.awcloud_ip()) current_app.logger.info('message push API: {}'.format(URL)) manager = AWCloudManage('', '') is_login = True while is_login: try: manager._login() is_login = False except ConnectionError as e: print "docker 未启动连接失败" time.sleep(3) headers = manager.get_auth_header() body = { "enterpriseUid": "66666666666666666666666666666666", "paramValue": "http://{}/v1/awcloud-message/".format(GetModel.panacube_ip()), "paramName": "resource_pass", "parentId": 939, "regionUid": "8b4f22a536f845769820b5777d549238", "paramLevel": 2, "paramDesc": "消息推送", "regionKey": 0 } resp = requests.post(URL, data=json.dumps(body), headers=headers) current_app.logger.info("message return info: {}".format(resp.json())) if resp.json().get('code') == '01170101': print 'push message: 参数名称已存在' current_app.logger.info('push message: 添加消息推送成功')