Пример #1
0
    def ask_snapshot_name(cls, parameter_pool):
        original_value = parameter_pool.get_value(PName.RdsSourceSnapshotName)
        append_message = TerminalMessage.CurrentValue.format(RdsTerminalMessage.NoSnapshot)\
             if original_value is None else TerminalMessage.CurrentValue.format(original_value)
        print(
            (RdsTerminalMessage.RdsSnapshotNameSelect.format(append_message)))

        snapshots = api_wrapper.retrive_rds_snapshots(parameter_pool)
        sorted_snapshots = cls._sort_snapshots_by_create_time(snapshots)

        snapshot_list = [
            RdsTerminalMessage.NoSnapshot,
        ]
        for i in range(
                0,
                min(len(sorted_snapshots),
                    TerminalConstant.RdsSnapshotListNumber)):
            snapshot_list.append(sorted_snapshots[i].db_snapshot_identifier)
        snapshot_list.append(RdsTerminalMessage.OtherSnapshot)

        snapshot_index = cls.single_choice(choice_list=snapshot_list,
                                           can_return_none=True)
        if snapshot_index == 0:
            # Create RDS instance from scratch
            value = None
        elif snapshot_index == len(snapshot_list) - 1:
            # Name not in list
            value = cls.ask_value(parameter_pool, PName.RdsSourceSnapshotName)
        else:
            value = snapshot_list[
                snapshot_index] if snapshot_index is not None else original_value

        snapshot = Parameter(PName.RdsSourceSnapshotName, value,
                             PSource.Terminal)
        parameter_pool.put(snapshot, True)
Пример #2
0
 def ask_snapshot_name(cls, parameter_pool):
     original_value = parameter_pool.get_value(PName.RdsSourceSnapshotName) \
         if parameter_pool.has(PName.RdsSourceSnapshotName) else None
     append_message = TerminalMessage.CurrentValue.format(RdsTerminalMessage.NoSnapshot)\
          if original_value is None else TerminalMessage.CurrentValue.format(original_value)        
     print((RdsTerminalMessage.RdsSnapshotNameSelect.format(append_message)))
     
     snapshots = api_wrapper.retrive_rds_snapshots(parameter_pool)
     sorted_snapshots = cls._sort_snapshots_by_create_time(snapshots)
     
     snapshot_list = [RdsTerminalMessage.NoSnapshot,];
     for i in range(0, min(len(sorted_snapshots), TerminalConstant.RdsSnapshotListNumber)):
         snapshot_list.append(sorted_snapshots[i].db_snapshot_identifier)
     snapshot_list.append(RdsTerminalMessage.OtherSnapshot)
     
     snapshot_index = cls.single_choice(snapshot_list, None, None, True)
     if snapshot_index == 0:
         # Create RDS instance from scratch
         value = None
     elif snapshot_index == len(snapshot_list) - 1:
         # Name not in list
         value = cls.ask_value(parameter_pool, PName.RdsSourceSnapshotName)
     else:
         value = snapshot_list[snapshot_index] if snapshot_index is not None else original_value
         
     snapshot = Parameter(PName.RdsSourceSnapshotName, value, PSource.Terminal)
     parameter_pool.put(snapshot, True)