service.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //go:build windows
  2. package hcs
  3. import (
  4. "context"
  5. "encoding/json"
  6. hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
  7. "github.com/Microsoft/hcsshim/internal/vmcompute"
  8. )
  9. // GetServiceProperties returns properties of the host compute service.
  10. func GetServiceProperties(ctx context.Context, q hcsschema.PropertyQuery) (*hcsschema.ServiceProperties, error) {
  11. operation := "hcs::GetServiceProperties"
  12. queryb, err := json.Marshal(q)
  13. if err != nil {
  14. return nil, err
  15. }
  16. propertiesJSON, resultJSON, err := vmcompute.HcsGetServiceProperties(ctx, string(queryb))
  17. events := processHcsResult(ctx, resultJSON)
  18. if err != nil {
  19. return nil, &HcsError{Op: operation, Err: err, Events: events}
  20. }
  21. if propertiesJSON == "" {
  22. return nil, ErrUnexpectedValue
  23. }
  24. properties := &hcsschema.ServiceProperties{}
  25. if err := json.Unmarshal([]byte(propertiesJSON), properties); err != nil {
  26. return nil, err
  27. }
  28. return properties, nil
  29. }
  30. // ModifyServiceSettings modifies settings of the host compute service.
  31. func ModifyServiceSettings(ctx context.Context, settings hcsschema.ModificationRequest) error {
  32. operation := "hcs::ModifyServiceSettings"
  33. settingsJSON, err := json.Marshal(settings)
  34. if err != nil {
  35. return err
  36. }
  37. resultJSON, err := vmcompute.HcsModifyServiceSettings(ctx, string(settingsJSON))
  38. events := processHcsResult(ctx, resultJSON)
  39. if err != nil {
  40. return &HcsError{Op: operation, Err: err, Events: events}
  41. }
  42. return nil
  43. }