Repository: ifosch/accloudtant

Issue:
Fails with Python 3
My system have Python 3 installed by default (Archlinux). This is the output of `accloudtant report`:

```
Traceback (most recent call last):
  File "/usr/bin/accloudtant", line 22, in <module>
    cli()
  File "/usr/lib/python3.5/site-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3.5/site-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3.5/site-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3.5/site-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3.5/site-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/usr/bin/accloudtant", line 19, in report
    click.echo(Reports())
  File "/usr/lib/python3.5/site-packages/click/utils.py", line 221, in echo
    message = text_type(message)
  File "/usr/lib/python3.5/site-packages/accloudtant/aws/reports.py", line 69, in __repr__
    instance.name,
  File "/usr/lib/python3.5/site-packages/accloudtant/aws/instance.py", line 68, in name
    return names[0]['Value']
IndexError: list index out of range
```

I can't verify that it works well on Python 2 so fell free to close this issue and open a new one if the problem is not caused by the Python version.

Comments:

Patch:
diff --git a/accloudtant/aws/instance.py b/accloudtant/aws/instance.py
index 4e19b2d..2073f28 100644
--- a/accloudtant/aws/instance.py
+++ b/accloudtant/aws/instance.py
@@ -62,7 +62,7 @@ class Instance(object):
     @property
     def name(self):
         names = [tag for tag in self.tags if tag['Key'] == 'Name']
-        if names is None:
+        if len(names) == 0:
             return ''
         else:
             return names[0]['Value']


Test patch:
diff --git a/tests/aws/test_instance.py b/tests/aws/test_instance.py
index d90e2c5..a016f7b 100644
--- a/tests/aws/test_instance.py
+++ b/tests/aws/test_instance.py
@@ -73,6 +73,57 @@ def test_instance():
     assert(instance.best == 0.293)
 
 
+def test_unnamed_instance():
+    az = 'us-east-1b'
+    region = 'us-east-1'
+    instance_data = {
+        'id': 'i-1840273e',
+        'tags': [],
+        'instance_type': 'r2.8xlarge',
+        'placement': {
+            'AvailabilityZone': az,
+        },
+        'state': {
+            'Name': 'running',
+        },
+        'launch_time': datetime.datetime(
+                2015,
+                10,
+                22,
+                14,
+                15,
+                10,
+                tzinfo=tzutc()
+            ),
+        'console_output': {'Output': 'RHEL Linux', },
+    }
+
+
+    ec2_instance = MockEC2Instance(instance_data)
+    instance = accloudtant.aws.instance.Instance(ec2_instance)
+
+    assert(instance.id == ec2_instance.id)
+    assert(instance.reserved == 'No')
+    assert(instance.name == '')
+    assert(instance.size == ec2_instance.instance_type)
+    assert(instance.availability_zone == az)
+    assert(instance.region == region)
+    assert(instance.operating_system == 'Red Hat Enterprise Linux')
+    assert(instance.key == 'rhel')
+    assert(instance.state == ec2_instance.state['Name'])
+    assert(instance.current == 0.0)
+    assert(instance.best == 0.0)
+
+    with pytest.raises(ValueError):
+        instance.reserved = 'Maybe'
+
+    instance.current = 0.392
+    instance.best = 0.293
+
+    assert(instance.current == 0.392)
+    assert(instance.best == 0.293)
+
+
 def test_guess_os():
     instance_data_win = {
             'id': 'i-912a4392',