def update_host_status(host_id, status): host_data = db.host[host_id] host_ip = host_data.host_ip.private_ip logger.debug(host_ip) host_info=host_data.host_type logger.debug(host_info) if status == HOST_STATUS_UP: if is_host_available(host_ip): if host_data.CPUs == 0: cpu_num = get_host_cpu(host_ip) ram_gb = get_host_ram(host_ip) hdd_gb = get_host_hdd(host_ip) host_data.update_record(CPUs=cpu_num, RAM=ram_gb, HDD=hdd_gb) else: host_power_up(host_data) host_data.update_record(status = HOST_STATUS_UP) elif status == HOST_STATUS_MAINTENANCE: migrate_all_vms_from_host(host_ip) host_data.update_record(status=HOST_STATUS_MAINTENANCE) elif status == HOST_STATUS_DOWN: host_power_down(host_data) host_data.update_record(status = HOST_STATUS_DOWN ) return True
def get_host_form(host_ip): form = get_add_host_form() form.vars.host_name = 'host' + str(host_ip.split('.')[3]) form.vars.host_ip = host_ip if is_host_available(host_ip): form.vars.mac_addr = get_host_mac_address(host_ip) form.vars.CPUs = get_host_cpu(host_ip) form.vars.RAM = get_host_ram(host_ip) form.vars.HDD = get_host_hdd(host_ip) form.vars.host_type = get_host_type(host_ip) form.vars.status = HOST_STATUS_UP else: form.vars.status = HOST_STATUS_DOWN return form
def get_host_form(host_ip): form = get_add_host_form() private_ip_data = db.private_ip_pool(private_ip = host_ip) if private_ip_data: form.vars.host_ip = private_ip_data.id form.vars.host_name = 'host'+str(host_ip.split('.')[3]) if is_host_available(host_ip): form.vars.CPUs = get_host_cpu(host_ip) form.vars.RAM = get_host_ram(host_ip) form.vars.HDD = get_host_hdd(host_ip) form.vars.host_type = get_host_type(host_ip) form.vars.status = HOST_STATUS_UP else: form.vars.status = HOST_STATUS_DOWN return form