Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with
#1
Need help. trying to set below parameters with code listed below but throwing error. can you help me what is the correct syntax for condition listed below for EBS volume size. thank you

Output:
Disk Size in GB IOPS Throughput(MBps) < 250 3000 125 >250 to <1TB 3000 250
============================

CODE
------
for volume in volumes:

  VolumeId = volume['VolumeId']

  VolumeType = volume['VolumeType']

  Size = volume['Size']

  IOP = volume['Iops']

  try:

    if VolumeType == 'gp2' or VolumeType == 'io1' and VolumeSize<=250:

      modify = client.modify_volume(VolumeId=VolumeId,VolumeType='gp3',IOPS='3000','Throughput=125',DryRun=DryRun)

      print(f"{VolumeId} changed to gp3")

    else:

      print(f"{VolumeId} does not fit criteria")

  except botocore.exceptions.ClientError as error:

    print(error)

    if VolumeType == 'gp2' or VolumeType == 'io1' and VolumeSize>=250 and =<1000:

      modify = client.modify_volume(VolumeId=VolumeId,VolumeType='gp3',IOPS='3000','Throughput=250',DryRun=DryRun)

      print(f"{VolumeId} changed to gp3")

    else:

      print(f"{VolumeId} does not fit criteria")

  except botocore.exceptions.ClientError as error:

    print(error)
Reply
#2
"and <= 1000" is not valid Python. If testing that number is in a rande use
250 <= VolumeSize <= 1000

Should 'Throughput = 250' have the quotes removred? I don't see where you assign a value to DryRun. May be more errors. You should post your error message.

I aso think you have some logic errors, or at least confusing logic. Is volume == 500 a valid crireria or not?
if volume_type in ('iol', ,gp1'):
    try:
        If volume_size <= 250:
            # do <= 250 stuff
        elif volume_size <= 1000;
             # do 250 < x <= 1000 stuff
        else:
             print(volume_id, 'does not fit criteria')
    excrpt botcore.exceptions.ClientError as e:
        Print(e)
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020