github.com/blixtra/rkt@v0.8.1-0.20160204105720-ab0d1add1a43/api/v1alpha/client_example.go (about) 1 // Copyright 2015 The rkt Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // +build ignore 16 17 package main 18 19 import ( 20 "fmt" 21 "os" 22 23 "github.com/coreos/rkt/api/v1alpha" 24 "golang.org/x/net/context" 25 "google.golang.org/grpc" 26 ) 27 28 func main() { 29 conn, err := grpc.Dial("localhost:15441", grpc.WithInsecure()) 30 if err != nil { 31 fmt.Println(err) 32 os.Exit(1) 33 } 34 c := v1alpha.NewPublicAPIClient(conn) 35 defer conn.Close() 36 37 // List pods. 38 podResp, err := c.ListPods(context.Background(), &v1alpha.ListPodsRequest{ 39 // Specify the request: Fetch and print only running pods and their details. 40 Detail: true, 41 Filters: []*v1alpha.PodFilter{ 42 { 43 States: []v1alpha.PodState{v1alpha.PodState_POD_STATE_RUNNING}, 44 }, 45 }, 46 }) 47 if err != nil { 48 fmt.Println(err) 49 os.Exit(2) 50 } 51 52 for _, p := range podResp.Pods { 53 fmt.Printf("Pod %q is running\n", p.Id) 54 } 55 56 // List images. 57 imgResp, err := c.ListImages(context.Background(), &v1alpha.ListImagesRequest{ 58 // In this request, we fetch the details of images whose names are prefixed with "coreos.com". 59 Detail: true, 60 Filters: []*v1alpha.ImageFilter{ 61 { 62 Prefixes: []string{"coreos.com"}, 63 }, 64 }, 65 }) 66 if err != nil { 67 fmt.Println(err) 68 os.Exit(3) 69 } 70 71 for _, im := range imgResp.Images { 72 fmt.Printf("Found image %q\n", im.Name) 73 } 74 }