|
5 | 5 |
|
6 | 6 | :license: MIT, see LICENSE for more details. |
7 | 7 | """ |
| 8 | +import concurrent.futures as cf |
8 | 9 | import datetime |
9 | 10 | import logging |
10 | 11 | import socket |
@@ -276,6 +277,97 @@ def get_hardware(self, hardware_id, **kwargs): |
276 | 277 |
|
277 | 278 | return self.hardware.getObject(id=hardware_id, **kwargs) |
278 | 279 |
|
| 280 | + @retry(logger=LOGGER) |
| 281 | + def get_hardware_fast(self, hardware_id): |
| 282 | + """Get details about a hardware device. Similar to get_hardware() but this uses threads |
| 283 | +
|
| 284 | + :param integer id: the hardware ID |
| 285 | + :returns: A dictionary containing a large amount of information about the specified server. |
| 286 | + """ |
| 287 | + |
| 288 | + hw_mask = ( |
| 289 | + 'id, globalIdentifier, fullyQualifiedDomainName, hostname, domain,' |
| 290 | + 'provisionDate, hardwareStatus, bareMetalInstanceFlag, processorPhysicalCoreAmount,' |
| 291 | + 'memoryCapacity, notes, privateNetworkOnlyFlag, primaryBackendIpAddress,' |
| 292 | + 'primaryIpAddress, networkManagementIpAddress, userData, datacenter, hourlyBillingFlag,' |
| 293 | + 'lastTransaction[transactionGroup], hardwareChassis[id,name]' |
| 294 | + ) |
| 295 | + server = self.client.call('SoftLayer_Hardware_Server', 'getObject', id=hardware_id, mask=hw_mask) |
| 296 | + with cf.ThreadPoolExecutor(max_workers=10) as executor: |
| 297 | + networkComponentsMask = ( |
| 298 | + "id, status, speed, maxSpeed, name, ipmiMacAddress, ipmiIpAddress, macAddress, primaryIpAddress," |
| 299 | + "port, primarySubnet[id, netmask, broadcastAddress, networkIdentifier, gateway]," |
| 300 | + "uplinkComponent[networkVlanTrunks[networkVlan[networkSpace]]]" |
| 301 | + ) |
| 302 | + networkComponents = executor.submit( |
| 303 | + self.client.call, 'SoftLayer_Hardware_Server', 'getNetworkComponents', |
| 304 | + id=hardware_id, mask=networkComponentsMask |
| 305 | + ) |
| 306 | + activeComponentsMask = ( |
| 307 | + 'id,hardwareComponentModel[hardwareGenericComponentModel[id,hardwareComponentType[keyName]]]' |
| 308 | + ) |
| 309 | + activeComponents = executor.submit( |
| 310 | + self.client.call, 'SoftLayer_Hardware_Server', 'getActiveComponents', |
| 311 | + id=hardware_id, mask=activeComponentsMask |
| 312 | + ) |
| 313 | + |
| 314 | + activeTransaction = executor.submit( |
| 315 | + self.client.call, 'SoftLayer_Hardware_Server', 'getActiveTransaction', |
| 316 | + id=hardware_id, mask="id, transactionStatus[friendlyName,name]" |
| 317 | + ) |
| 318 | + |
| 319 | + operatingSystemMask = ( |
| 320 | + 'softwareLicense[softwareDescription[manufacturer, name, version, referenceCode]],' |
| 321 | + 'passwords[id,username,password]' |
| 322 | + ) |
| 323 | + operatingSystem = executor.submit( |
| 324 | + self.client.call, 'SoftLayer_Hardware_Server', 'getOperatingSystem', |
| 325 | + id=hardware_id, mask=operatingSystemMask |
| 326 | + ) |
| 327 | + |
| 328 | + # Intentionally reusing the operatingSystemMask here. They are both softwareComponents |
| 329 | + softwareComponents = executor.submit( |
| 330 | + self.client.call, 'SoftLayer_Hardware_Server', 'getSoftwareComponents', |
| 331 | + id=hardware_id, mask=operatingSystemMask |
| 332 | + ) |
| 333 | + |
| 334 | + billingItemMask = ( |
| 335 | + 'id,nextInvoiceTotalRecurringAmount,' |
| 336 | + 'nextInvoiceChildren[nextInvoiceTotalRecurringAmount],' |
| 337 | + 'orderItem.order.userRecord[username]' |
| 338 | + ) |
| 339 | + billingItem = executor.submit( |
| 340 | + self.client.call, 'SoftLayer_Hardware_Server', 'getBillingItem', |
| 341 | + id=hardware_id, mask=billingItemMask |
| 342 | + ) |
| 343 | + |
| 344 | + tagReferences = executor.submit( |
| 345 | + self.client.call, 'SoftLayer_Hardware_Server', 'getTagReferences', |
| 346 | + id=hardware_id, mask="id,tag[name,id]" |
| 347 | + ) |
| 348 | + |
| 349 | + networkVlans = executor.submit( |
| 350 | + self.client.call, 'SoftLayer_Hardware_Server', 'getNetworkVlans', |
| 351 | + id=hardware_id, mask="id,vlanNumber,networkSpace,fullyQualifiedName,primarySubnets[ipAddresses]" |
| 352 | + ) |
| 353 | + |
| 354 | + remoteManagementAccounts = executor.submit( |
| 355 | + self.client.call, 'SoftLayer_Hardware_Server', 'getRemoteManagementAccounts', |
| 356 | + id=hardware_id, mask="username,password" |
| 357 | + ) |
| 358 | + |
| 359 | + server['networkComponents'] = networkComponents.result() |
| 360 | + server['activeComponents'] = activeComponents.result() |
| 361 | + server['activeTransaction'] = activeTransaction.result() |
| 362 | + server['operatingSystem'] = operatingSystem.result() |
| 363 | + server['softwareComponents'] = softwareComponents.result() |
| 364 | + server['billingItem'] = billingItem.result() |
| 365 | + server['networkVlans'] = networkVlans.result() |
| 366 | + server['remoteManagementAccounts'] = remoteManagementAccounts.result() |
| 367 | + server['tagReferences'] = tagReferences.result() |
| 368 | + |
| 369 | + return server |
| 370 | + |
279 | 371 | def reload(self, hardware_id, post_uri=None, ssh_keys=None, lvm=False): |
280 | 372 | """Perform an OS reload of a server with its current configuration. |
281 | 373 |
|
|
0 commit comments