コード例 #1
0
ファイル: update_client.py プロジェクト: maggiegrace/apollo
def update():
    # setup server url
    ip = config.get('Host', 'ip')
    port = config.get('Host', 'port')
    url = 'http://' + ip + ':' + port + '/update'

    # setup car info
    vehicle_info = VehicleInfo()
    VEHICLE_INFO_FILE = os.path.join(os.path.dirname(__file__),
                                     'vehicle_info.pb.txt')
    try:
        proto_utils.get_pb_from_text_file(VEHICLE_INFO_FILE, vehicle_info)
    except IOError:
        print "vehicle_info.pb.txt cannot be open file."
        exit()

    brand = VehicleInfo.Brand.Name(vehicle_info.brand)
    model = VehicleInfo.Model.Name(vehicle_info.model)
    vin = vehicle_info.license.vin
    car_info = {
        "car_type": brand + "." + model,
        "tag": sys.argv[1],
        "vin": vin,
    }

    r = requests.post(url, json=car_info)
    if r.status_code == 200:
        print "Update successfully."
    elif r.status_code == 400:
        print "Invalid Request."
    else:
        print "Cannot connect to server."
コード例 #2
0
ファイル: query_client.py プロジェクト: zmyer/apollo-1
def query():
    vehicle_info = VehicleInfo()
    VEHICLE_INFO_FILE = os.path.join(os.path.dirname(__file__),
                                     'vehicle_info.pb.txt')
    try:
        proto_utils.get_pb_from_text_file(VEHICLE_INFO_FILE, vehicle_info)
    except IOError:
        print "vehicle_info.pb.txt cannot be open file."
        sys.exit(1)

    # setup server url
    config = ConfigParser()
    CONFIG_FILE = os.path.join(os.path.dirname(__file__), 'config.ini')
    config.read(CONFIG_FILE)
    ip = config.get('Host', 'ip')
    port = config.get('Host', 'port')
    url = 'http://' + ip + ':' + port + '/query'

    # generat device token
    returnCode = sec_api.sec_upgrade_get_device_token()
    if returnCode[0] == False:
        print 'get device token failed!'
        sys.exit(1)
    dev_token = returnCode[1]

    # setup car info
    brand = VehicleInfo.Brand.Name(vehicle_info.brand)
    model = VehicleInfo.Model.Name(vehicle_info.model)
    vin = vehicle_info.license.vin
    car_info = {
        "car_type": brand + "." + model,
        "tag": os.environ['DOCKER_IMG'],
        "vin": vin,
        "token": dev_token
    }

    r = requests.post(url, json=car_info)
    if r.status_code == 200:
        auth_token = r.json().get("auth_token")
        if auth_token == "":
            print "Cannot get authorize token!"
            sys.exit(1)
        else:
            token_file_name = os.environ[
                'HOME'] + '/.cache/apollo_update/auth_token'
            apollo_update = os.path.dirname(token_file_name)
            if not os.path.exists(apollo_update):
                os.makedirs(apollo_update)
            with open(token_file_name, 'w') as token_file:
                token_file.write(auth_token)
        tag = r.json().get("tag")
        print tag
        sys.exit(0)
    elif r.status_code == 204:
        print "Release is up to date."
    elif r.status_code == 400:
        print "Invalid car type."
    else:
        print "Cannot connect to server."
    sys.exit(1)
コード例 #3
0
def update():
    UPDATE_FILE = os.path.join(os.path.dirname(__file__), 'update.ini')
    if not os.path.exists(UPDATE_FILE):
        print "No update found!"
        exit()
        
    config = ConfigParser()
    config.read(UPDATE_FILE)
    update_tag = config.get('Update', 'tag')
    usr_name = os.environ['DOCKER_USER']
    cmd = 'ssh ' + usr_name + '@localhost' + ' docker pull ' + update_tag
    code = os.system(cmd)
    if code != 0:
        print "Update fail!"
        exit()

    # setup server url
    ip = config.get('Host', 'ip')
    port = config.get('Host', 'port')
    url = 'http://' + ip + ':' + port + '/update'
    
    # setup car info
    vehicle_info = VehicleInfo()
    VEHICLE_INFO_FILE = os.path.join(os.path.dirname(__file__), 'vehicle_info.pb.txt')
    try:
        proto_utils.get_pb_from_text_file(VEHICLE_INFO_FILE, vehicle_info)
    except IOError:
        print "vehicle_info.pb.txt cannot be open file."
        exit()

    brand = VehicleInfo.Brand.Name(vehicle_info.brand)
    model = VehicleInfo.Model.Name(vehicle_info.model)
    vin = vehicle_info.license.vin
    car_info = {
        "car_type" : brand + "." + model,
        "tag" : update_tag,
        "vin" : vin,
    }

    r = requests.post(url, data=car_info)
    if r.status_code == 200:
        cmd = 'rm ' + UPDATE_FILE
        os.system(cmd)
        print "Update successfully."
    elif r.status_code == 400:
        print "Invalid Request."
    else:
        print "Cannot connect to server."
コード例 #4
0
def query():
    vehicle_info = VehicleInfo()
    VEHICLE_INFO_FILE = os.path.join(os.path.dirname(__file__),
                                     'vehicle_info.pb.txt')
    try:
        proto_utils.get_pb_from_text_file(VEHICLE_INFO_FILE, vehicle_info)
    except IOError:
        print "vehicle_info.pb.txt cannot be open file."
        exit()

    # setup server url
    config = ConfigParser()
    CONFIG_FILE = os.path.join(os.path.dirname(__file__), 'config.ini')
    config.read(CONFIG_FILE)
    ip = config.get('Host', 'ip')
    port = config.get('Host', 'port')
    url = 'http://' + ip + ':' + port + '/query'

    # setup car info
    brand = VehicleInfo.Brand.Name(vehicle_info.brand)
    model = VehicleInfo.Model.Name(vehicle_info.model)
    vin = vehicle_info.license.vin
    car_info = {
        "car_type": brand + "." + model,
        "tag": os.environ['DOCKER_IMG'],
        "vin": vin,
    }

    r = requests.post(url, data=car_info)
    if r.status_code == 200:
        tag = r.json().get("tag")
        config.add_section('Update')
        config.set('Update', 'tag', tag)
        UPDATE_FILE = os.path.join(os.path.dirname(__file__), 'update.ini')
        with open(UPDATE_FILE, 'wb') as update_file:
            config.write(update_file)
    elif r.status_code == 204:
        print "Release is up to date."
    elif r.status_code == 400:
        print "Invalid car type."
    else:
        print "Cannot connect to server."