Пример #1
0
async def get_gpu_details():
    """Gets GPU details from nvidia-smi."""
    details = {
        NAME: '',
        DRIVER_VERSION: '',
        CUDA_VERSION: '',
        COUNT: 0,
        GPU: 0,
        MEMORY: 0,
        TEMPERATURE: '',
    }
    app_log.debug('Getting GPU information from nvidia-smi')
    process = await asyncio.create_subprocess_shell(
        NVIDIA_CMD,
        stdout=asyncio.subprocess.PIPE,
        stderr=asyncio.subprocess.PIPE)
    stdout, _ = await process.communicate()

    if process.returncode != 0:
        app_log.warning('Unable to determine GPU information')
        return details

    root = xml.fromstring(stdout)
    details[DRIVER_VERSION] = root.find(DRIVER_VERSION).text
    details[CUDA_VERSION] = root.find(CUDA_VERSION).text
    gpu = root.find(GPU)
    details[COUNT] = int(root.find('attached_gpus').text)
    details[NAME] = gpu.find('product_name').text
    utilization = gpu.find('utilization')
    details[GPU] = int(utilization.find('gpu_util').text[:-1].strip())
    details[MEMORY] = int(utilization.find('memory_util').text[:-1].strip())
    details[TEMPERATURE] = gpu.find(TEMPERATURE).find('gpu_temp').text

    return details
Пример #2
0
async def get_metadata():
    """Retrieves JSON-formatted metadata from the local metadata server."""
    request = HTTPRequest(METADATA_SERVER, headers=METADATA_HEADER)
    client = AsyncHTTPClient()
    metadata = {}
    try:
        app_log.debug('Retrieving GCE Metadata')
        response = await client.fetch(request)
        metadata = json.loads(response.body)
    except HTTPClientError as e:
        app_log.error('Unable to retrieve Metadata %s: %s', e.code, e.message)
    return metadata
Пример #3
0
async def get_pricelist():
    """Retrieves JSON-formatted pricelist data from cloud pricing calculator."""
    client = AsyncHTTPClient()
    pricelist = {}
    try:
        app_log.debug('Retrieving pricelist')
        response = await client.fetch(
            "https://cloudpricingcalculator.appspot.com/static/data/pricelist.json"
        )
        pricelist = json.loads(response.body)
    except HTTPClientError as e:
        app_log.error('Unable to retrieve pricelist %s: %s', e.code, e.message)
    return pricelist
Пример #4
0
async def get_gpu_list(zone):
    """Uses gcloud to return a list of available Accelerator Types."""
    accelerator_types = []
    zone = zone[zone.rindex('/') + 1:]
    app_log.debug('Getting Accelerator Types from gcloud')
    process = await asyncio.create_subprocess_shell(
        '{} --filter="zone:{}"'.format(ACCELERATOR_TYPES_CMD, zone),
        stdout=asyncio.subprocess.PIPE,
        stderr=asyncio.subprocess.PIPE)
    stdout, _ = await process.communicate()

    if process.returncode != 0:
        app_log.error('Unable to obtain Accelerator Types from gcloud')
        return accelerator_types

    accelerator_types = json.loads(stdout.decode())
    return accelerator_types
Пример #5
0
async def get_machine_type_details(zone, machine_type):
  """Uses gcloud to return the Machine Type details."""
  machine_type_name = machine_type[machine_type.rindex('/') + 1:]
  details = {NAME: machine_type_name, DESCRIPTION: ''}
  app_log.debug('Getting Machine Type details from gcloud')
  process = await asyncio.create_subprocess_shell(
      '{} {} --zone {}'.format(MACHINE_TYPE_CMD, machine_type_name, zone),
      stdout=asyncio.subprocess.PIPE,
      stderr=asyncio.subprocess.PIPE)
  stdout, _ = await process.communicate()

  if process.returncode != 0:
    app_log.error('Unable to obtain Machine Type details for %s', machine_type)
    return details

  for line in stdout.decode().splitlines():
    if line.startswith(DESCRIPTION):
      details[DESCRIPTION] = line.split(': ')[1].strip()
    elif line.startswith(NAME):
      details[NAME] = line.split(': ')[1].strip()
  return details