def ec2_command(argv=None, aws_config=None): ec2_res = docopt(__doc__, argv=argv) if any((ec2_res.get('ls'), ec2_res.get('list'))): ec2.ec2_list(aws_config, filter_term=ec2_res.get('--filter')) elif ec2_res.get('info'): ec2.ec2_info(aws_config, instance_id=ec2_res.get('<instance_id>')) elif ec2_res.get('stop'): ec2.ec2_manage(aws_config, instance_id=ec2_res.get('<instance_id>'), action="stop") elif ec2_res.get('reboot'): ec2.ec2_manage(aws_config, instance_id=ec2_res.get('<instance_id>'), action="reboot") elif ec2_res.get('start'): ec2.ec2_manage(aws_config, instance_id=ec2_res.get('<instance_id>'), action="start") elif ec2_res.get('terminate'): ec2.ec2_manage(aws_config, instance_id=ec2_res.get('<instance_id>'), action="terminate") elif ec2_res.get('cpu'): cloudwatch.ec2_cpu(aws_config=aws_config, instance_id=ec2_res.get('<instance_id>')) elif ec2_res.get('net'): cloudwatch.ec2_net(aws_config=aws_config, instance_id=ec2_res.get('<instance_id>'), start=ec2_res.get('--start'), period=ec2_res.get('--end'), intervals=ec2_res.get('intervals') ) elif ec2_res.get('vols'): cloudwatch.ec2_vol(aws_config=aws_config, instance_id=ec2_res.get('<instance_id>'), start=ec2_res.get('--start'), period=ec2_res.get('--end'), intervals=ec2_res.get('intervals') ) elif ec2_res.get('summary'): ec2.ec2_summary(aws_config=aws_config)
def ec2_command(argv=None, aws_config=None): ec2_res = docopt(__doc__, argv=argv) if any((ec2_res.get('ls'), ec2_res.get('list'))): ec2.ec2_list(aws_config, filter_term=ec2_res.get('--filter')) elif ec2_res.get('info'): ec2.ec2_info(aws_config, instance_id=ec2_res.get('<instance_id>')) elif ec2_res.get('stop'): ec2.ec2_manage(aws_config, instance_id=ec2_res.get('<instance_id>'), action="stop") elif ec2_res.get('reboot'): ec2.ec2_manage(aws_config, instance_id=ec2_res.get('<instance_id>'), action="reboot") elif ec2_res.get('start'): ec2.ec2_manage(aws_config, instance_id=ec2_res.get('<instance_id>'), action="start") elif ec2_res.get('terminate'): ec2.ec2_manage(aws_config, instance_id=ec2_res.get('<instance_id>'), action="terminate") elif ec2_res.get('cpu'): cloudwatch.ec2_cpu(aws_config=aws_config, instance_id=ec2_res.get('<instance_id>')) elif ec2_res.get('net'): cloudwatch.ec2_net(aws_config=aws_config, instance_id=ec2_res.get('<instance_id>'), start=ec2_res.get('--start'), period=ec2_res.get('--end'), intervals=ec2_res.get('intervals')) elif ec2_res.get('vols'): cloudwatch.ec2_vol(aws_config=aws_config, instance_id=ec2_res.get('<instance_id>'), start=ec2_res.get('--start'), period=ec2_res.get('--end'), intervals=ec2_res.get('intervals')) elif ec2_res.get('summary'): ec2.ec2_summary(aws_config=aws_config)
def test_ec2_list_service_no_instances(): with pytest.raises(SystemExit): assert ec2_list(aws_config=config)