aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/Microsoft/hcsshim/internal/hcs/service.go
blob: a634dfc1515879d010c18574d8d31ed86961f88f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package hcs

import (
	"context"
	"encoding/json"

	hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
	"github.com/Microsoft/hcsshim/internal/vmcompute"
)

// GetServiceProperties returns properties of the host compute service.
func GetServiceProperties(ctx context.Context, q hcsschema.PropertyQuery) (*hcsschema.ServiceProperties, error) {
	operation := "hcs::GetServiceProperties"

	queryb, err := json.Marshal(q)
	if err != nil {
		return nil, err
	}
	propertiesJSON, resultJSON, err := vmcompute.HcsGetServiceProperties(ctx, string(queryb))
	events := processHcsResult(ctx, resultJSON)
	if err != nil {
		return nil, &HcsError{Op: operation, Err: err, Events: events}
	}

	if propertiesJSON == "" {
		return nil, ErrUnexpectedValue
	}
	properties := &hcsschema.ServiceProperties{}
	if err := json.Unmarshal([]byte(propertiesJSON), properties); err != nil {
		return nil, err
	}
	return properties, nil
}

// ModifyServiceSettings modifies settings of the host compute service.
func ModifyServiceSettings(ctx context.Context, settings hcsschema.ModificationRequest) error {
	operation := "hcs::ModifyServiceSettings"

	settingsJSON, err := json.Marshal(settings)
	if err != nil {
		return err
	}
	resultJSON, err := vmcompute.HcsModifyServiceSettings(ctx, string(settingsJSON))
	events := processHcsResult(ctx, resultJSON)
	if err != nil {
		return &HcsError{Op: operation, Err: err, Events: events}
	}
	return nil
}