Beispiel #1
0
def run_apigateway(params):
	command = ["cloudformation", "describe-stack-resource", "--stack-name", params.stack, "--logical-resource-id", "RestApi"]
	restApi = common.run_shell_command(params.region, command)

	command = ["cloudformation", "describe-stack-resource", "--stack-name", params.stack, "--logical-resource-id", "ApiResource"]
	restResource = common.run_shell_command(params.region, command)

	uri = '/v1/environments'
	queryParams = {}
	if params.environment != None:
		uri = '/v1/environments/%s' % params.environment
	else:
		if params.cluster != None:
			queryParams['cluster'] = params.cluster
		uri += common.get_query_string(queryParams)

	command = ["apigateway", "test-invoke-method", "--rest-api-id", restApi['StackResourceDetail']['PhysicalResourceId'], "--resource-id", restResource['StackResourceDetail']['PhysicalResourceId'], "--http-method", "GET", "--headers", "{}", "--path-with-query-string", uri]
	response = common.run_shell_command(params.region, command)

	print "HTTP Response Code: %d" % response['status']

	try:
		obj = json.loads(response['body'])
		print json.dumps(obj, indent=2)
	except Exception as e:
		print "Error: Could not parse response - %s" % e
		print json.dumps(response, indent=2)
		sys.exit(1)
Beispiel #2
0
def run_apigateway(params):
    command = [
        "cloudformation", "describe-stack-resource", "--stack-name",
        params.stack, "--logical-resource-id", "RestApi"
    ]
    restApi = common.run_shell_command(params.region, command)

    command = [
        "cloudformation", "describe-stack-resource", "--stack-name",
        params.stack, "--logical-resource-id", "ApiResource"
    ]
    restResource = common.run_shell_command(params.region, command)

    command = [
        "apigateway", "test-invoke-method", "--rest-api-id",
        restApi['StackResourceDetail']['PhysicalResourceId'], "--resource-id",
        restResource['StackResourceDetail']['PhysicalResourceId'],
        "--http-method", "POST", "--headers", "{}", "--path-with-query-string",
        "/v1/environments/%s/deployments?deploymentToken=%s" %
        (params.environment, params.token), "--body", ""
    ]
    response = common.run_shell_command(params.region, command)

    print "HTTP Response Code: %d" % response['status']

    try:
        obj = json.loads(response['body'])
        print json.dumps(obj, indent=2)
    except Exception as e:
        print "Error: Could not parse response - %s" % e
        print json.dumps(response, indent=2)
        sys.exit(1)
def main():
	args = [
		{'arg':'--cluster', 'dest':'cluster', 'default':None, 'help':'ECS cluster name'},
		{'arg':'--num', 'dest':'num', 'default':None, 'help':'number of instances to increment by'}
	]
	params = common.parse_cli_args('Increment Cluster Instances', args)
	params.num = int(params.num)

	command = ["ecs", "describe-clusters", "--clusters", params.cluster]
	clusterResult = common.run_shell_command(params.region, command)
	if len(clusterResult['clusters']) == 0:
		print "Error: Cluster '%s' does not exist." % params.cluster
		sys.exit(1)

	command = ["ecs", "list-container-instances", "--cluster", params.cluster]
	containersResult = common.run_shell_command(params.region, command)
	if len(containersResult['containerInstanceArns']) == 0:
		print "Error: Cluster '%s' does not contain any instances." % params.cluster
		sys.exit(1)

	command = ["ecs", "describe-container-instances", "--cluster", params.cluster, "--container-instances", containersResult['containerInstanceArns'][0]]
	containerResult = common.run_shell_command(params.region, command)
	if len(containerResult['containerInstances']) == 0:
		print "Error: Could not retrieve container instance '%s'." % containersResult['containerInstanceArns'][0]
		sys.exit(1)

	command = ["ec2", "describe-instances", "--instance-ids", containerResult['containerInstances'][0]['ec2InstanceId']]
	instanceResult = common.run_shell_command(params.region, command)
	if len(instanceResult['Reservations']) == 0:
		print "Error: Could not retrieve ec2 instance '%s'." % containerResult['containerInstances'][0]['ec2InstanceId']
		sys.exit(1)

	amiId = instanceResult['Reservations'][0]['Instances'][0]['ImageId']
	keyName = instanceResult['Reservations'][0]['Instances'][0]['KeyName']
	securityGroup = instanceResult['Reservations'][0]['Instances'][0]['SecurityGroups'][0]['GroupId']
	subnetId = instanceResult['Reservations'][0]['Instances'][0]['SubnetId']
	instanceType = instanceResult['Reservations'][0]['Instances'][0]['InstanceType']
	instanceProfileArn = instanceResult['Reservations'][0]['Instances'][0]['IamInstanceProfile']['Arn']
	instanceProfile = None

	instanceProfileRegex = re.match('(.+)\/(.+)', instanceProfileArn)
	if instanceProfileRegex != None:
		instanceProfile = instanceProfileRegex.group(2)

	userDataRaw = "#!/bin/bash\necho ECS_CLUSTER=%s >> /etc/ecs/ecs.config\n" % params.cluster
	userData = base64.b64encode(userDataRaw)

	for i in range(params.num):
		command = ["ec2", "run-instances", "--image-id", amiId, "--instance-type", instanceType, "--user-data", userData, "--iam-instance-profile", "Name=\"%s\"" % instanceProfile, "--security-group-ids", securityGroup, "--key-name", keyName]
		result = common.run_shell_command(params.region, command)
		print "Created instance '%s'." % result['Instances'][0]['InstanceId']
def main():
	params = common.parse_cli_args('List Task Definitions', [])

	command = ["ecs", "list-task-definitions"]
	result = common.run_shell_command(params.region, command)

	print json.dumps(result, indent=2)
Beispiel #5
0
def get_video_info(full_path):
    command = f'ffprobe -i {full_path} -v quiet -print_format json -show_format -show_streams -hide_banner'
    result = run_shell_command(command)
    video_streams = [
        s for s in result['streams'] if s['codec_type'] == 'video'
    ]
    video_stream = video_streams[0]
    video_duration = float(video_stream['duration'])
    video_frames = int(video_stream['nb_frames'])
    video_fps = video_frames / video_duration
    return video_duration, video_fps
Beispiel #6
0
def run_apigateway(params):
    command = [
        "cloudformation", "describe-stack-resource", "--stack-name",
        params.stack, "--logical-resource-id", "RestApi"
    ]
    restApi = common.run_shell_command(params.region, command)

    command = [
        "cloudformation", "describe-stack-resource", "--stack-name",
        params.stack, "--logical-resource-id", "ApiResource"
    ]
    restResource = common.run_shell_command(params.region, command)

    uri = '/v1/environments'
    queryParams = {}
    if params.environment != None:
        uri = '/v1/environments/%s' % params.environment
    else:
        if params.cluster != None:
            queryParams['cluster'] = params.cluster
        uri += common.get_query_string(queryParams)

    command = [
        "apigateway", "test-invoke-method", "--rest-api-id",
        restApi['StackResourceDetail']['PhysicalResourceId'], "--resource-id",
        restResource['StackResourceDetail']['PhysicalResourceId'],
        "--http-method", "GET", "--headers", "{}", "--path-with-query-string",
        uri
    ]

    response = common.run_shell_command(params.region, command)

    print "HTTP Response Code: %d" % response['status']

    try:
        obj = json.loads(response['body'])
        print json.dumps(obj, indent=2)
    except Exception as e:
        print "Error: Could not parse response - %s" % e
        print json.dumps(response, indent=2)
        sys.exit(1)
def main():
	args = [
		{'arg':'--file', 'dest':'file', 'default':None, 'help':'path to task definition file'}
	]
	params = common.parse_cli_args('Register Task Definition', args)

	if not os.path.isfile(params.file):
		print "Error: File path '%s' does not exist." % params.file
		sys.exit(1)

	command = ["ecs", "register-task-definition", "--cli-input-json", "file://%s" % params.file]
	result = common.run_shell_command(params.region, command)

	print json.dumps(result, indent=2)
def main():
    args = [{
        'arg': '--file',
        'dest': 'file',
        'default': None,
        'help': 'path to task definition file'
    }]
    params = common.parse_cli_args('Register Task Definition', args)

    if not os.path.isfile(params.file):
        print "Error: File path '%s' does not exist." % params.file
        sys.exit(1)

    command = [
        "ecs", "register-task-definition", "--cli-input-json",
        "file://%s" % params.file
    ]
    result = common.run_shell_command(params.region, command)

    print json.dumps(result, indent=2)
Beispiel #9
0
        shutil.rmtree(args.to_video, ignore_errors=True)
        Path(args.to_video).mkdir(parents=True, exist_ok=True)
    for full_path, sub_path, file_name, file_ext in tqdm(list_files(
            args.input)):
        if file_ext in set(['.avi', '.mp4']):
            print(f'To images: {full_path}')

            video_duration, video_fps = get_video_info(full_path)

            step = math.ceil(video_fps / sample_fps)
            if args.tool == "ffmpeg":
                for s in tqdm(range(int(video_duration))):
                    for t in range(sample_fps):
                        st = s + t / sample_fps
                        command = f'ffmpeg -ss {st} -i {full_path} -qmin 1 -q:v 1 -vframes 1 {args.output}/{file_name}_{st:08.2f}.jpg'
                        result = run_shell_command(command)
            elif args.tool == "vlc":
                command = f"vlc {full_path} --intf=dummy --rate=5 --video-filter=scene --vout=dummy --scene-format=jpg \
                    --scene-ratio={step} --scene-path={args.output}  --scene-prefix={file_name}_ vlc://quit"

                result = run_shell_command(command)

    print(f'Output file count:{len(list_files(args.output))}')
    if args.to_video:
        for full_path, sub_path, file_name, file_ext in tqdm(
                list_files(args.input)):
            if file_ext in set(['.avi', '.mp4']):
                to_video_name = f'{args.to_video}/{file_name}_{sample_fps}fps.mp4'
                print(f'To video: {to_video_name}')
                command = f'ffmpeg -framerate {sample_fps} -pattern_type glob -i "{args.output}/{file_name}_*.jpg" {to_video_name}'
                result = run_shell_command(command)