@@ -1073,6 +1073,13 @@ def poststart(server_client, server, os_family, **_):
10731073 server_obj = get_server_by_context (server_client , server , os_family )
10741074 ctx .logger .debug ("Summary config: {}" .format (server_obj .summary .config ))
10751075 ctx .logger .debug ("Network vm: {}" .format (server_obj .network ))
1076+ disk_size = None
1077+ for device in server_obj .summary .vm .config .hardware .device :
1078+ if isinstance (device , vim .vm .device .VirtualDisk ):
1079+ disk_size = device .capacityInKB // 1024 // 1024
1080+ ctx .logger .debug ("disk_size: {}" .format (disk_size ))
1081+ break
1082+
10761083 expected_configuration = {}
10771084 network = json .loads (json .dumps (server_obj .network ,
10781085 cls = VmomiSupport .VmomiJSONEncoder ,
@@ -1082,6 +1089,7 @@ def poststart(server_client, server, os_family, **_):
10821089 sort_keys = True , indent = 4 ))
10831090 expected_configuration ['network' ] = network
10841091 expected_configuration ['summary' ] = summary
1092+ expected_configuration ['disk_size' ] = disk_size
10851093
10861094 ctx .instance .runtime_properties [
10871095 'expected_configuration' ] = expected_configuration
@@ -1150,6 +1158,12 @@ def check_drift(server_client, **_):
11501158 ctx .instance .runtime_properties ['spec_update' ] = True
11511159 needs_update = True
11521160
1161+ # get new disk_size from update
1162+ disk_size = ctx .node .properties .get ('server' , {}).get ('disk_size' )
1163+ if disk_size and disk_size != expected_configuration ['disk_size' ]:
1164+ ctx .instance .runtime_properties ['disk_size_update' ] = True
1165+ needs_update = True
1166+
11531167 # handled and expected possible update
11541168 if needs_update :
11551169 return True
@@ -1166,6 +1180,8 @@ def update(server_client, **_):
11661180 spec_update = ctx .instance .runtime_properties .pop ('spec_update' , None )
11671181 network_update = \
11681182 ctx .instance .runtime_properties .pop ('network_update' , None )
1183+ disk_size_update = \
1184+ ctx .instance .runtime_properties .pop ('disk_size_update' , None )
11691185 if spec_update :
11701186 cpus = ctx .node .properties .get ('server' , {}).get ('cpus' )
11711187 memory = ctx .node .properties .get ('server' , {}).get ('memory' )
@@ -1181,6 +1197,31 @@ def update(server_client, **_):
11811197 'summary' ]['memorySizeMB' ] = memory
11821198 ctx .instance .runtime_properties ['expected_configuration' ][
11831199 'summary' ]['numCpu' ] = cpus
1200+ ctx .instance .runtime_properties .dirty = True
1201+ ctx .instance .update ()
1202+ if disk_size_update :
1203+ disk_size = ctx .node .properties .get ('server' , {}).get ('disk_size' )
1204+ server_obj = server_client .get_server_by_id (
1205+ ctx .instance .runtime_properties [VSPHERE_SERVER_ID ])
1206+ device_changes = []
1207+ for device in server_obj .config .hardware .device :
1208+ if isinstance (device , vim .vm .device .VirtualDisk ):
1209+ diskspec = vim .vm .device .VirtualDeviceSpec ()
1210+ diskspec .operation = \
1211+ vim .vm .device .VirtualDeviceSpec .Operation .edit
1212+ diskspec .device = device
1213+ diskspec .device .capacityInKB = disk_size * 1024 * 1024
1214+ device_changes .append (diskspec )
1215+ break
1216+
1217+ vmconf = vim .vm .ConfigSpec ()
1218+ vmconf .deviceChange = device_changes
1219+ task = server_obj .obj .ReconfigVM_Task (spec = vmconf )
1220+ server_client ._wait_for_task (task )
1221+ ctx .instance .runtime_properties ['expected_configuration' ][
1222+ 'disk_size' ] = disk_size
1223+ ctx .instance .runtime_properties .dirty = True
1224+ ctx .instance .update ()
11841225 if network_update :
11851226 server_obj = server_client .get_server_by_id (
11861227 ctx .instance .runtime_properties [VSPHERE_SERVER_ID ])
@@ -1305,4 +1346,5 @@ def update(server_client, **_):
13051346 manager_network_ip = get_ip_from_vsphere_nic_ips (network )
13061347 ctx .instance .runtime_properties [IP ] = manager_network_ip or \
13071348 default_ip
1349+ ctx .instance .runtime_properties .dirty = True
13081350 ctx .instance .update ()
0 commit comments