':type args: EnvironmentConfig
:type platform: str
:type version: str
:type stage: str
:type persist: bool
:type name: str'

def __init__(self, args, platform, version, stage='prod', persist=True, name=None):

    self.args = args
    self.platform = platform
    self.version = version
    self.stage = stage
    self.client = HttpClient(args)
    self.connection = None
    self.instance_id = None
    self.name = (name if name else ('%s-%s' % (self.platform, self.version)))
    self.ci_key = os.path.expanduser('~/.ansible-core-ci.key')
    aws_platforms = ('aws', 'windows', 'freebsd', 'rhel', 'vyos', 'junos', 'ios')
    osx_platforms = ('osx',)
    if (self.platform in aws_platforms):
        if args.remote_aws_region:
            region = args.remote_aws_region
            self.ci_key += ('.%s' % args.remote_aws_region)
        elif is_shippable():
            if (self.platform == 'windows'):
                region = 'us-east-2'
            else:
                region = 'us-east-1'
        else:
            region = 'us-east-1'
        self.endpoint = AWS_ENDPOINTS[region]
        if (self.platform == 'windows'):
            self.ssh_key = None
            self.port = 5986
        else:
            self.ssh_key = SshKey(args)
            self.port = 22
    elif (self.platform in osx_platforms):
        self.endpoint = 'https://osx.testing.ansible.com'
        self.ssh_key = SshKey(args)
        self.port = None
    else:
        raise ApplicationError(('Unsupported    platform:    %s' % platform))
    self.path = os.path.expanduser(('~/.ansible/test/instances/%s-%s' % (self.name, self.stage)))
    if (persist and self._load()):
        try:
            display.info(('Checking    existing    %s/%s    instance    %s.' % (self.platform, self.version, self.instance_id)), verbosity=1)
            self.connection = self.get(always_raise_on=[404])
            display.info(('Loaded    existing    %s/%s    from:    %s' % (self.platform, self.version, self._uri)), verbosity=1)
        except HttpError as ex:
            if (ex.status != 404):
                raise
            self._clear()
            display.info(('Cleared    stale    %s/%s    instance    %s.' % (self.platform, self.version, self.instance_id)), verbosity=1)
            self.instance_id = None
    else:
        self.instance_id = None
        self._clear()
    if self.instance_id:
        self.started = True
    else:
        self.started = False
        self.instance_id = str(uuid.uuid4())
