github.com/containers/podman/v4@v4.9.4/pkg/bindings/generate/generate.go (about) 1 package generate 2 3 import ( 4 "context" 5 "errors" 6 "net/http" 7 "strconv" 8 9 "github.com/containers/podman/v4/pkg/bindings" 10 "github.com/containers/podman/v4/pkg/domain/entities" 11 ) 12 13 func Systemd(ctx context.Context, nameOrID string, options *SystemdOptions) (*entities.GenerateSystemdReport, error) { 14 if options == nil { 15 options = new(SystemdOptions) 16 } 17 conn, err := bindings.GetClient(ctx) 18 if err != nil { 19 return nil, err 20 } 21 params, err := options.ToParams() 22 if err != nil { 23 return nil, err 24 } 25 26 response, err := conn.DoRequest(ctx, nil, http.MethodGet, "/generate/%s/systemd", params, nil, nameOrID) 27 if err != nil { 28 return nil, err 29 } 30 defer response.Body.Close() 31 32 report := &entities.GenerateSystemdReport{} 33 return report, response.Process(&report.Units) 34 } 35 36 // Kube generate Kubernetes YAML (v1 specification) 37 // 38 // Note: Caller is responsible for closing returned reader 39 func Kube(ctx context.Context, nameOrIDs []string, options *KubeOptions) (*entities.GenerateKubeReport, error) { 40 if options == nil { 41 options = new(KubeOptions) 42 } 43 conn, err := bindings.GetClient(ctx) 44 if err != nil { 45 return nil, err 46 } 47 if len(nameOrIDs) < 1 { 48 return nil, errors.New("must provide the name or ID of one container or pod") 49 } 50 51 params, err := options.ToParams() 52 if err != nil { 53 return nil, err 54 } 55 for _, name := range nameOrIDs { 56 params.Add("names", name) 57 } 58 if options.Replicas != nil { 59 params.Set("replicas", strconv.Itoa(int(*options.Replicas))) 60 } 61 response, err := conn.DoRequest(ctx, nil, http.MethodGet, "/generate/kube", params, nil) 62 if err != nil { 63 return nil, err 64 } 65 66 if response.StatusCode == http.StatusOK { 67 return &entities.GenerateKubeReport{Reader: response.Body}, nil 68 } 69 70 // Unpack the error. 71 return nil, response.Process(nil) 72 }