github.com/ruphin/docker@v1.10.1/daemon/graphdriver/proxy.go (about) 1 // +build experimental 2 3 package graphdriver 4 5 import ( 6 "errors" 7 "fmt" 8 9 "github.com/docker/docker/pkg/archive" 10 ) 11 12 type graphDriverProxy struct { 13 name string 14 client pluginClient 15 } 16 17 type graphDriverRequest struct { 18 ID string `json:",omitempty"` 19 Parent string `json:",omitempty"` 20 MountLabel string `json:",omitempty"` 21 } 22 23 type graphDriverResponse struct { 24 Err string `json:",omitempty"` 25 Dir string `json:",omitempty"` 26 Exists bool `json:",omitempty"` 27 Status [][2]string `json:",omitempty"` 28 Changes []archive.Change `json:",omitempty"` 29 Size int64 `json:",omitempty"` 30 Metadata map[string]string `json:",omitempty"` 31 } 32 33 type graphDriverInitRequest struct { 34 Home string 35 Opts []string 36 } 37 38 func (d *graphDriverProxy) Init(home string, opts []string) error { 39 args := &graphDriverInitRequest{ 40 Home: home, 41 Opts: opts, 42 } 43 var ret graphDriverResponse 44 if err := d.client.Call("GraphDriver.Init", args, &ret); err != nil { 45 return err 46 } 47 if ret.Err != "" { 48 return errors.New(ret.Err) 49 } 50 return nil 51 } 52 53 func (d *graphDriverProxy) String() string { 54 return d.name 55 } 56 57 func (d *graphDriverProxy) Create(id, parent, mountLabel string) error { 58 args := &graphDriverRequest{ 59 ID: id, 60 Parent: parent, 61 MountLabel: mountLabel, 62 } 63 var ret graphDriverResponse 64 if err := d.client.Call("GraphDriver.Create", args, &ret); err != nil { 65 return err 66 } 67 if ret.Err != "" { 68 return errors.New(ret.Err) 69 } 70 return nil 71 } 72 73 func (d *graphDriverProxy) Remove(id string) error { 74 args := &graphDriverRequest{ID: id} 75 var ret graphDriverResponse 76 if err := d.client.Call("GraphDriver.Remove", args, &ret); err != nil { 77 return err 78 } 79 if ret.Err != "" { 80 return errors.New(ret.Err) 81 } 82 return nil 83 } 84 85 func (d *graphDriverProxy) Get(id, mountLabel string) (string, error) { 86 args := &graphDriverRequest{ 87 ID: id, 88 MountLabel: mountLabel, 89 } 90 var ret graphDriverResponse 91 if err := d.client.Call("GraphDriver.Get", args, &ret); err != nil { 92 return "", err 93 } 94 var err error 95 if ret.Err != "" { 96 err = errors.New(ret.Err) 97 } 98 return ret.Dir, err 99 } 100 101 func (d *graphDriverProxy) Put(id string) error { 102 args := &graphDriverRequest{ID: id} 103 var ret graphDriverResponse 104 if err := d.client.Call("GraphDriver.Put", args, &ret); err != nil { 105 return err 106 } 107 if ret.Err != "" { 108 return errors.New(ret.Err) 109 } 110 return nil 111 } 112 113 func (d *graphDriverProxy) Exists(id string) bool { 114 args := &graphDriverRequest{ID: id} 115 var ret graphDriverResponse 116 if err := d.client.Call("GraphDriver.Exists", args, &ret); err != nil { 117 return false 118 } 119 return ret.Exists 120 } 121 122 func (d *graphDriverProxy) Status() [][2]string { 123 args := &graphDriverRequest{} 124 var ret graphDriverResponse 125 if err := d.client.Call("GraphDriver.Status", args, &ret); err != nil { 126 return nil 127 } 128 return ret.Status 129 } 130 131 func (d *graphDriverProxy) GetMetadata(id string) (map[string]string, error) { 132 args := &graphDriverRequest{ 133 ID: id, 134 } 135 var ret graphDriverResponse 136 if err := d.client.Call("GraphDriver.GetMetadata", args, &ret); err != nil { 137 return nil, err 138 } 139 if ret.Err != "" { 140 return nil, errors.New(ret.Err) 141 } 142 return ret.Metadata, nil 143 } 144 145 func (d *graphDriverProxy) Cleanup() error { 146 args := &graphDriverRequest{} 147 var ret graphDriverResponse 148 if err := d.client.Call("GraphDriver.Cleanup", args, &ret); err != nil { 149 return nil 150 } 151 if ret.Err != "" { 152 return errors.New(ret.Err) 153 } 154 return nil 155 } 156 157 func (d *graphDriverProxy) Diff(id, parent string) (archive.Archive, error) { 158 args := &graphDriverRequest{ 159 ID: id, 160 Parent: parent, 161 } 162 body, err := d.client.Stream("GraphDriver.Diff", args) 163 if err != nil { 164 body.Close() 165 return nil, err 166 } 167 return archive.Archive(body), nil 168 } 169 170 func (d *graphDriverProxy) Changes(id, parent string) ([]archive.Change, error) { 171 args := &graphDriverRequest{ 172 ID: id, 173 Parent: parent, 174 } 175 var ret graphDriverResponse 176 if err := d.client.Call("GraphDriver.Changes", args, &ret); err != nil { 177 return nil, err 178 } 179 if ret.Err != "" { 180 return nil, errors.New(ret.Err) 181 } 182 183 return ret.Changes, nil 184 } 185 186 func (d *graphDriverProxy) ApplyDiff(id, parent string, diff archive.Reader) (int64, error) { 187 var ret graphDriverResponse 188 if err := d.client.SendFile(fmt.Sprintf("GraphDriver.ApplyDiff?id=%s&parent=%s", id, parent), diff, &ret); err != nil { 189 return -1, err 190 } 191 if ret.Err != "" { 192 return -1, errors.New(ret.Err) 193 } 194 return ret.Size, nil 195 } 196 197 func (d *graphDriverProxy) DiffSize(id, parent string) (int64, error) { 198 args := &graphDriverRequest{ 199 ID: id, 200 Parent: parent, 201 } 202 var ret graphDriverResponse 203 if err := d.client.Call("GraphDriver.DiffSize", args, &ret); err != nil { 204 return -1, err 205 } 206 if ret.Err != "" { 207 return -1, errors.New(ret.Err) 208 } 209 return ret.Size, nil 210 }