Example #1
0
def validate_instance(params):
    if platform.system() == "Linux":
        if "Ubuntu" in platform.linux_distribution()[0]:
            params.system = Ubuntu(params)
        if "Red Hat Enterprise Linux Server" in platform.linux_distribution()[0]:
            params.system = RHEL(params)
    elif platform.system() == "Windows":
        params.system = Windows(params)
    if "system" not in params:
        raise RuntimeError(System.UNSUPPORTED_SYSTEM_MSG)
    try:
        urlopen("http://169.254.169.254/latest/meta-data/", timeout=1)
        raise RuntimeError("Amazon EC2 instances are not supported.")
    except (URLError, timeout):
        pass
Example #2
0
    def _run_main(self, args, parsed_globals):
        client = self._session.create_client(
            'gamelift', region_name=parsed_globals.region,
            endpoint_url=parsed_globals.endpoint_url,
            verify=parsed_globals.verify_ssl
        )

        # Retrieve a signed url.
        response = client.get_game_session_log_url(
            GameSessionId=args.game_session_id)
        url = response['PreSignedUrl']

        # Retrieve the content from the presigned url and save it locally.
        contents = urlopen(url)

        sys.stdout.write(
            'Downloading log archive for game session %s...\r' %
            args.game_session_id
        )

        with open(args.save_as, 'wb') as f:
            for chunk in iter(partial(contents.read, 1024), b''):
                f.write(chunk)

        sys.stdout.write(
            'Successfully downloaded log archive for game '
            'session %s to %s\n' % (args.game_session_id, args.save_as))

        return 0
Example #3
0
    def _run_main(self, args, parsed_globals):
        client = self._session.create_client(
            'gamelift',
            region_name=parsed_globals.region,
            endpoint_url=parsed_globals.endpoint_url,
            verify=parsed_globals.verify_ssl)

        # Retrieve a signed url.
        response = client.get_game_session_log_url(
            GameSessionId=args.game_session_id)
        url = response['PreSignedUrl']

        # Retrieve the content from the presigned url and save it locally.
        contents = urlopen(url)

        sys.stdout.write('Downloading log archive for game session %s...\r' %
                         args.game_session_id)

        with open(args.save_as, 'wb') as f:
            for chunk in iter(partial(contents.read, 1024), b''):
                f.write(chunk)

        sys.stdout.write('Successfully downloaded log archive for game '
                         'session %s to %s\n' %
                         (args.game_session_id, args.save_as))

        return 0
Example #4
0
def validate_instance(params):
    if platform.system() == 'Linux':
        if 'Ubuntu' in platform.linux_distribution()[0]:
            params.system = Ubuntu(params)
    elif platform.system() == 'Windows':
        params.system = Windows(params)
    if 'system' not in params:
        raise RuntimeError(
            'Only Ubuntu Server and Windows Server operating systems are '
            'supported.'
        )
    try:
        urlopen('http://169.254.169.254/latest/meta-data/', timeout=1)
        raise RuntimeError('Amazon EC2 instances are not supported.')
    except (URLError, timeout):
        pass
Example #5
0
def validate_instance(params):
    if platform.system() == 'Linux':
        if 'Ubuntu' in platform.linux_distribution()[0]:
            params.system = Ubuntu(params)
        if 'Red Hat Enterprise Linux Server' in platform.linux_distribution()[0]:
            params.system = RHEL(params)
    elif platform.system() == 'Windows':
        params.system = Windows(params)
    if 'system' not in params:
        raise RuntimeError(
            System.UNSUPPORTED_SYSTEM_MSG
        )
    try:
        urlopen('http://169.254.169.254/latest/meta-data/', timeout=1)
        raise RuntimeError('Amazon EC2 instances are not supported.')
    except (URLError, timeout):
        pass
Example #6
0
    def validate_arguments(self, args):
        """
        Validates command line arguments using the retrieved information.
        """

        if args.hostname:
            instances = self.opsworks.describe_instances(
                StackId=self._stack['StackId']
            )['Instances']
            if any(args.hostname.lower() == instance['Hostname']
                   for instance in instances):
                raise ValueError(
                    "Invalid hostname: '%s'. Hostnames must be unique within "
                    "a stack." % args.hostname)

        if args.infrastructure_class == 'ec2' and args.local:
            # make sure the regions match
            region = json.loads(urlopen(IDENTITY_URL).read())['region']
            if region != self._stack['Region']:
                raise ValueError(
                    "The stack's and the instance's region must match.")