def show_config(args_str=None):
    parser = parse_arguments()
    args = parser.parse_args(args_str)
    if args.config_file:
        config_file = args.config_file
    else:
        config_file = smgr_client_def._DEF_SMGR_CFG_FILE
    # end args.config_file
    if hasattr(args, 'detail'):
        detail = args.detail
    else:
        detail = None
    try:
        config = ConfigParser.SafeConfigParser()
        config.read([config_file])
        smgr_config = dict(config.items("SERVER-MANAGER"))
        smgr_ip = smgr_config.get("listen_ip_addr", None)
        if not smgr_ip:
            sys.exit(("listen_ip_addr missing in config file"
                      "%s" % config_file))
        smgr_port = smgr_config.get("listen_port",
                                    smgr_client_def._DEF_SMGR_PORT)
    except Exception as e:
        sys.exit("Exception: %s : Error reading config file %s" %
                 (e.message, config_file))
    # end except
    rest_api_params = args.func(args)
    resp = send_REST_request(smgr_ip, smgr_port, rest_api_params, detail)
    smgr_client_def.print_rest_response(resp)
def show_status(args_str=None):
    parser = parse_arguments()
    args = parser.parse_args(args_str)
    if args.config_file:
        config_file = args.config_file
    else:
        config_file = smgr_client_def._DEF_SMGR_CFG_FILE
    # end args.config_file
    if hasattr(args, 'detail'):
        detail = args.detail
    else:
        detail = None
    try:
        config = ConfigParser.SafeConfigParser()
        config.read([config_file])
        smgr_config = dict(config.items("SERVER-MANAGER"))
        smgr_ip = smgr_config.get("listen_ip_addr", None)
        if not smgr_ip:
            sys.exit(("listen_ip_addr missing in config file"
                      "%s" %config_file))
        smgr_port = smgr_config.get("listen_port", smgr_client_def._DEF_SMGR_PORT)
    except:
        sys.exit("Error reading config file %s" %config_file)
    # end except
    rest_api_params = args.func(args)
    resp = send_REST_request(smgr_ip, smgr_port,
                      rest_api_params['object']+"_status",
                      rest_api_params['match_key'],
                      rest_api_params['match_value'],
                      detail)
    smgr_client_def.print_rest_response(resp)
Exemple #3
0
def delete_config(args_str=None):
    parser = parse_arguments()
    args = parser.parse_args(args_str)
    if args.config_file:
        config_file = args.config_file
    else:
        config_file = smgr_client_def._DEF_SMGR_CFG_FILE
    # end args.config_file
    try:
        config = ConfigParser.SafeConfigParser()
        config.read([config_file])
        smgr_config = dict(config.items("SERVER-MANAGER"))
        smgr_ip = smgr_config.get("listen_ip_addr", None)
        if not smgr_ip:
            sys.exit(("listen_ip_addr missing in config file"
                      "%s" %config_file))
        smgr_port = smgr_config.get("listen_port", smgr_client_def._DEF_SMGR_PORT)
    except:
        sys.exit("Error reading config file %s" %config_file)
    # end except
    rest_api_params = args.func(args)
    force = False
    if 'force' in args:
        force = args.force
    resp = send_REST_request(smgr_ip, smgr_port,
                      rest_api_params['object'],
                      rest_api_params['match_key'],
                      rest_api_params['match_value'],
                      force)
    smgr_client_def.print_rest_response(resp)
Exemple #4
0
def do_issu(args_str=None):
    args = parse_arguments(args_str)

    smgr_port, smgr_ip = setup_smgr(args)
    # contruct paylod for backend
    payload = {}
    payload['opcode'] = 'issu'
    payload['old_cluster'] = args.cluster_id_old
    payload['new_cluster'] = args.cluster_id_new
    #payload['old_version'] = args.old_version
    payload['new_image'] = args.new_image
    if args.compute_all:
        payload['compute_tag'] = "all_computes"
    elif args.tag:
        payload['compute_tag'] = args.tag
    else:
        payload['compute_tag'] = ""

    if (not args.no_confirm):
        msg = "Upgrade cluster %s to %s, Contrail Image:%s? (y/N) :" % (
            args.cluster_id_old, args.cluster_id_new, args.new_image)
        user_input = raw_input(msg).lower()
        if user_input not in ["y", "yes"]:
            sys.exit()
    # end if

    resp = send_REST_request(smgr_ip, smgr_port, payload)
    smgr_client_def.print_rest_response(resp)
def reimage_server(args_str=None):
    args = parse_arguments(args_str)
    if args.config_file:
        config_file = args.config_file
    else:
        config_file = smgr_client_def._DEF_SMGR_CFG_FILE
    # end args.config_file
    try:
        config = ConfigParser.SafeConfigParser()
        config.read([config_file])
        smgr_config = dict(config.items("SERVER-MANAGER"))
        smgr_ip = smgr_config.get("listen_ip_addr", None)
        if not smgr_ip:
            sys.exit(("listen_ip_addr missing in config file"
                      "%s" %config_file))
        smgr_port = smgr_config.get("listen_port", smgr_client_def._DEF_SMGR_PORT)
    except:
        sys.exit("Error reading config file %s" %config_file)
    # end except

    match_key = None
    match_value = None
    payload = {}
    if args.server_id:
        match_key='id'
        match_value = args.server_id
    elif args.cluster_id:
        match_key='cluster_id'
        match_value = args.cluster_id
    elif args.tag:
        match_key='tag'
        match_value = args.tag
    elif args.where:
        match_key='where'
        match_value = args.where
    else:
        pass
    
    payload['base_image_id'] = args.base_image_id
    payload['package_image_id'] = args.package_image_id
    if (args.no_reboot):
        payload['no_reboot'] = "y"
    if match_key:
        payload[match_key] = match_value

    if (not args.no_confirm):
        if args.base_image_id:
            image_str = args.base_image_id
        else:
            image_str = "configured"
        msg = "Reimage servers (%s:%s) with %s? (y/N) :" %(
            match_key, match_value, image_str)
        user_input = raw_input(msg).lower()
        if user_input not in ["y", "yes"]:
            sys.exit()
    # end if
 
    resp = send_REST_request(smgr_ip, smgr_port,
                             payload)
    smgr_client_def.print_rest_response(resp)
def do_issu(args_str=None):
    args = parse_arguments(args_str)

    smgr_port, smgr_ip = setup_smgr(args)
    # contruct paylod for backend
    payload = {}
    payload['opcode'] = 'issu'
    payload['old_cluster'] = args.cluster_id_old
    payload['new_cluster'] = args.cluster_id_new
    #payload['old_version'] = args.old_version
    payload['new_image'] = args.new_image
    if args.compute_all:
        payload['compute_tag'] = "all_computes"
    elif args.tag:
        payload['compute_tag'] = args.tag
    else:
        payload['compute_tag'] = ""

    if (not args.no_confirm):
        msg = "Upgrade cluster %s to %s, Contrail Image:%s? (y/N) :" %(
                            args.cluster_id_old, args.cluster_id_new,
                            args.new_image)
        user_input = raw_input(msg).lower()
        if user_input not in ["y", "yes"]:
            sys.exit()
    # end if
 
    resp = send_REST_request(smgr_ip, smgr_port,
                             payload)
    smgr_client_def.print_rest_response(resp)
def reimage_server(args_str=None):
    args = parse_arguments(args_str)
    if args.config_file:
        config_file = args.config_file
    else:
        config_file = smgr_client_def._DEF_SMGR_CFG_FILE
    # end args.config_file
    try:
        config = ConfigParser.SafeConfigParser()
        config.read([config_file])
        smgr_config = dict(config.items("SERVER-MANAGER"))
        smgr_ip = smgr_config.get("listen_ip_addr", None)
        if not smgr_ip:
            sys.exit(("listen_ip_addr missing in config file"
                      "%s" % config_file))
        smgr_port = smgr_config.get("listen_port",
                                    smgr_client_def._DEF_SMGR_PORT)
    except:
        sys.exit("Error reading config file %s" % config_file)
    # end except

    match_key = None
    match_value = None
    payload = {}
    if args.server_id:
        match_key = 'id'
        match_value = args.server_id
    elif args.cluster_id:
        match_key = 'cluster_id'
        match_value = args.cluster_id
    elif args.tag:
        match_key = 'tag'
        match_value = args.tag
    elif args.where:
        match_key = 'where'
        match_value = args.where
    else:
        pass

    payload['base_image_id'] = args.base_image_id
    payload['package_image_id'] = args.package_image_id
    if (args.no_reboot):
        payload['no_reboot'] = "y"
    if match_key:
        payload[match_key] = match_value

    if (not args.no_confirm):
        if args.base_image_id:
            image_str = args.base_image_id
        else:
            image_str = "configured"
        msg = "Reimage servers (%s:%s) with %s? (y/N) :" % (
            match_key, match_value, image_str)
        user_input = raw_input(msg).lower()
        if user_input not in ["y", "yes"]:
            sys.exit()
    # end if

    resp = send_REST_request(smgr_ip, smgr_port, payload)
    smgr_client_def.print_rest_response(resp)
def show_config(args_str=None):
    mon_query = False
    mon_rest_api_params = None
    parser = parse_arguments()
    args = parser.parse_args(args_str)
    if args.config_file:
        config_file = args.config_file
    else:
        config_file = smgr_client_def._DEF_SMGR_CFG_FILE
    # end args.config_file
    if hasattr(args, 'detail'):
        detail = args.detail
    else:
        detail = None
    try:
        config = ConfigParser.SafeConfigParser()
        config.read([config_file])
        smgr_config = dict(config.items("SERVER-MANAGER"))
        smgr_ip = smgr_config.get("listen_ip_addr", None)
        if not smgr_ip:
            sys.exit(("listen_ip_addr missing in config file"
                      "%s" %config_file))
        smgr_port = smgr_config.get("listen_port", smgr_client_def._DEF_SMGR_PORT)
    except Exception as e:
        sys.exit("Exception: %s : Error reading config file %s" %(e.message, config_file))
    # end except
    rest_api_params = args.func(args)
    try:
        mon_config = dict(config.items("MONITORING"))
        query_engine_port = mon_config.get("ipmi_introspect_port", None)
    except ConfigParser.NoSectionError:
        if rest_api_params['object'] == "Monitor":
            sys.exit("Monitoring hasn't been configured. Cannot use this command.")
        else:
            pass
    except Exception as e:
        if rest_api_params['object'] == "Monitor":
            sys.exit("Monitoring hasn't been configured. Cannot use this command.")
        else:
            pass
    if rest_api_params['object'] == "Monitor" and smgr_ip:
        if rest_api_params['monitoring_value'] != "Status":
            mon_query = True
            mon_rest_api_params = dict(rest_api_params)
            rest_api_params = mon_querying_obj.get_wrapper_call_params(rest_api_params)
        else:
            mon_query = False
    else:
        mon_query = False
    resp = send_REST_request(smgr_ip, smgr_port,
                      rest_api_params['object'],
                      rest_api_params['match_key'],
                      rest_api_params['match_value'],
                      rest_api_params['select'],
                      detail)
    if mon_query:
        resp = mon_querying_obj.handle_smgr_response(resp, smgr_ip, query_engine_port, mon_rest_api_params)
    smgr_client_def.print_rest_response(resp)
Exemple #9
0
def run_inventory(args_str=None):
    args = parse_arguments(args_str)
    if args.config_file:
        config_file = args.config_file
    else:
        config_file = smgr_client_def._DEF_SMGR_CFG_FILE
    # end args.config_file
    try:
        config = ConfigParser.SafeConfigParser()
        config.read([config_file])
        smgr_config = dict(config.items("SERVER-MANAGER"))
        smgr_ip = smgr_config.get("listen_ip_addr", None)
        if not smgr_ip:
            sys.exit(("listen_ip_addr missing in config file"
                      "%s" % config_file))
        smgr_port = smgr_config.get("listen_port",
                                    smgr_client_def._DEF_SMGR_PORT)
    except:
        sys.exit("Error reading config file %s" % config_file)
    # end except

    payload = {}
    match_key = None
    if args.server_id:
        match_key = 'id'
        match_value = args.server_id
    elif args.cluster_id:
        match_key = 'cluster_id'
        match_value = args.cluster_id
    elif args.tag:
        match_key = 'tag'
        match_value = args.tag
    else:
        pass

    if match_key:
        payload[match_key] = match_value

    if (not args.no_confirm):
        msg = "Run Inventory on servers matching: (%s:%s)? (y/N) :" % (
            match_key, match_value)
        user_input = raw_input(msg).lower()
        if user_input not in ["y", "yes"]:
            sys.exit()
    # end if

    resp = send_REST_request(smgr_ip, smgr_port, payload)
    smgr_client_def.print_rest_response(resp)
def run_inventory(args_str=None):
    args = parse_arguments(args_str)
    if args.config_file:
        config_file = args.config_file
    else:
        config_file = smgr_client_def._DEF_SMGR_CFG_FILE
    # end args.config_file
    try:
        config = ConfigParser.SafeConfigParser()
        config.read([config_file])
        smgr_config = dict(config.items("SERVER-MANAGER"))
        smgr_ip = smgr_config.get("listen_ip_addr", None)
        if not smgr_ip:
            sys.exit(("listen_ip_addr missing in config file"
                      "%s" % config_file))
        smgr_port = smgr_config.get("listen_port", smgr_client_def._DEF_SMGR_PORT)
    except:
        sys.exit("Error reading config file %s" % config_file)
    # end except

    payload = {}
    match_key = None
    if args.server_id:
        match_key = 'id'
        match_value = args.server_id
    elif args.cluster_id:
        match_key = 'cluster_id'
        match_value = args.cluster_id
    elif args.tag:
        match_key = 'tag'
        match_value = args.tag
    else:
        pass

    if match_key:
        payload[match_key] = match_value

    if (not args.no_confirm):
        msg = "Run Inventory on servers matching: (%s:%s)? (y/N) :" % (
            match_key, match_value)
        user_input = raw_input(msg).lower()
        if user_input not in ["y", "yes"]:
            sys.exit()
    # end if

    resp = send_REST_request(smgr_ip, smgr_port, payload)
    smgr_client_def.print_rest_response(resp)
Exemple #11
0
def do_issu_finalize(args_str=None):

    args = parse_arguments(args_str, flag=True)
    smgr_port, smgr_ip = setup_smgr(args)
    # contruct paylod for backend
    payload = {}
    payload['opcode'] = 'issu_finalize'
    payload['old_cluster'] = args.cluster_id_old
    payload['new_cluster'] = args.cluster_id_new

    if (not args.no_confirm):
        msg = "Switch from cluster %s to %s? (y/N) :" % (args.cluster_id_old,
                                                         args.cluster_id_new)
        user_input = raw_input(msg).lower()
        if user_input not in ["y", "yes"]:
            sys.exit()
    # end if

    resp = send_REST_request(smgr_ip, smgr_port, payload)
    smgr_client_def.print_rest_response(resp)
def add_config(args_str=None):
    args = parse_arguments(args_str)
    global smgr_ip
    global smgr_port

    if args.config_file:
        config_file = args.config_file
    else:
        config_file = smgr_client_def._DEF_SMGR_CFG_FILE
    # end args.config_file
    try:
        config = ConfigParser.SafeConfigParser()
        config.read([config_file])
        smgr_config = dict(config.items("SERVER-MANAGER"))
        smgr_ip = smgr_config.get("listen_ip_addr", None)
        if not smgr_ip:
            sys.exit(("listen_ip_addr missing in config file"
                      "%s" %config_file))
        smgr_port = smgr_config.get("listen_port", smgr_client_def._DEF_SMGR_PORT)
    except:
        sys.exit("Error reading config file %s" %config_file)
    # end except
    object = args.object
    try:
        if args.file_name:
            payload = json.load(open(args.file_name))
            merge_with_defaults(object, payload, config)
        else:
            # Accept parameters and construct json.
            if object == 'tag':
                payload = add_tag_payload(object)
            else:
                default_object = get_default_object(object, config)
                payload = add_payload(object, default_object)
    except ValueError as e:
        print "Error in JSON Format : %s" % e
        sys.exit(1)
    if payload:
        resp = send_REST_request(smgr_ip, smgr_port,
                                 object, payload)
        smgr_client_def.print_rest_response(resp)
def add_config(args_str=None):
    args = parse_arguments(args_str)
    global smgr_ip
    global smgr_port

    if args.config_file:
        config_file = args.config_file
    else:
        config_file = smgr_client_def._DEF_SMGR_CFG_FILE
    # end args.config_file
    try:
        config = ConfigParser.SafeConfigParser()
        config.read([config_file])
        smgr_config = dict(config.items("SERVER-MANAGER"))
        smgr_ip = smgr_config.get("listen_ip_addr", None)
        if not smgr_ip:
            sys.exit(("listen_ip_addr missing in config file"
                      "%s" % config_file))
        smgr_port = smgr_config.get("listen_port",
                                    smgr_client_def._DEF_SMGR_PORT)
    except:
        sys.exit("Error reading config file %s" % config_file)
    # end except
    object = args.object
    try:
        if args.file_name:
            payload = json.load(open(args.file_name))
            merge_with_defaults(object, payload, config)
        else:
            # Accept parameters and construct json.
            if object == 'tag':
                payload = add_tag_payload(object)
            else:
                default_object = get_default_object(object, config)
                payload = add_payload(object, default_object)
    except ValueError as e:
        print "Error in JSON Format : %s" % e
        sys.exit(1)
    if payload:
        resp = send_REST_request(smgr_ip, smgr_port, object, payload)
        smgr_client_def.print_rest_response(resp)
def do_issu_finalize(args_str = None):

    args = parse_arguments(args_str, flag = True)
    smgr_port, smgr_ip = setup_smgr(args)
    # contruct paylod for backend
    payload = {}
    payload['opcode'] = 'issu_finalize'
    payload['old_cluster'] = args.cluster_id_old
    payload['new_cluster'] = args.cluster_id_new

    if (not args.no_confirm):
        msg = "Switch from cluster %s to %s? (y/N) :" %(
                            args.cluster_id_old, args.cluster_id_new)
        user_input = raw_input(msg).lower()
        if user_input not in ["y", "yes"]:
            sys.exit()
    # end if

    resp = send_REST_request(smgr_ip, smgr_port,
                             payload)
    smgr_client_def.print_rest_response(resp)
def provision_server(args_str=None):
    args = parse_arguments(args_str)
    if args.config_file:
        config_file = args.config_file
    else:
        config_file = smgr_client_def._DEF_SMGR_CFG_FILE
    # end args.config_file
    try:
        config = ConfigParser.SafeConfigParser()
        config.read([config_file])
        smgr_config = dict(config.items("SERVER-MANAGER"))
        smgr_ip = smgr_config.get("listen_ip_addr", None)
        if not smgr_ip:
            sys.exit(("listen_ip_addr missing in config file"
                      "%s" %config_file))
        smgr_port = smgr_config.get("listen_port", smgr_client_def._DEF_SMGR_PORT)
    except:
        sys.exit("Error reading config file %s" %config_file)
    # end except

    provision_params = {}
    payload = {}
    match_key = None
    match_param = None
    if args.server_id:
        match_key='id'
        match_value = args.server_id
    elif args.cluster_id:
        match_key='cluster_id'
        match_value = args.cluster_id
    elif args.tag:
        match_key='tag'
        match_value = args.tag
    elif args.where:
        match_key='where'
        match_value = args.where
    elif args.interactive:
       provision_params = get_provision_params()
    elif args.provision_params_file:
       provision_params = json.load(
           open(args.provision_params_file))
    else:
        pass

    payload['package_image_id'] = args.package_image_id
    if match_key:
        payload[match_key] = match_value
    if provision_params:
        payload['provision_parameters'] = provision_params

    if (not args.no_confirm):
        if args.package_image_id:
            pkg_id_str = args.package_image_id
        else:
            pkg_id_str = "configured package"
        if match_key:
            msg = "Provision servers (%s:%s) with %s? (y/N) :" %(
                match_key, match_value, pkg_id_str)
        else:
            msg = "Provision servers with %s? (y/N) :" %(pkg_id_str)
        user_input = raw_input(msg).lower()
        if user_input not in ["y", "yes"]:
            sys.exit()
    # end if
 
    resp = send_REST_request(smgr_ip, smgr_port,
                             payload)
    smgr_client_def.print_rest_response(resp)
def provision_server(args_str=None):
    args = parse_arguments(args_str)
    if args.config_file:
        config_file = args.config_file
    else:
        config_file = smgr_client_def._DEF_SMGR_CFG_FILE
    # end args.config_file
    try:
        config = ConfigParser.SafeConfigParser()
        config.read([config_file])
        smgr_config = dict(config.items("SERVER-MANAGER"))
        smgr_ip = smgr_config.get("listen_ip_addr", None)
        if not smgr_ip:
            sys.exit(("listen_ip_addr missing in config file"
                      "%s" %config_file))
        smgr_port = smgr_config.get("listen_port", smgr_client_def._DEF_SMGR_PORT)
    except:
        sys.exit("Error reading config file %s" %config_file)
    # end except

    provision_params = {}
    match_key = None
    match_param = None
    if args.server_id:
        match_key='id'
        match_value = args.server_id
    elif args.cluster_id:
        match_key='cluster_id'
        match_value = args.cluster_id
    elif args.tag:
        match_key='tag'
        match_value = args.tag
    elif args.interactive:
       provision_params = get_provision_params()
    elif args.provision_params_file:
       provision_params = json.load(
           open(args.provision_params_file))
    else:
        pass

    payload = {}
    payload['package_image_id'] = args.package_image_id
    if match_key:
        payload[match_key] = match_value
    if provision_params:
        payload['provision_parameters'] = provision_params

    if (not args.no_confirm):
        if match_key:
            msg = "Provision servers (%s:%s) with %s? (y/N) :" %(
                match_key, match_value, args.package_image_id)
        else:
            msg = "Provision servers with %s? (y/N) :" %(
                args.package_image_id)
        user_input = raw_input(msg).lower()
        if user_input not in ["y", "yes"]:
            sys.exit()
    # end if
 
    resp = send_REST_request(smgr_ip, smgr_port,
                             payload)
    smgr_client_def.print_rest_response(resp)