Skip to content

Commit

Permalink
Add created_at property to know when vms are created
Browse files Browse the repository at this point in the history
  • Loading branch information
Lantero committed Jun 15, 2018
1 parent 3253455 commit c423907
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


setup(
version='4.0.0',
version='4.1.0',
name='osirium-vcdriver',
description='A vcenter driver based on pyvmomi, fabric and pywinrm',
url='https://github.com/Osirium/vcdriver',
Expand Down
6 changes: 6 additions & 0 deletions test/integration/test_integration.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
import hashlib
import os
import shutil
Expand Down Expand Up @@ -226,3 +227,8 @@ def test_snapshots(vms):
vm.revert_snapshot(snapshot_name)
with snapshot(vm):
pass


def test_created_at(vms):
for vm in vms.values():
assert type(vm.created_at) == datetime.datetime
10 changes: 10 additions & 0 deletions test/unit/test_vm.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
import mock
import os

Expand Down Expand Up @@ -655,3 +656,12 @@ def test_get_all_virtual_machines(get_all_vcenter_objects, connection):
obj2 = mock.MagicMock()
get_all_vcenter_objects.return_value = [obj1, obj2]
assert len(get_all_virtual_machines()) == 2


@mock.patch('vcdriver.vm.connection')
def test_created_at(connection):
vm = VirtualMachine()
vm_object_mock = mock.MagicMock()
vm_object_mock.config.changeVersion = '2018-06-13T15:12:43.700814Z'
vm.__setattr__('_vm_object', vm_object_mock)
assert vm.created_at == datetime.datetime(2018, 6, 13, 15, 12, 43, 700814)
7 changes: 7 additions & 0 deletions vcdriver/vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import base64
import contextlib
import datetime
import os
import sys
import time
Expand Down Expand Up @@ -197,6 +198,12 @@ def ip(self):
validate_ip(ip)
return ip

@property
def created_at(self):
return datetime.datetime.strptime(
self._vm_object.config.changeVersion, '%Y-%m-%dT%H:%M:%S.%fZ'
)

@configurable([
('Virtual Machine Remote Management', 'vcdriver_vm_ssh_username'),
('Virtual Machine Remote Management', 'vcdriver_vm_ssh_password')
Expand Down

0 comments on commit c423907

Please sign in to comment.