def get_node_manage_nic_name(node_uuid): networks = model_query(YzyNodeNetworkInfo).filter_by(node_uuid=node_uuid).all() for nic in networks: interface = model_query(YzyInterfaceIp).filter_by(nic_uuid=nic.uuid).first() if interface and interface.is_manage: return interface.name return None
def update_voi_terminal_desktop_bind(desktop_group_uuid, terminal_mac, info): update_data = { 'updated_at': datetime.datetime.utcnow(), } update_data.update(info) model_query(YzyVoiTerminalToDesktops).filter_by( desktop_group_uuid=desktop_group_uuid, terminal_mac=terminal_mac).update(update_data)
def get_education_ipaddr(subnet_uuid): ips = list() education_desktops = model_query(YzyDesktop).filter_by( subnet_uuid=subnet_uuid).all() for desktop in education_desktops: instances = model_query(YzyInstances).filter_by( desktop_uuid=desktop.uuid).all() for instance in instances: if instance.ipaddr and instance.ipaddr not in ips: ips.append(instance.ipaddr) return ips
def get_nodes_by_uuids(node_uuids): """ :param node_uuids: :return: """ _tmp = [] for i in node_uuids: if i: _tmp.append(i) if _tmp: nodes = model_query(YzyNodes).filter(YzyNodes.uuid.in_(_tmp)).all() else: nodes = model_query(YzyNodes).all() return nodes
def update_voi_terminal_desktop_info(values): update_data = { 'updated_at': datetime.datetime.utcnow(), } update_data.update(values) desktop_group_uuid = values.get('desktop_group_uuid', None) if desktop_group_uuid: model_query(YzyVoiTerminalToDesktops).filter_by( desktop_group_uuid=values['desktop_group_uuid'], terminal_mac=values['terminal_mac']).update(update_data) else: model_query(YzyVoiTerminalToDesktops).filter_by( terminal_mac=values['terminal_mac']).update(update_data)
def get_network_by_nic(nic_uuid, node_uuid): nets = model_query(YzyNetworks).\ join(YzyVswitchUplink, YzyNetworks.switch_uuid == YzyVswitchUplink.vs_uuid).\ join(YzyNodeNetworkInfo, YzyVswitchUplink.nic_uuid == YzyNodeNetworkInfo.uuid).\ filter(YzyVswitchUplink.nic_uuid == nic_uuid). \ filter(YzyVswitchUplink.node_uuid == node_uuid).all() return nets
def get_interface_by_network(network_uuid, node_uuid): net = model_query(YzyNetworks, YzyNodeNetworkInfo.nic).\ join(YzyVswitchUplink, YzyNetworks.switch_uuid == YzyVswitchUplink.vs_uuid).\ join(YzyNodeNetworkInfo, YzyVswitchUplink.nic_uuid == YzyNodeNetworkInfo.uuid).\ filter(YzyNetworks.uuid == network_uuid).\ filter(YzyVswitchUplink.node_uuid == node_uuid).first() return net
def get_task_step(task_id): try: result = model_query(YzyTaskInfo).filter_by(task_id=task_id).order_by( YzyTaskInfo.step.desc()).first() return result.step except Exception: return 0
def get_voi_template_ipaddr(): ips = list() items = model_query(YzyVoiTemplate.bind_ip).all() for item in items: if item[0] and item[0] not in ips: ips.append(item[0]) return ips
def get_monitor_info(node_uuid, hours): end_datetime = dt.datetime.now() start_datetime = end_datetime - dt.timedelta(hours=hours) results = model_query(YzyMonitorHalfMin).filter( YzyMonitorHalfMin.node_uuid == node_uuid, start_datetime <= YzyMonitorHalfMin.node_datetime <= end_datetime).all() return results
def get_distinct_course_schedule_week_nums(item): """ 查询yzy_course_schedule表中不同的week_num值 :param item: 查询yzy_course_schedule的过滤条件 :return: [(1, ), (2, ), ...] """ return model_query( YzyCourseSchedule.week_num).filter_by(**item).distinct().all()
def get_distinct_course_template_uuids_by_course(item): """ 查询yzy_course表中不同的course_template_uuid值 :param item: 查询yzy_course的过滤条件 :return: [("0d86933a-b3d0-42ef-83b0-d0aad7ca1a7f", ), ("2f3f0d3e-aaed-480e-aa4c-7dc6b91d025f", ), ...] """ return model_query( YzyCourse.course_template_uuid).filter_by(**item).distinct().all()
def select_controller_image_ip(): # 1. get controller uuid qry_node = model_query(YzyNodes).filter(YzyNodes.type.in_((1, 3))).first() if qry_node and qry_node.uuid: controller_uuid = qry_node.uuid else: return None qry_node_network_info = model_query(YzyNodeNetworkInfo).filter_by(node_uuid=controller_uuid).all() if qry_node_network_info: uuid_tuple = tuple([x.uuid for x in qry_node_network_info]) qry_interface_ip = model_query(YzyInterfaceIp).filter(YzyInterfaceIp.nic_uuid.in_(uuid_tuple))\ .filter_by(is_image=1).filter_by(deleted=0) if qry_interface_ip: return qry_interface_ip.first() else: return None else: return None
def get_resource_pool_by_key(key, val): _query = model_query(YzyResourcePool) if key == "name": _query = _query.filter_by(name=val) elif key == "id": _query = _query.filter_by(id=val) else: _query = _query.filter_by(uuid=val) res_pool = _query.first() return res_pool
def get_remote_storage_by_key(key, val): _query = model_query(YzyRemoteStorage) if key == "name": _query = _query.filter_by(name=val) elif key == "server": _query = _query.filter_by(server=val) else: _query = _query.filter_by(uuid=val) res_rs = _query.first() return res_rs
def get_instance_data_storage(node_uuid): storage = model_query(YzyNodeStorages).filter(node_uuid == node_uuid).\ filter(YzyNodeStorages.role.contains(str(constants.INSTANCE_DATA))).first() return storage
def get_template_data_storage(node_uuid): storage = model_query(YzyNodeStorages).filter(node_uuid == node_uuid).\ filter(YzyNodeStorages.role.contains(str(constants.TEMPLATE_DATA))).first() return storage
def get_node_by_uuid(node_uuid): node = model_query(YzyNodes).filter_by(uuid=node_uuid).first() return node
def get_controller_image(): nic = model_query(YzyNodeNetworkInfo, YzyInterfaceIp.ip).join(YzyNodes).join(YzyInterfaceIp). \ filter(YzyNodes.type.in_([constants.ROLE_MASTER_AND_COMPUTE, constants.ROLE_MASTER])). \ filter(YzyInterfaceIp.is_image == 1).first() return nic
def get_backup_node(): node = model_query(YzyNodes).filter(YzyNodes.type.in_([constants.ROLE_SLAVE_AND_COMPUTE, constants.ROLE_SLAVE])).first() return node
def get_controller_node(): node = model_query(YzyNodes).filter(YzyNodes.type.in_([constants.ROLE_MASTER_AND_COMPUTE, constants.ROLE_MASTER])).first() return node
def clear_monitor_half_min(last_days): now_datatime = dt.datetime.now() model_query(YzyMonitorHalfMin).filter( YzyMonitorHalfMin.node_datetime < (now_datatime - dt.timedelta(days=last_days))).delete()
def get_ha_info_first(): return model_query(YzyHaInfo).first()
def get_ha_info_all(): ha_infos = model_query(YzyHaInfo).all() return ha_infos
def get_ha_info_by_uuid(ha_uuid): ha_info = model_query(YzyHaInfo).filter_by(uuid=ha_uuid).first() return ha_info
def get_node_by_ip(ipaddr): node = model_query(YzyNodes).filter_by(ip=ipaddr).first() return node
def get_service_by_uuid(service_uuid): service = model_query(YzyNodeServices).filter_by(uuid=service_uuid).first() return service
def get_node_with_first(item): nodes = model_query(YzyNodes).filter_by(**item).first() return nodes
def get_node_by_pool_uuid(pool_uuid): nodes = model_query(YzyNodes).filter_by(resource_pool_uuid=pool_uuid).all() return nodes
def get_service_by_name(service_name): service = model_query(YzyNodeServices).filter_by(name=service_name).first() return service