...
1
2
3 package processorinfo
4
5 import (
6 "context"
7 "encoding/json"
8 "errors"
9 "fmt"
10
11 "github.com/Microsoft/hcsshim/internal/hcs"
12 hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
13 )
14
15
16
17
18 func HostProcessorInfo(ctx context.Context) (*hcsschema.ProcessorTopology, error) {
19 q := hcsschema.PropertyQuery{
20 PropertyTypes: []hcsschema.PropertyType{hcsschema.PTProcessorTopology},
21 }
22 serviceProps, err := hcs.GetServiceProperties(ctx, q)
23 if err != nil {
24 return nil, fmt.Errorf("failed to retrieve processor and processor topology information: %s", err)
25 }
26 if len(serviceProps.Properties) != 1 {
27 return nil, errors.New("wrong number of service properties present")
28 }
29 processorTopology := &hcsschema.ProcessorTopology{}
30 if err := json.Unmarshal(serviceProps.Properties[0], processorTopology); err != nil {
31 return nil, fmt.Errorf("failed to unmarshal host processor topology: %s", err)
32 }
33 return processorTopology, nil
34 }
35
View as plain text