Skip to content
This repository has been archived by the owner on Oct 19, 2020. It is now read-only.

Use munchify instead of assisted_service_client moduels #9

Merged
merged 1 commit into from
Aug 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
boto3
botocore
pyyaml
munch==2.5.0
19 changes: 10 additions & 9 deletions utils.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
import os
import json
from assisted_service_client import ApiClient, Configuration, api, models
from assisted_service_client import ApiClient, Configuration, api
from munch import munchify



class InventoryHost:

def __init__(self, host_dict):
self._host = models.Host(**host_dict)
self._inventory = models.Inventory(**json.loads(self._host.inventory))
self._host = munchify(**host_dict)
self._inventory = munchify(**json.loads(self._host.inventory))


def get_inventory_host_nics_data(self):
interfaces_list = [models.Interface(**interface) for interface in self._inventory.interfaces]
interfaces_list = [munchify(**interface) for interface in self._inventory.interfaces]
return [{'name': interface.name, 'model': interface.product, 'mac': interface.mac_address, 'ip': self._get_network_interface_ip(interface), 'speed': interface.speed_mbps} for interface in interfaces_list]


def get_inventory_host_cpu_data(self):
cpu = models.Cpu(**self._inventory.cpu)
cpu = munchify(**self._inventory.cpu)
return {'model': cpu.model_name, 'arch': cpu.architecture, 'flags': cpu.flags, 'clockMegahertz': cpu.frequency, 'count': cpu.count}


def get_inventory_host_storage_data(self):
disks_list = [models.Disk(**disk) for disk in self._inventory.disks]
return [{'name': disk.name, 'vendor': disk.vendor, 'sizeBytes': disk.size_bytes, 'model': disk.model, 'wwn': disk.wwn, 'hctl': disk.hctl, 'serialNumber': disk.serial, 'rotational': True if disk.drive_type == 'HDD' else False} for disk in disks_list]
disks_list = [munchify(**disk) for disk in self._inventory.disks]
return [{'name': disk.name, 'vendor': disk.vendor, 'sizeBytes': disk.size_bytes, 'model': disk.model, 'wwn': disk.wwn, 'hctl': disk.hctl, 'serialNumber': disk.serial, 'rotational': True if disk.drive_type == 'HDD' else False} for disk in disks_list]


def get_inventory_host_memory(self):
memory = models.Memory(**self._inventory.memory)
memory = munchify(**self._inventory.memory)
return int(memory.physical_bytes / 1024 / 1024)


Expand All @@ -36,7 +37,7 @@ def get_inventory_host_name(self):


def get_inventory_host_system_vendor(self):
system_vendor = models.SystemVendor(**self._inventory.system_vendor)
system_vendor = munchify(**self._inventory.system_vendor)
return {'manufacturer': system_vendor.manufacturer, 'productName': system_vendor.product_name, 'serialNumber': system_vendor.serial_number}

def is_role(self, role):
Expand Down