Exemple #1
0
    def _create_default_profile(cls, iam_client, parameter_pool):
        try:
            region = parameter_pool.get_value(PName.Region, False)
            log.info(u'Creating IAM role {0}'.format(EbDefault.DefaultRoleName))
            assume_policy_url = EbDefault.RoleAssumePolicyUrlMask.format(PolicyBucket[region])
            assume_policy = misc.to_unicode(requests.get(assume_policy_url).content)
            iam_client.create_role(EbDefault.DefaultRoleName, assume_policy)
        except IamEntityAlreadyExistsException:
            log.info(u'Role {0} already exists.'.format(EbDefault.DefaultRoleName))
            pass

        try:
            log.info(u'Creating IAM instance profile {0}'.format(EbDefault.DefaultInstanceProfileName))            
            iam_client.create_instance_profile(EbDefault.DefaultInstanceProfileName)
        except IamEntityAlreadyExistsException:
            log.info(u'Profile {0} already exists.'.format(EbDefault.DefaultInstanceProfileName))
            pass

        try:
            log.info(u'Adding IAM role {0} to instance profile {1}'.format
                     (EbDefault.DefaultRoleName, EbDefault.DefaultInstanceProfileName))            
            iam_client.add_role_to_instance_profile(EbDefault.DefaultRoleName, 
                                                    EbDefault.DefaultInstanceProfileName)
        except IamLimitExceededException:
            log.info(u'Profile {0} already has one role.'.format(EbDefault.DefaultInstanceProfileName))
            pass
        
        return EbDefault.DefaultInstanceProfileName
Exemple #2
0
    def _create_default_profile(cls, iam_client, parameter_pool):
        try:
            region = parameter_pool.get_value(PName.Region, False)
            log.info(u'Creating IAM role {0}'.format(EbDefault.DefaultRoleName))
            assume_policy_url = EbDefault.RoleAssumePolicyUrlMask.format(PolicyBucket[region])
            assume_policy = misc.to_unicode(requests.get(assume_policy_url).content)
            iam_client.create_role(EbDefault.DefaultRoleName, assume_policy)
        except IamEntityAlreadyExistsException:
            log.info(u'Role {0} already exists.'.format(EbDefault.DefaultRoleName))
            pass

        try:
            log.info(u'Creating IAM instance profile {0}'.format(EbDefault.DefaultInstanceProfileName))            
            iam_client.create_instance_profile(EbDefault.DefaultInstanceProfileName)
        except IamEntityAlreadyExistsException:
            log.info(u'Profile {0} already exists.'.format(EbDefault.DefaultInstanceProfileName))
            pass

        try:
            log.info(u'Adding IAM role {0} to instance profile {1}'.format
                     (EbDefault.DefaultRoleName, EbDefault.DefaultInstanceProfileName))            
            iam_client.add_role_to_instance_profile(EbDefault.DefaultRoleName, 
                                                    EbDefault.DefaultInstanceProfileName)
        except IamLimitExceededException:
            log.info(u'Profile {0} already has one role.'.format(EbDefault.DefaultInstanceProfileName))
            pass
        
        return EbDefault.DefaultInstanceProfileName
    def execute(self, parameter_pool):
        eb_client = self._get_eb_client(parameter_pool)
        env_name = parameter_pool.get_value(ParameterName.EnvironmentName,
                                            False)
        wait_timeout = parameter_pool.get_value(
            ParameterName.WaitForUpdateTimeout, False)
        poll_delay = parameter_pool.get_value(ParameterName.PollDelay, False)
        info_request_id = parameter_pool.get_value(
            ParameterName.RequestEnvInfoRequestID)

        self._wait_for_env_operation_finish(
            eb_client=eb_client,
            env_name=env_name,
            original_request_id=info_request_id,
            pending_status=EnvironmentStatus.Updating,
            expected_health=None,
            operation_name=self.__class__.__name__,
            action_name=EnvRetrieveInfoOpMessage.Action,
            wait_timeout=wait_timeout,
            poll_delay=poll_delay,
            include_deleted=u'false',
            initial_delay=ServiceDefault.UPDATE_ENV_POLL_DELAY,
            quiet=False)

        # After polling
        _, subcommands = parameter_pool.command
        info_type = subcommands[0].lower(
        ) if len(subcommands) > 0 else EbDefault.TailLog
        response = eb_client.retrieve_environment_info(env_name,
                                                       info_type=info_type)

        # Sort and find latest log for each instance
        instance_timestamps = dict()
        instance_logs = dict()
        for env_info in response.result:
            instance_id = env_info.ec2_instance_id
            timestamp = env_info.sample_timestamp
            url = env_info.message

            if not instance_timestamps.has_key(instance_id)\
                or instance_timestamps[instance_id] < timestamp:
                instance_timestamps[instance_id] = timestamp
                instance_logs[instance_id] = url

        for instance_id in sorted(instance_logs.keys()):
            content = misc.to_unicode(
                requests.get(instance_logs[instance_id]).content)
            prompt.result(os.linesep + misc.to_terminal_codepage(
                EnvRetrieveInfoOpMessage.FileOuputPrefix.format(instance_id)))
            prompt.result(misc.to_terminal_codepage(content))

        ret_result = OperationResult(self, None, None, None)

        return ret_result
    def execute(self, parameter_pool):
        eb_client = self._get_eb_client(parameter_pool)
        env_name = parameter_pool.get_value(ParameterName.EnvironmentName, False)
        wait_timeout = parameter_pool.get_value(ParameterName.WaitForUpdateTimeout, False)
        poll_delay = parameter_pool.get_value(ParameterName.PollDelay, False)
        info_request_id = parameter_pool.get_value(ParameterName.RequestEnvInfoRequestID)

        self._wait_for_env_operation_finish(
                         eb_client = eb_client, 
                         env_name = env_name, 
                         original_request_id = info_request_id,
                         pending_status = EnvironmentStatus.Updating,
                         expected_health = None,
                         operation_name = self.__class__.__name__, 
                         action_name = EnvRetrieveInfoOpMessage.Action,
                         wait_timeout = wait_timeout, 
                         poll_delay = poll_delay, 
                         include_deleted = 'false',
                         initial_delay = ServiceDefault.UPDATE_ENV_POLL_DELAY,
                         quiet = False)                                                     
                                                     
        # After polling
        _, subcommands = parameter_pool.command
        info_type = subcommands[0].lower() if len(subcommands) > 0 else EbDefault.TailLog
        response = eb_client.retrieve_environment_info(env_name, info_type=info_type)
        
        # Sort and find latest log for each instance
        instance_timestamps = dict()
        instance_logs = dict()
        for env_info in response.result:
            instance_id = env_info.ec2_instance_id
            timestamp = env_info.sample_timestamp
            url = env_info.message
            
            if instance_id not in instance_timestamps\
                or instance_timestamps[instance_id] < timestamp:
                instance_timestamps[instance_id] = timestamp
                instance_logs[instance_id] = url

        for instance_id in sorted(instance_logs.keys()):
            content = misc.to_unicode(requests.get(instance_logs[instance_id]).content)
            prompt.result(os.linesep + 
                          misc.to_terminal_codepage(EnvRetrieveInfoOpMessage.FileOuputPrefix.format(instance_id)))
            prompt.result(misc.to_terminal_codepage(content))
                                
        ret_result = OperationResult(self,
                                     None,
                                     None,
                                     None)

        return ret_result