func getSupportedSchemas()

in plugins/cmd/query-hcs-capabilities/main.go [40:81]


func getSupportedSchemas() ([]*Version, error) {

	// Attempt to load vmcompute.dll
	if err := vmcompute.Load(); err != nil {
		return nil, fmt.Errorf("failed to load %s: %s", vmcompute.Name, err.Error())
	}

	// Convert our query string into a UTF-16 pointer
	queryPtr, err := windows.UTF16PtrFromString("{\"PropertyTypes\": [\"Basic\"]}")
	if err != nil {
		return nil, fmt.Errorf("failed to convert string to UTF-16: %s", err.Error())
	}

	// Call HcsGetServiceProperties() to query the supported schema version
	var resultPtr *uint16 = nil
	retval, _, _ := hcsGetServiceProperties.Call(
		uintptr(unsafe.Pointer(queryPtr)),
		uintptr(unsafe.Pointer(&resultPtr)),
	)

	// Verify that the query was successful
	if retval != 0 {
		return nil, fmt.Errorf("HcsGetServiceProperties() failed: %v", windows.Errno(retval))
	}

	// Convert the result into a JSON string
	result := windows.UTF16PtrToString((*uint16)(unsafe.Pointer(resultPtr)))

	// Parse the JSON
	serviceProperties := &ServiceProperties{}
	if err := json.Unmarshal([]byte(result), &serviceProperties); err != nil {
		return nil, err
	}

	// Verify that we have at least one supported schema version
	if len(serviceProperties.Properties) == 0 || len(serviceProperties.Properties[0].SupportedSchemaVersions) == 0 {
		return nil, errors.New("HcsGetServiceProperties() returned zero supported schema versions")
	}

	// Return the list of supported schema versions
	return serviceProperties.Properties[0].SupportedSchemaVersions, nil
}