espenak / awsfabrictasks

Other
84 stars 26 forks source link

ec2_list_instances broken with boto 2.6.0 #7

Closed jonathanq closed 11 years ago

jonathanq commented 12 years ago

We are using boto 2.6.0 and I discovered the ec2_list_instances call doesn't work anymore. Works fine with boto 2.5.2.

(pyenv)$ awsfab --awsfab-settings=awsfab_dev ec2_list_instances

id: <...>
   owner_id: <...>
   groups:
      - <...>
   instances:
      - id: i-xxxxxxxxx   (Name: <...>)
Traceback (most recent call last):
  File "/<...>/pyenv/lib/python2.7/site-packages/fabric/main.py", line 717, in main
    *args, **kwargs
  File "/<...>/pyenv/lib/python2.7/site-packages/fabric/tasks.py", line 322, in execute
    results['<local-only>'] = task.run(*args, **new_kwargs)
  File "/<...>/pyenv/lib/python2.7/site-packages/fabric/tasks.py", line 112, in run
    return self.wrapped(*args, **kwargs)
  File "/<...>/pyenv/lib/python2.7/site-packages/awsfabrictasks/ec2/tasks.py", line 214, in ec2_list_instances
    print_ec2_instance(instance, full=full, indentspaces=11)
  File "/<...>/pyenv/lib/python2.7/site-packages/awsfabrictasks/ec2/api.py", line 423, in print_ec2_instance
    value = instance.__dict__[attrname]
KeyError: 'state'

Looking at the changelog for boto 2.6.0 (https://github.com/boto/boto/compare/2.5.2...2.6.0) - specifically https://github.com/boto/boto/commits/develop/boto/ec2/instance.py it appears that the state attribute was removed and a new InstanceState class was created to hold the EC2 instance state. So "state" is no longer in the attributes. It is now _state. Placement was also changed and is now _placement (and an InstancePlacement class introduced).

in awsfabrictasks/ec2/api.py - print_ec2_instance:

if full:
        attrnames = sorted(instance.__dict__.keys())
    else:
        attrnames = ['state', 'instance_type', 'ip_address', 'public_dns_name',
                     'private_dns_name', 'private_ip_address',
                     'key_name', 'tags', 'placement']

If you change state -> _state and placement -> _placement - the code works, but you have to remove the:

        if attrname.startswith('_'):
            continue

Then you get:

id: r-xxxxxxx
   owner_id: xxxxxxxxxxxx
   groups:
      - MyGroup (id:sg-xxxxxxxx)
   instances:
      - id: i-xxxxxxxx   (Name: my_server)
           _state: running(16)
           instance_type: t1.micro
           ip_address: xx.xx.xx.xx
           public_dns_name: ec2-xx-xx-xx-xx.compute-1.amazonaws.com
           private_dns_name: ip-xx-xxx-xxx-xxx.ec2.internal
           private_ip_address: xx-xxx-xxx-xxx
           key_name: my_key
           tags: {             u'Name': u'my_server'}
           _placement: us-east-1a

Of course this won't work with older versions of boto - and doesn't really take advantage of the new data in boto 2.6.0 re: previous states. Anyway, I just wanted to report the issue. Not sure how best to handle the solution in a way to support both boto 2.5.2 and boto 2.6.0.

topiaruss commented 11 years ago

I sent pull request https://github.com/espenak/awsfabrictasks/pull/9 that fixes the issue in a backward compatible way.

espenak commented 11 years ago

Great work! Just uploaded version 1.1.1 to pypi.

I also added a Contribute-section with your pull request #9 as example in the docs.

topiaruss commented 11 years ago

Happy to help! Please add a 1.1.1 tag when you have a moment. --r. On 29 May 2013, at 11:52, Espen Angell Kristiansen notifications@github.com wrote:

Great work! Just uploaded version 1.1.1 to pypi.

I also added a Contribute-section with your pull request #9 as example in the docs.

— Reply to this email directly or view it on GitHub.

Russ Ferriday -- Software and Systems Architect/Developer CEO Topia Systems Ltd. russf@topia.com -- +44 7429 518822 -- www.topia.com

espenak commented 11 years ago

Oups, I forgot git push --tags :-) Should be pushed now.