예제 #1
0
 def get_host_memorySize(self, host):
     summary_hardware = self.get_host_hardwaresummary(host)
     mem_size = summary_hardware.memorySize
     print '------mem_size------',
     print mem_size,
     print type(mem_size)
     size = convert_byte_to(mem_size)
     return size
예제 #2
0
파일: VMWNode.py 프로젝트: smarkm/ovm
 def _VMWNodeEnvHelper__populateDictionary(self):
     if self._VMWNodeEnvHelper__dict is not None:
         self._VMWNodeEnvHelper__dict = None
         #(comp_dict[component.type], device_name, device_type, device_size, mount_path, device_block, device_blocksize, device_size, device_size, datastore_name, datastore_summary, datastore_type, datastore_size, datastore_description, datastore_status, status, status, spec, nw_name, nw_description, nw_type, nw_details, vswitch_key, vswitch_name, nw_type, vnic, spec, ip, vnic, nw_type, vswitch_name, vlan_id, vswitch, pnics, pnics_name, pnics_key, pnics_key, vswitch, self._VMWNodeEnvHelper__dict) = (component, storage_device.displayName, storage_device.deviceType, 0, storage_device.deviceName, storage_device.capacity.block, storage_device.capacity.blockSize, device_block * device_blocksize, convert_byte_to(device_size, convert_to='G', humansize=True), datastore.name, datastore.summary, datastore_summary.type, convert_byte_to(datastore_summary.capacity, convert_to='GB', humansize=False), datastore.name, datastore.overallStatus, 'OUT_OF_SYNC', 'IN_SYNC', portgroup.spec, portgroup.spec.name, nw_name, '', '', portgroup.vswitch, '', 'VMKernel', None, vnic.spec, spec.ip, virtual_nic, 'Virtual Machine', spec.vswitchName, spec.vlanId, None, [], [], [], vswitch.pnic, virtual_switch, None)
     cpu_attributes = [key_cpu_count, key_cpu_vendor_id, key_cpu_model_name, key_cpu_mhz]
     memory_attributes = [key_memory_total, key_memory_free]
     disk_attributes = [key_disk_file_system, key_disk_size, key_disk_mounted]
     print 'BBB Just before node_proxy ',
     print self.node_proxy is None
     host_mob = self.node_proxy.get_hs()
     print 'DEBUG======self.node_proxy.client.server======',
     print self.node_proxy.client.server
     print 'DEBUG======host_mob======',
     print host_mob
     print 'DEBUG=====host_mob.name====',
     print host_mob.name
     hw_summary = host_mob.summary.hardware
     v_idx = hw_summary.cpuModel.find(' ')
     cpu_vendor = hw_summary.cpuModel[0:v_idx]
     cpu_model = hw_summary.cpuModel[v_idx + 1:]
     cpu_dict = {key_cpu_count: hw_summary.numCpuPkgs, key_cpu_vendor_id: cpu_vendor, key_cpu_model_name: cpu_model, key_cpu_mhz: hw_summary.cpuMhz}
     memory_dict = {key_memory_total: str(hw_summary.memorySize / 1048576), key_memory_free: 0}
     network_list = []
     network = host_mob.config.network
     host_virtual_nics = network.vnic
     for vnic in host_virtual_nics:
         network_list.append({key_network_interface_name: vnic.device, key_network_ip: vnic.spec.ip.ipAddress})
     nics = {}
     bridges = {}
     host_portgroups = network.portgroup
     host_physical_nics = network.pnic
     host_virtual_switches = network.vswitch
     host_networks = host_mob.network
     host_networks_name = [hnw.name for hnw in host_networks]
     port_groups_list = []
     for portgroup in host_portgroups:
         spec = portgroup.spec
         nw_name = portgroup.spec.name
         nw_description = nw_name
         nw_type = ''
         nw_details = ''
         vswitch_key = portgroup.vswitch
         vswitch_name = ''
         if spec:
             vswitch_name = spec.vswitchName
             vlan_id = spec.vlanId
             vswitch = None
             pnics = []
             nw_details += 'Switch:%s, VlanId:%s' % (vswitch_name, vlan_id)
             for virtual_switch in host_virtual_switches:
                 if vswitch_key == virtual_switch.key:
                     vswitch = virtual_switch
                     break
             if vswitch:
                 try:
                     pnics_key = vswitch.pnic
                 except AttributeError as ex:
                     pnics_key = []
                 for pnic_key in pnics_key:
                     for physical_nic in host_physical_nics:
                         if pnic_key == physical_nic.key:
                             pnics.append(physical_nic)
                             break
                 if pnics:
                     pnics_name = []
                     for pnic in pnics:
                         pnics_name.append(pnic.device)
                     nw_details += ', Physical adapters:%s' % ','.join(pnics_name)
         if nw_name in host_networks_name:
             nw_type = 'Virtual Machine'
         else:
             nw_type = 'VMKernel'
             vnic = None
             for virtual_nic in host_virtual_nics:
                 if nw_name == virtual_nic.portgroup:
                     break
             if vnic:
                 spec = vnic.spec
                 ip = spec.ip
                 nw_details += ', Virtual Adapter:%s, IP:%s' % (vnic.device, ip.ipAddress)
         port_groups_list.append({key_virtual_network_name: to_str(nw_name), key_virtual_network_type: to_str(nw_type), key_virtual_network_details: to_str(nw_details), key_virtual_network_description: to_str(nw_description), key_virtual_network_switch: to_str(vswitch_name)})
     storage_resource_list = []
     datastores = host_mob.datastore
     for datastore in datastores:
         datastore_name = datastore.name
         datastore_summary = datastore.summary
         datastore_type = datastore_summary.type
         
         ################
         datastore_size = convert_byte_to(datastore_summary.capacity,convert_to = 'GB',humansize = False)
         datastore_description = datastore.name
         datastore_status = datastore.overallStatus
         status = 'OUT_OF_SYNC'
         if datastore_status in ('green',):
             status = 'IN_SYNC'
         storage_resource_list.append({key_storage_resource_name: to_str(datastore_name), key_storage_resource_type: to_str(datastore_type), key_storage_resource_size: to_str(datastore_size), key_storage_resource_description: to_str(datastore_description), key_storage_resource_status: to_str(status)})
     disk_list = []
     storage_devices = host_mob.configManager.storageSystem.storageDeviceInfo.scsiLun
     for storage_device in storage_devices:
         device_name = storage_device.displayName
         device_type = storage_device.deviceType
         device_size = 0
         if device_type in ('disk',):
             device_block = storage_device.capacity.block
             device_blocksize = storage_device.capacity.blockSize
             device_size = device_block * device_blocksize
             ###########
             device_size = convert_byte_to(device_size,convert_to = 'G',humansize = True)
         mount_path = storage_device.deviceName
         disk_list.append({key_disk_file_system: to_str(device_name), key_disk_size: to_str(device_size), key_disk_mounted: to_str(mount_path)})
     summary = host_mob.summary
     product = summary.config.product
     os_dict = {key_os_release:product.version + 'build-' + product.build,key_os_system:product.name,key_os_machine:product.osType,key_os_distro:product.name,key_os_distro_ver:product.version,key_os_distro_string:product.fullName,'node_name':summary.config.name}
     def_bridge = ''
     platform_dict = {'version':product.version}
     if platform_dict is None:
         raise Exception('Cannot get server platform')
     self._VMWNodeEnvHelper__dict = dict([('cpu_info',cpu_dict),('memory_info',memory_dict),('disk_info',disk_list),('network_info',network_list),('nic_info',nics),('bridge_info',bridges),('os_info',os_dict),('default_bridge',def_bridge),('platform_info',platform_dict),('virt_nw_info',port_groups_list),('storage_info',storage_resource_list)])
     
     comp_dict = {}
     components = DBHelper().get_all(Component)
     for component in components:
         comp_dict[component.type] = component
     instances = []
     for key,val in self._VMWNodeEnvHelper__dict.iteritems():
         print key,'-----------------',val
         if key in ('cpu_info', 'memory_info', 'os_info', 'nic_info', 'bridge_info', 'platform_info'):
             for k1,v1 in val.iteritems():
                 inst = Instance(to_unicode(k1))
                 inst.value = to_unicode(v1)
                 inst.display_name = to_unicode('')
                 inst.component = comp_dict[key]
                 inst.node_id = self.node_id
                 instances.append(inst)
             continue
         if key in ('disk_info', 'storage_info'):
             inst = Instance(to_unicode('disks'))
             inst.value = to_unicode(val)
             inst.display_name = to_unicode('')
             inst.component = comp_dict[key]
             inst.node_id = self.node_id
             instances.append(inst)
             continue
         if key in ('network_info',):
             for i in range(len(val)):
                 k1,v1 = val[i]
                 inst = Instance(to_unicode(val[i][k1]))
                 inst.value = to_unicode(val[i][v1])
                 inst.display_name = to_unicode('')
                 inst.component = comp_dict[key]
                 inst.node_id = self.node_id
                 instances.append(inst)
             continue
         if key in ('virt_nw_info',):
             inst = Instance(to_unicode('networks'))
             inst.value = to_unicode(val)
             inst.display_name = to_unicode('')
             inst.component = comp_dict[key]
             inst.node_id = self.node_id
             instances.append(inst)
             continue
         if key in ('default_bridge',):
             inst = Instance(to_unicode(key))
             inst.value = to_unicode(val)
             inst.display_name = to_unicode('')
             inst.component = comp_dict[key]
             inst.node_id = self.node_id
             instances.append(inst)
             continue
     DBHelper().add_all(instances)