repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
CreateTargetHTTPProxy
func (gce *Cloud) CreateTargetHTTPProxy(urlMap *compute.UrlMap, name string) (*compute.TargetHttpProxy, error) { proxy := &compute.TargetHttpProxy{ Name: name, UrlMap: urlMap.SelfLink, } op, err := gce.service.TargetHttpProxies.Insert(gce.projectID, proxy).Do() if err != nil { return nil, err } if err = gce.waitForGlobalOp(op); err != nil { return nil, err } return gce.GetTargetHTTPProxy(name) }
go
func (gce *Cloud) CreateTargetHTTPProxy(urlMap *compute.UrlMap, name string) (*compute.TargetHttpProxy, error) { proxy := &compute.TargetHttpProxy{ Name: name, UrlMap: urlMap.SelfLink, } op, err := gce.service.TargetHttpProxies.Insert(gce.projectID, proxy).Do() if err != nil { return nil, err } if err = gce.waitForGlobalOp(op); err != nil { return nil, err } return gce.GetTargetHTTPProxy(name) }
[ "func", "(", "gce", "*", "Cloud", ")", "CreateTargetHTTPProxy", "(", "urlMap", "*", "compute", ".", "UrlMap", ",", "name", "string", ")", "(", "*", "compute", ".", "TargetHttpProxy", ",", "error", ")", "{", "proxy", ":=", "&", "compute", ".", "TargetHttpProxy", "{", "Name", ":", "name", ",", "UrlMap", ":", "urlMap", ".", "SelfLink", ",", "}", "\n", "op", ",", "err", ":=", "gce", ".", "service", ".", "TargetHttpProxies", ".", "Insert", "(", "gce", ".", "projectID", ",", "proxy", ")", ".", "Do", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "err", "=", "gce", ".", "waitForGlobalOp", "(", "op", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "gce", ".", "GetTargetHTTPProxy", "(", "name", ")", "\n", "}" ]
// CreateTargetHTTPProxy creates and returns a TargetHTTPProxy with the given UrlMap.
[ "CreateTargetHTTPProxy", "creates", "and", "returns", "a", "TargetHTTPProxy", "with", "the", "given", "UrlMap", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L1730-L1743
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
SetURLMapForTargetHTTPProxy
func (gce *Cloud) SetURLMapForTargetHTTPProxy(proxy *compute.TargetHttpProxy, urlMap *compute.UrlMap) error { op, err := gce.service.TargetHttpProxies.SetUrlMap(gce.projectID, proxy.Name, &compute.UrlMapReference{UrlMap: urlMap.SelfLink}).Do() if err != nil { return err } return gce.waitForGlobalOp(op) }
go
func (gce *Cloud) SetURLMapForTargetHTTPProxy(proxy *compute.TargetHttpProxy, urlMap *compute.UrlMap) error { op, err := gce.service.TargetHttpProxies.SetUrlMap(gce.projectID, proxy.Name, &compute.UrlMapReference{UrlMap: urlMap.SelfLink}).Do() if err != nil { return err } return gce.waitForGlobalOp(op) }
[ "func", "(", "gce", "*", "Cloud", ")", "SetURLMapForTargetHTTPProxy", "(", "proxy", "*", "compute", ".", "TargetHttpProxy", ",", "urlMap", "*", "compute", ".", "UrlMap", ")", "error", "{", "op", ",", "err", ":=", "gce", ".", "service", ".", "TargetHttpProxies", ".", "SetUrlMap", "(", "gce", ".", "projectID", ",", "proxy", ".", "Name", ",", "&", "compute", ".", "UrlMapReference", "{", "UrlMap", ":", "urlMap", ".", "SelfLink", "}", ")", ".", "Do", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "gce", ".", "waitForGlobalOp", "(", "op", ")", "\n", "}" ]
// SetURLMapForTargetHTTPProxy sets the given URLMap for the given TargetHTTPProxy.
[ "SetURLMapForTargetHTTPProxy", "sets", "the", "given", "URLMap", "for", "the", "given", "TargetHTTPProxy", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L1746-L1752
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
ListTargetHTTPProxies
func (gce *Cloud) ListTargetHTTPProxies() (*compute.TargetHttpProxyList, error) { // TODO: use PageToken to list all not just the first 500 return gce.service.TargetHttpProxies.List(gce.projectID).Do() }
go
func (gce *Cloud) ListTargetHTTPProxies() (*compute.TargetHttpProxyList, error) { // TODO: use PageToken to list all not just the first 500 return gce.service.TargetHttpProxies.List(gce.projectID).Do() }
[ "func", "(", "gce", "*", "Cloud", ")", "ListTargetHTTPProxies", "(", ")", "(", "*", "compute", ".", "TargetHttpProxyList", ",", "error", ")", "{", "return", "gce", ".", "service", ".", "TargetHttpProxies", ".", "List", "(", "gce", ".", "projectID", ")", ".", "Do", "(", ")", "\n", "}" ]
// ListTargetHTTPProxies lists all TargetHTTPProxies in the project.
[ "ListTargetHTTPProxies", "lists", "all", "TargetHTTPProxies", "in", "the", "project", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L1767-L1770
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
GetTargetHTTPSProxy
func (gce *Cloud) GetTargetHTTPSProxy(name string) (*compute.TargetHttpsProxy, error) { return gce.service.TargetHttpsProxies.Get(gce.projectID, name).Do() }
go
func (gce *Cloud) GetTargetHTTPSProxy(name string) (*compute.TargetHttpsProxy, error) { return gce.service.TargetHttpsProxies.Get(gce.projectID, name).Do() }
[ "func", "(", "gce", "*", "Cloud", ")", "GetTargetHTTPSProxy", "(", "name", "string", ")", "(", "*", "compute", ".", "TargetHttpsProxy", ",", "error", ")", "{", "return", "gce", ".", "service", ".", "TargetHttpsProxies", ".", "Get", "(", "gce", ".", "projectID", ",", "name", ")", ".", "Do", "(", ")", "\n", "}" ]
// TargetHttpsProxy management // GetTargetHTTPSProxy returns the URLMap by name.
[ "TargetHttpsProxy", "management", "GetTargetHTTPSProxy", "returns", "the", "URLMap", "by", "name", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L1775-L1777
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
CreateTargetHTTPSProxy
func (gce *Cloud) CreateTargetHTTPSProxy(urlMap *compute.UrlMap, sslCert *compute.SslCertificate, name string) (*compute.TargetHttpsProxy, error) { proxy := &compute.TargetHttpsProxy{ Name: name, UrlMap: urlMap.SelfLink, SslCertificates: []string{sslCert.SelfLink}, } op, err := gce.service.TargetHttpsProxies.Insert(gce.projectID, proxy).Do() if err != nil { return nil, err } if err = gce.waitForGlobalOp(op); err != nil { return nil, err } return gce.GetTargetHTTPSProxy(name) }
go
func (gce *Cloud) CreateTargetHTTPSProxy(urlMap *compute.UrlMap, sslCert *compute.SslCertificate, name string) (*compute.TargetHttpsProxy, error) { proxy := &compute.TargetHttpsProxy{ Name: name, UrlMap: urlMap.SelfLink, SslCertificates: []string{sslCert.SelfLink}, } op, err := gce.service.TargetHttpsProxies.Insert(gce.projectID, proxy).Do() if err != nil { return nil, err } if err = gce.waitForGlobalOp(op); err != nil { return nil, err } return gce.GetTargetHTTPSProxy(name) }
[ "func", "(", "gce", "*", "Cloud", ")", "CreateTargetHTTPSProxy", "(", "urlMap", "*", "compute", ".", "UrlMap", ",", "sslCert", "*", "compute", ".", "SslCertificate", ",", "name", "string", ")", "(", "*", "compute", ".", "TargetHttpsProxy", ",", "error", ")", "{", "proxy", ":=", "&", "compute", ".", "TargetHttpsProxy", "{", "Name", ":", "name", ",", "UrlMap", ":", "urlMap", ".", "SelfLink", ",", "SslCertificates", ":", "[", "]", "string", "{", "sslCert", ".", "SelfLink", "}", ",", "}", "\n", "op", ",", "err", ":=", "gce", ".", "service", ".", "TargetHttpsProxies", ".", "Insert", "(", "gce", ".", "projectID", ",", "proxy", ")", ".", "Do", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "err", "=", "gce", ".", "waitForGlobalOp", "(", "op", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "gce", ".", "GetTargetHTTPSProxy", "(", "name", ")", "\n", "}" ]
// CreateTargetHTTPSProxy creates and returns a TargetHTTPSProxy with the given URLMap and SslCertificate.
[ "CreateTargetHTTPSProxy", "creates", "and", "returns", "a", "TargetHTTPSProxy", "with", "the", "given", "URLMap", "and", "SslCertificate", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L1780-L1794
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
SetURLMapForTargetHTTPSProxy
func (gce *Cloud) SetURLMapForTargetHTTPSProxy(proxy *compute.TargetHttpsProxy, urlMap *compute.UrlMap) error { op, err := gce.service.TargetHttpsProxies.SetUrlMap(gce.projectID, proxy.Name, &compute.UrlMapReference{UrlMap: urlMap.SelfLink}).Do() if err != nil { return err } return gce.waitForGlobalOp(op) }
go
func (gce *Cloud) SetURLMapForTargetHTTPSProxy(proxy *compute.TargetHttpsProxy, urlMap *compute.UrlMap) error { op, err := gce.service.TargetHttpsProxies.SetUrlMap(gce.projectID, proxy.Name, &compute.UrlMapReference{UrlMap: urlMap.SelfLink}).Do() if err != nil { return err } return gce.waitForGlobalOp(op) }
[ "func", "(", "gce", "*", "Cloud", ")", "SetURLMapForTargetHTTPSProxy", "(", "proxy", "*", "compute", ".", "TargetHttpsProxy", ",", "urlMap", "*", "compute", ".", "UrlMap", ")", "error", "{", "op", ",", "err", ":=", "gce", ".", "service", ".", "TargetHttpsProxies", ".", "SetUrlMap", "(", "gce", ".", "projectID", ",", "proxy", ".", "Name", ",", "&", "compute", ".", "UrlMapReference", "{", "UrlMap", ":", "urlMap", ".", "SelfLink", "}", ")", ".", "Do", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "gce", ".", "waitForGlobalOp", "(", "op", ")", "\n", "}" ]
// SetURLMapForTargetHTTPSProxy sets the given URLMap for the given TargetHTTPSProxy.
[ "SetURLMapForTargetHTTPSProxy", "sets", "the", "given", "URLMap", "for", "the", "given", "TargetHTTPSProxy", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L1797-L1803
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
SetSslCertificateForTargetHTTPSProxy
func (gce *Cloud) SetSslCertificateForTargetHTTPSProxy(proxy *compute.TargetHttpsProxy, sslCert *compute.SslCertificate) error { op, err := gce.service.TargetHttpsProxies.SetSslCertificates(gce.projectID, proxy.Name, &compute.TargetHttpsProxiesSetSslCertificatesRequest{SslCertificates: []string{sslCert.SelfLink}}).Do() if err != nil { return err } return gce.waitForGlobalOp(op) }
go
func (gce *Cloud) SetSslCertificateForTargetHTTPSProxy(proxy *compute.TargetHttpsProxy, sslCert *compute.SslCertificate) error { op, err := gce.service.TargetHttpsProxies.SetSslCertificates(gce.projectID, proxy.Name, &compute.TargetHttpsProxiesSetSslCertificatesRequest{SslCertificates: []string{sslCert.SelfLink}}).Do() if err != nil { return err } return gce.waitForGlobalOp(op) }
[ "func", "(", "gce", "*", "Cloud", ")", "SetSslCertificateForTargetHTTPSProxy", "(", "proxy", "*", "compute", ".", "TargetHttpsProxy", ",", "sslCert", "*", "compute", ".", "SslCertificate", ")", "error", "{", "op", ",", "err", ":=", "gce", ".", "service", ".", "TargetHttpsProxies", ".", "SetSslCertificates", "(", "gce", ".", "projectID", ",", "proxy", ".", "Name", ",", "&", "compute", ".", "TargetHttpsProxiesSetSslCertificatesRequest", "{", "SslCertificates", ":", "[", "]", "string", "{", "sslCert", ".", "SelfLink", "}", "}", ")", ".", "Do", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "gce", ".", "waitForGlobalOp", "(", "op", ")", "\n", "}" ]
// SetSslCertificateForTargetHTTPSProxy sets the given SslCertificate for the given TargetHTTPSProxy.
[ "SetSslCertificateForTargetHTTPSProxy", "sets", "the", "given", "SslCertificate", "for", "the", "given", "TargetHTTPSProxy", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L1806-L1812
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
DeleteTargetHTTPSProxy
func (gce *Cloud) DeleteTargetHTTPSProxy(name string) error { op, err := gce.service.TargetHttpsProxies.Delete(gce.projectID, name).Do() if err != nil { if isHTTPErrorCode(err, http.StatusNotFound) { return nil } return err } return gce.waitForGlobalOp(op) }
go
func (gce *Cloud) DeleteTargetHTTPSProxy(name string) error { op, err := gce.service.TargetHttpsProxies.Delete(gce.projectID, name).Do() if err != nil { if isHTTPErrorCode(err, http.StatusNotFound) { return nil } return err } return gce.waitForGlobalOp(op) }
[ "func", "(", "gce", "*", "Cloud", ")", "DeleteTargetHTTPSProxy", "(", "name", "string", ")", "error", "{", "op", ",", "err", ":=", "gce", ".", "service", ".", "TargetHttpsProxies", ".", "Delete", "(", "gce", ".", "projectID", ",", "name", ")", ".", "Do", "(", ")", "\n", "if", "err", "!=", "nil", "{", "if", "isHTTPErrorCode", "(", "err", ",", "http", ".", "StatusNotFound", ")", "{", "return", "nil", "\n", "}", "\n", "return", "err", "\n", "}", "\n", "return", "gce", ".", "waitForGlobalOp", "(", "op", ")", "\n", "}" ]
// DeleteTargetHTTPSProxy deletes the TargetHTTPSProxy by name.
[ "DeleteTargetHTTPSProxy", "deletes", "the", "TargetHTTPSProxy", "by", "name", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L1815-L1824
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
ListTargetHTTPSProxies
func (gce *Cloud) ListTargetHTTPSProxies() (*compute.TargetHttpsProxyList, error) { // TODO: use PageToken to list all not just the first 500 return gce.service.TargetHttpsProxies.List(gce.projectID).Do() }
go
func (gce *Cloud) ListTargetHTTPSProxies() (*compute.TargetHttpsProxyList, error) { // TODO: use PageToken to list all not just the first 500 return gce.service.TargetHttpsProxies.List(gce.projectID).Do() }
[ "func", "(", "gce", "*", "Cloud", ")", "ListTargetHTTPSProxies", "(", ")", "(", "*", "compute", ".", "TargetHttpsProxyList", ",", "error", ")", "{", "return", "gce", ".", "service", ".", "TargetHttpsProxies", ".", "List", "(", "gce", ".", "projectID", ")", ".", "Do", "(", ")", "\n", "}" ]
// ListTargetHTTPSProxies lists all TargetHTTPSProxies in the project.
[ "ListTargetHTTPSProxies", "lists", "all", "TargetHTTPSProxies", "in", "the", "project", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L1827-L1830
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
GetSslCertificate
func (gce *Cloud) GetSslCertificate(name string) (*compute.SslCertificate, error) { return gce.service.SslCertificates.Get(gce.projectID, name).Do() }
go
func (gce *Cloud) GetSslCertificate(name string) (*compute.SslCertificate, error) { return gce.service.SslCertificates.Get(gce.projectID, name).Do() }
[ "func", "(", "gce", "*", "Cloud", ")", "GetSslCertificate", "(", "name", "string", ")", "(", "*", "compute", ".", "SslCertificate", ",", "error", ")", "{", "return", "gce", ".", "service", ".", "SslCertificates", ".", "Get", "(", "gce", ".", "projectID", ",", "name", ")", ".", "Do", "(", ")", "\n", "}" ]
// SSL Certificate management // GetSslCertificate returns the SslCertificate by name.
[ "SSL", "Certificate", "management", "GetSslCertificate", "returns", "the", "SslCertificate", "by", "name", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L1835-L1837
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
GetBackendService
func (gce *Cloud) GetBackendService(name string) (*compute.BackendService, error) { return gce.service.BackendServices.Get(gce.projectID, name).Do() }
go
func (gce *Cloud) GetBackendService(name string) (*compute.BackendService, error) { return gce.service.BackendServices.Get(gce.projectID, name).Do() }
[ "func", "(", "gce", "*", "Cloud", ")", "GetBackendService", "(", "name", "string", ")", "(", "*", "compute", ".", "BackendService", ",", "error", ")", "{", "return", "gce", ".", "service", ".", "BackendServices", ".", "Get", "(", "gce", ".", "projectID", ",", "name", ")", ".", "Do", "(", ")", "\n", "}" ]
// BackendService Management // GetBackendService retrieves a backend by name.
[ "BackendService", "Management", "GetBackendService", "retrieves", "a", "backend", "by", "name", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L1927-L1929
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
UpdateBackendService
func (gce *Cloud) UpdateBackendService(bg *compute.BackendService) error { op, err := gce.service.BackendServices.Update(gce.projectID, bg.Name, bg).Do() if err != nil { return err } return gce.waitForGlobalOp(op) }
go
func (gce *Cloud) UpdateBackendService(bg *compute.BackendService) error { op, err := gce.service.BackendServices.Update(gce.projectID, bg.Name, bg).Do() if err != nil { return err } return gce.waitForGlobalOp(op) }
[ "func", "(", "gce", "*", "Cloud", ")", "UpdateBackendService", "(", "bg", "*", "compute", ".", "BackendService", ")", "error", "{", "op", ",", "err", ":=", "gce", ".", "service", ".", "BackendServices", ".", "Update", "(", "gce", ".", "projectID", ",", "bg", ".", "Name", ",", "bg", ")", ".", "Do", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "gce", ".", "waitForGlobalOp", "(", "op", ")", "\n", "}" ]
// UpdateBackendService applies the given BackendService as an update to an existing service.
[ "UpdateBackendService", "applies", "the", "given", "BackendService", "as", "an", "update", "to", "an", "existing", "service", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L1932-L1938
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
CreateBackendService
func (gce *Cloud) CreateBackendService(bg *compute.BackendService) error { op, err := gce.service.BackendServices.Insert(gce.projectID, bg).Do() if err != nil { return err } return gce.waitForGlobalOp(op) }
go
func (gce *Cloud) CreateBackendService(bg *compute.BackendService) error { op, err := gce.service.BackendServices.Insert(gce.projectID, bg).Do() if err != nil { return err } return gce.waitForGlobalOp(op) }
[ "func", "(", "gce", "*", "Cloud", ")", "CreateBackendService", "(", "bg", "*", "compute", ".", "BackendService", ")", "error", "{", "op", ",", "err", ":=", "gce", ".", "service", ".", "BackendServices", ".", "Insert", "(", "gce", ".", "projectID", ",", "bg", ")", ".", "Do", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "gce", ".", "waitForGlobalOp", "(", "op", ")", "\n", "}" ]
// CreateBackendService creates the given BackendService.
[ "CreateBackendService", "creates", "the", "given", "BackendService", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L1953-L1959
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
ListBackendServices
func (gce *Cloud) ListBackendServices() (*compute.BackendServiceList, error) { // TODO: use PageToken to list all not just the first 500 return gce.service.BackendServices.List(gce.projectID).Do() }
go
func (gce *Cloud) ListBackendServices() (*compute.BackendServiceList, error) { // TODO: use PageToken to list all not just the first 500 return gce.service.BackendServices.List(gce.projectID).Do() }
[ "func", "(", "gce", "*", "Cloud", ")", "ListBackendServices", "(", ")", "(", "*", "compute", ".", "BackendServiceList", ",", "error", ")", "{", "return", "gce", ".", "service", ".", "BackendServices", ".", "List", "(", "gce", ".", "projectID", ")", ".", "Do", "(", ")", "\n", "}" ]
// ListBackendServices lists all backend services in the project.
[ "ListBackendServices", "lists", "all", "backend", "services", "in", "the", "project", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L1962-L1965
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
GetHealth
func (gce *Cloud) GetHealth(name string, instanceGroupLink string) (*compute.BackendServiceGroupHealth, error) { groupRef := &compute.ResourceGroupReference{Group: instanceGroupLink} return gce.service.BackendServices.GetHealth(gce.projectID, name, groupRef).Do() }
go
func (gce *Cloud) GetHealth(name string, instanceGroupLink string) (*compute.BackendServiceGroupHealth, error) { groupRef := &compute.ResourceGroupReference{Group: instanceGroupLink} return gce.service.BackendServices.GetHealth(gce.projectID, name, groupRef).Do() }
[ "func", "(", "gce", "*", "Cloud", ")", "GetHealth", "(", "name", "string", ",", "instanceGroupLink", "string", ")", "(", "*", "compute", ".", "BackendServiceGroupHealth", ",", "error", ")", "{", "groupRef", ":=", "&", "compute", ".", "ResourceGroupReference", "{", "Group", ":", "instanceGroupLink", "}", "\n", "return", "gce", ".", "service", ".", "BackendServices", ".", "GetHealth", "(", "gce", ".", "projectID", ",", "name", ",", "groupRef", ")", ".", "Do", "(", ")", "\n", "}" ]
// GetHealth returns the health of the BackendService identified by the given // name, in the given instanceGroup. The instanceGroupLink is the fully // qualified self link of an instance group.
[ "GetHealth", "returns", "the", "health", "of", "the", "BackendService", "identified", "by", "the", "given", "name", "in", "the", "given", "instanceGroup", ".", "The", "instanceGroupLink", "is", "the", "fully", "qualified", "self", "link", "of", "an", "instance", "group", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L1970-L1973
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
GetHTTPHealthCheck
func (gce *Cloud) GetHTTPHealthCheck(name string) (*compute.HttpHealthCheck, error) { return gce.service.HttpHealthChecks.Get(gce.projectID, name).Do() }
go
func (gce *Cloud) GetHTTPHealthCheck(name string) (*compute.HttpHealthCheck, error) { return gce.service.HttpHealthChecks.Get(gce.projectID, name).Do() }
[ "func", "(", "gce", "*", "Cloud", ")", "GetHTTPHealthCheck", "(", "name", "string", ")", "(", "*", "compute", ".", "HttpHealthCheck", ",", "error", ")", "{", "return", "gce", ".", "service", ".", "HttpHealthChecks", ".", "Get", "(", "gce", ".", "projectID", ",", "name", ")", ".", "Do", "(", ")", "\n", "}" ]
// Health Checks // GetHTTPHealthCheck returns the given HTTPHealthCheck by name.
[ "Health", "Checks", "GetHTTPHealthCheck", "returns", "the", "given", "HTTPHealthCheck", "by", "name", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L1978-L1980
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
UpdateHTTPHealthCheck
func (gce *Cloud) UpdateHTTPHealthCheck(hc *compute.HttpHealthCheck) error { op, err := gce.service.HttpHealthChecks.Update(gce.projectID, hc.Name, hc).Do() if err != nil { return err } return gce.waitForGlobalOp(op) }
go
func (gce *Cloud) UpdateHTTPHealthCheck(hc *compute.HttpHealthCheck) error { op, err := gce.service.HttpHealthChecks.Update(gce.projectID, hc.Name, hc).Do() if err != nil { return err } return gce.waitForGlobalOp(op) }
[ "func", "(", "gce", "*", "Cloud", ")", "UpdateHTTPHealthCheck", "(", "hc", "*", "compute", ".", "HttpHealthCheck", ")", "error", "{", "op", ",", "err", ":=", "gce", ".", "service", ".", "HttpHealthChecks", ".", "Update", "(", "gce", ".", "projectID", ",", "hc", ".", "Name", ",", "hc", ")", ".", "Do", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "gce", ".", "waitForGlobalOp", "(", "op", ")", "\n", "}" ]
// UpdateHTTPHealthCheck applies the given HTTPHealthCheck as an update.
[ "UpdateHTTPHealthCheck", "applies", "the", "given", "HTTPHealthCheck", "as", "an", "update", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L1983-L1989
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
CreateHTTPHealthCheck
func (gce *Cloud) CreateHTTPHealthCheck(hc *compute.HttpHealthCheck) error { op, err := gce.service.HttpHealthChecks.Insert(gce.projectID, hc).Do() if err != nil { return err } return gce.waitForGlobalOp(op) }
go
func (gce *Cloud) CreateHTTPHealthCheck(hc *compute.HttpHealthCheck) error { op, err := gce.service.HttpHealthChecks.Insert(gce.projectID, hc).Do() if err != nil { return err } return gce.waitForGlobalOp(op) }
[ "func", "(", "gce", "*", "Cloud", ")", "CreateHTTPHealthCheck", "(", "hc", "*", "compute", ".", "HttpHealthCheck", ")", "error", "{", "op", ",", "err", ":=", "gce", ".", "service", ".", "HttpHealthChecks", ".", "Insert", "(", "gce", ".", "projectID", ",", "hc", ")", ".", "Do", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "gce", ".", "waitForGlobalOp", "(", "op", ")", "\n", "}" ]
// CreateHTTPHealthCheck creates the given HTTPHealthCheck.
[ "CreateHTTPHealthCheck", "creates", "the", "given", "HTTPHealthCheck", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L2004-L2010
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
ListHTTPHealthChecks
func (gce *Cloud) ListHTTPHealthChecks() (*compute.HttpHealthCheckList, error) { // TODO: use PageToken to list all not just the first 500 return gce.service.HttpHealthChecks.List(gce.projectID).Do() }
go
func (gce *Cloud) ListHTTPHealthChecks() (*compute.HttpHealthCheckList, error) { // TODO: use PageToken to list all not just the first 500 return gce.service.HttpHealthChecks.List(gce.projectID).Do() }
[ "func", "(", "gce", "*", "Cloud", ")", "ListHTTPHealthChecks", "(", ")", "(", "*", "compute", ".", "HttpHealthCheckList", ",", "error", ")", "{", "return", "gce", ".", "service", ".", "HttpHealthChecks", ".", "List", "(", "gce", ".", "projectID", ")", ".", "Do", "(", ")", "\n", "}" ]
// ListHTTPHealthChecks lists all HTTPHealthChecks in the project.
[ "ListHTTPHealthChecks", "lists", "all", "HTTPHealthChecks", "in", "the", "project", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L2013-L2016
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
CreateInstanceGroup
func (gce *Cloud) CreateInstanceGroup(name string, zone string) (*compute.InstanceGroup, error) { op, err := gce.service.InstanceGroups.Insert( gce.projectID, zone, &compute.InstanceGroup{Name: name}).Do() if err != nil { return nil, err } if err = gce.waitForZoneOp(op, zone); err != nil { return nil, err } return gce.GetInstanceGroup(name, zone) }
go
func (gce *Cloud) CreateInstanceGroup(name string, zone string) (*compute.InstanceGroup, error) { op, err := gce.service.InstanceGroups.Insert( gce.projectID, zone, &compute.InstanceGroup{Name: name}).Do() if err != nil { return nil, err } if err = gce.waitForZoneOp(op, zone); err != nil { return nil, err } return gce.GetInstanceGroup(name, zone) }
[ "func", "(", "gce", "*", "Cloud", ")", "CreateInstanceGroup", "(", "name", "string", ",", "zone", "string", ")", "(", "*", "compute", ".", "InstanceGroup", ",", "error", ")", "{", "op", ",", "err", ":=", "gce", ".", "service", ".", "InstanceGroups", ".", "Insert", "(", "gce", ".", "projectID", ",", "zone", ",", "&", "compute", ".", "InstanceGroup", "{", "Name", ":", "name", "}", ")", ".", "Do", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "err", "=", "gce", ".", "waitForZoneOp", "(", "op", ",", "zone", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "gce", ".", "GetInstanceGroup", "(", "name", ",", "zone", ")", "\n", "}" ]
// InstanceGroup Management // CreateInstanceGroup creates an instance group with the given instances. It is the callers responsibility to add named ports.
[ "InstanceGroup", "Management", "CreateInstanceGroup", "creates", "an", "instance", "group", "with", "the", "given", "instances", ".", "It", "is", "the", "callers", "responsibility", "to", "add", "named", "ports", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L2021-L2031
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
RemoveInstancesFromInstanceGroup
func (gce *Cloud) RemoveInstancesFromInstanceGroup(name string, zone string, instanceNames []string) error { if len(instanceNames) == 0 { return nil } instances := []*compute.InstanceReference{} for _, ins := range instanceNames { instanceLink := makeHostURL(gce.projectID, zone, ins) instances = append(instances, &compute.InstanceReference{Instance: instanceLink}) } op, err := gce.service.InstanceGroups.RemoveInstances( gce.projectID, zone, name, &compute.InstanceGroupsRemoveInstancesRequest{ Instances: instances, }).Do() if err != nil { if isHTTPErrorCode(err, http.StatusNotFound) { return nil } return err } return gce.waitForZoneOp(op, zone) }
go
func (gce *Cloud) RemoveInstancesFromInstanceGroup(name string, zone string, instanceNames []string) error { if len(instanceNames) == 0 { return nil } instances := []*compute.InstanceReference{} for _, ins := range instanceNames { instanceLink := makeHostURL(gce.projectID, zone, ins) instances = append(instances, &compute.InstanceReference{Instance: instanceLink}) } op, err := gce.service.InstanceGroups.RemoveInstances( gce.projectID, zone, name, &compute.InstanceGroupsRemoveInstancesRequest{ Instances: instances, }).Do() if err != nil { if isHTTPErrorCode(err, http.StatusNotFound) { return nil } return err } return gce.waitForZoneOp(op, zone) }
[ "func", "(", "gce", "*", "Cloud", ")", "RemoveInstancesFromInstanceGroup", "(", "name", "string", ",", "zone", "string", ",", "instanceNames", "[", "]", "string", ")", "error", "{", "if", "len", "(", "instanceNames", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n", "instances", ":=", "[", "]", "*", "compute", ".", "InstanceReference", "{", "}", "\n", "for", "_", ",", "ins", ":=", "range", "instanceNames", "{", "instanceLink", ":=", "makeHostURL", "(", "gce", ".", "projectID", ",", "zone", ",", "ins", ")", "\n", "instances", "=", "append", "(", "instances", ",", "&", "compute", ".", "InstanceReference", "{", "Instance", ":", "instanceLink", "}", ")", "\n", "}", "\n", "op", ",", "err", ":=", "gce", ".", "service", ".", "InstanceGroups", ".", "RemoveInstances", "(", "gce", ".", "projectID", ",", "zone", ",", "name", ",", "&", "compute", ".", "InstanceGroupsRemoveInstancesRequest", "{", "Instances", ":", "instances", ",", "}", ")", ".", "Do", "(", ")", "\n", "if", "err", "!=", "nil", "{", "if", "isHTTPErrorCode", "(", "err", ",", "http", ".", "StatusNotFound", ")", "{", "return", "nil", "\n", "}", "\n", "return", "err", "\n", "}", "\n", "return", "gce", ".", "waitForZoneOp", "(", "op", ",", "zone", ")", "\n", "}" ]
// RemoveInstancesFromInstanceGroup removes the given instances from the instance group.
[ "RemoveInstancesFromInstanceGroup", "removes", "the", "given", "instances", "from", "the", "instance", "group", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L2080-L2102
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
AddPortToInstanceGroup
func (gce *Cloud) AddPortToInstanceGroup(ig *compute.InstanceGroup, port int64) (*compute.NamedPort, error) { for _, np := range ig.NamedPorts { if np.Port == port { glog.V(3).Infof("Instance group %v already has named port %+v", ig.Name, np) return np, nil } } glog.Infof("Adding port %v to instance group %v with %d ports", port, ig.Name, len(ig.NamedPorts)) namedPort := compute.NamedPort{Name: fmt.Sprintf("port%v", port), Port: port} ig.NamedPorts = append(ig.NamedPorts, &namedPort) // setNamedPorts is a zonal endpoint, meaning we invoke it by re-creating a URL like: // {project}/zones/{zone}/instanceGroups/{instanceGroup}/setNamedPorts, so the "zone" // parameter given to SetNamedPorts must not be the entire zone URL. zoneURLParts := strings.Split(ig.Zone, "/") zone := zoneURLParts[len(zoneURLParts)-1] op, err := gce.service.InstanceGroups.SetNamedPorts( gce.projectID, zone, ig.Name, &compute.InstanceGroupsSetNamedPortsRequest{ NamedPorts: ig.NamedPorts}).Do() if err != nil { return nil, err } if err = gce.waitForZoneOp(op, zone); err != nil { return nil, err } return &namedPort, nil }
go
func (gce *Cloud) AddPortToInstanceGroup(ig *compute.InstanceGroup, port int64) (*compute.NamedPort, error) { for _, np := range ig.NamedPorts { if np.Port == port { glog.V(3).Infof("Instance group %v already has named port %+v", ig.Name, np) return np, nil } } glog.Infof("Adding port %v to instance group %v with %d ports", port, ig.Name, len(ig.NamedPorts)) namedPort := compute.NamedPort{Name: fmt.Sprintf("port%v", port), Port: port} ig.NamedPorts = append(ig.NamedPorts, &namedPort) // setNamedPorts is a zonal endpoint, meaning we invoke it by re-creating a URL like: // {project}/zones/{zone}/instanceGroups/{instanceGroup}/setNamedPorts, so the "zone" // parameter given to SetNamedPorts must not be the entire zone URL. zoneURLParts := strings.Split(ig.Zone, "/") zone := zoneURLParts[len(zoneURLParts)-1] op, err := gce.service.InstanceGroups.SetNamedPorts( gce.projectID, zone, ig.Name, &compute.InstanceGroupsSetNamedPortsRequest{ NamedPorts: ig.NamedPorts}).Do() if err != nil { return nil, err } if err = gce.waitForZoneOp(op, zone); err != nil { return nil, err } return &namedPort, nil }
[ "func", "(", "gce", "*", "Cloud", ")", "AddPortToInstanceGroup", "(", "ig", "*", "compute", ".", "InstanceGroup", ",", "port", "int64", ")", "(", "*", "compute", ".", "NamedPort", ",", "error", ")", "{", "for", "_", ",", "np", ":=", "range", "ig", ".", "NamedPorts", "{", "if", "np", ".", "Port", "==", "port", "{", "glog", ".", "V", "(", "3", ")", ".", "Infof", "(", "\"Instance group %v already has named port %+v\"", ",", "ig", ".", "Name", ",", "np", ")", "\n", "return", "np", ",", "nil", "\n", "}", "\n", "}", "\n", "glog", ".", "Infof", "(", "\"Adding port %v to instance group %v with %d ports\"", ",", "port", ",", "ig", ".", "Name", ",", "len", "(", "ig", ".", "NamedPorts", ")", ")", "\n", "namedPort", ":=", "compute", ".", "NamedPort", "{", "Name", ":", "fmt", ".", "Sprintf", "(", "\"port%v\"", ",", "port", ")", ",", "Port", ":", "port", "}", "\n", "ig", ".", "NamedPorts", "=", "append", "(", "ig", ".", "NamedPorts", ",", "&", "namedPort", ")", "\n", "zoneURLParts", ":=", "strings", ".", "Split", "(", "ig", ".", "Zone", ",", "\"/\"", ")", "\n", "zone", ":=", "zoneURLParts", "[", "len", "(", "zoneURLParts", ")", "-", "1", "]", "\n", "op", ",", "err", ":=", "gce", ".", "service", ".", "InstanceGroups", ".", "SetNamedPorts", "(", "gce", ".", "projectID", ",", "zone", ",", "ig", ".", "Name", ",", "&", "compute", ".", "InstanceGroupsSetNamedPortsRequest", "{", "NamedPorts", ":", "ig", ".", "NamedPorts", "}", ")", ".", "Do", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "err", "=", "gce", ".", "waitForZoneOp", "(", "op", ",", "zone", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "namedPort", ",", "nil", "\n", "}" ]
// AddPortToInstanceGroup adds a port to the given instance group.
[ "AddPortToInstanceGroup", "adds", "a", "port", "to", "the", "given", "instance", "group", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L2105-L2133
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
CurrentNodeName
func (gce *Cloud) CurrentNodeName(hostname string) (types.NodeName, error) { return types.NodeName(hostname), nil }
go
func (gce *Cloud) CurrentNodeName(hostname string) (types.NodeName, error) { return types.NodeName(hostname), nil }
[ "func", "(", "gce", "*", "Cloud", ")", "CurrentNodeName", "(", "hostname", "string", ")", "(", "types", ".", "NodeName", ",", "error", ")", "{", "return", "types", ".", "NodeName", "(", "hostname", ")", ",", "nil", "\n", "}" ]
// CurrentNodeName is an implementation of Instances.CurrentNodeName
[ "CurrentNodeName", "is", "an", "implementation", "of", "Instances", ".", "CurrentNodeName" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L2152-L2154
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
GetAllZones
func (gce *Cloud) GetAllZones() (sets.String, error) { // Fast-path for non-multizone if len(gce.managedZones) == 1 { return sets.NewString(gce.managedZones...), nil } // TODO: Caching, but this is currently only called when we are creating a volume, // which is a relatively infrequent operation, and this is only # zones API calls zones := sets.NewString() // TODO: Parallelize, although O(zones) so not too bad (N <= 3 typically) for _, zone := range gce.managedZones { // We only retrieve one page in each zone - we only care about existence listCall := gce.service.Instances.List(gce.projectID, zone) // No filter: We assume that a zone is either used or unused // We could only consider running nodes (like we do in List above), // but probably if instances are starting we still want to consider them. // I think we should wait until we have a reason to make the // call one way or the other; we generally can't guarantee correct // volume spreading if the set of zones is changing // (and volume spreading is currently only a heuristic). // Long term we want to replace GetAllZones (which primarily supports volume // spreading) with a scheduler policy that is able to see the global state of // volumes and the health of zones. // Just a minimal set of fields - we only care about existence listCall = listCall.Fields("items(name)") res, err := listCall.Do() if err != nil { return nil, err } if len(res.Items) != 0 { zones.Insert(zone) } } return zones, nil }
go
func (gce *Cloud) GetAllZones() (sets.String, error) { // Fast-path for non-multizone if len(gce.managedZones) == 1 { return sets.NewString(gce.managedZones...), nil } // TODO: Caching, but this is currently only called when we are creating a volume, // which is a relatively infrequent operation, and this is only # zones API calls zones := sets.NewString() // TODO: Parallelize, although O(zones) so not too bad (N <= 3 typically) for _, zone := range gce.managedZones { // We only retrieve one page in each zone - we only care about existence listCall := gce.service.Instances.List(gce.projectID, zone) // No filter: We assume that a zone is either used or unused // We could only consider running nodes (like we do in List above), // but probably if instances are starting we still want to consider them. // I think we should wait until we have a reason to make the // call one way or the other; we generally can't guarantee correct // volume spreading if the set of zones is changing // (and volume spreading is currently only a heuristic). // Long term we want to replace GetAllZones (which primarily supports volume // spreading) with a scheduler policy that is able to see the global state of // volumes and the health of zones. // Just a minimal set of fields - we only care about existence listCall = listCall.Fields("items(name)") res, err := listCall.Do() if err != nil { return nil, err } if len(res.Items) != 0 { zones.Insert(zone) } } return zones, nil }
[ "func", "(", "gce", "*", "Cloud", ")", "GetAllZones", "(", ")", "(", "sets", ".", "String", ",", "error", ")", "{", "if", "len", "(", "gce", ".", "managedZones", ")", "==", "1", "{", "return", "sets", ".", "NewString", "(", "gce", ".", "managedZones", "...", ")", ",", "nil", "\n", "}", "\n", "zones", ":=", "sets", ".", "NewString", "(", ")", "\n", "for", "_", ",", "zone", ":=", "range", "gce", ".", "managedZones", "{", "listCall", ":=", "gce", ".", "service", ".", "Instances", ".", "List", "(", "gce", ".", "projectID", ",", "zone", ")", "\n", "listCall", "=", "listCall", ".", "Fields", "(", "\"items(name)\"", ")", "\n", "res", ",", "err", ":=", "listCall", ".", "Do", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "len", "(", "res", ".", "Items", ")", "!=", "0", "{", "zones", ".", "Insert", "(", "zone", ")", "\n", "}", "\n", "}", "\n", "return", "zones", ",", "nil", "\n", "}" ]
// GetAllZones returns all the zones in which nodes are running
[ "GetAllZones", "returns", "all", "the", "zones", "in", "which", "nodes", "are", "running" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L2296-L2335
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
ListRoutes
func (gce *Cloud) ListRoutes(clusterName string) ([]*cloudprovider.Route, error) { var routes []*cloudprovider.Route pageToken := "" page := 0 for ; page == 0 || (pageToken != "" && page < maxPages); page++ { listCall := gce.service.Routes.List(gce.projectID) prefix := truncateClusterName(clusterName) listCall = listCall.Filter("name eq " + prefix + "-.*") if pageToken != "" { listCall = listCall.PageToken(pageToken) } res, err := listCall.Do() if err != nil { glog.Errorf("Error getting routes from GCE: %v", err) return nil, err } pageToken = res.NextPageToken for _, r := range res.Items { if r.Network != gce.networkURL { continue } // Not managed if route description != "k8s-node-route" if r.Description != k8sNodeRouteTag { continue } // Not managed if route name doesn't start with <clusterName> if !strings.HasPrefix(r.Name, prefix) { continue } target := path.Base(r.NextHopInstance) // TODO: Should we lastComponent(target) this? targetNodeName := types.NodeName(target) // NodeName == Instance Name on GCE routes = append(routes, &cloudprovider.Route{Name: r.Name, TargetNode: targetNodeName, DestinationCIDR: r.DestRange}) } } if page >= maxPages { glog.Errorf("ListRoutes exceeded maxPages=%d for Routes.List; truncating.", maxPages) } return routes, nil }
go
func (gce *Cloud) ListRoutes(clusterName string) ([]*cloudprovider.Route, error) { var routes []*cloudprovider.Route pageToken := "" page := 0 for ; page == 0 || (pageToken != "" && page < maxPages); page++ { listCall := gce.service.Routes.List(gce.projectID) prefix := truncateClusterName(clusterName) listCall = listCall.Filter("name eq " + prefix + "-.*") if pageToken != "" { listCall = listCall.PageToken(pageToken) } res, err := listCall.Do() if err != nil { glog.Errorf("Error getting routes from GCE: %v", err) return nil, err } pageToken = res.NextPageToken for _, r := range res.Items { if r.Network != gce.networkURL { continue } // Not managed if route description != "k8s-node-route" if r.Description != k8sNodeRouteTag { continue } // Not managed if route name doesn't start with <clusterName> if !strings.HasPrefix(r.Name, prefix) { continue } target := path.Base(r.NextHopInstance) // TODO: Should we lastComponent(target) this? targetNodeName := types.NodeName(target) // NodeName == Instance Name on GCE routes = append(routes, &cloudprovider.Route{Name: r.Name, TargetNode: targetNodeName, DestinationCIDR: r.DestRange}) } } if page >= maxPages { glog.Errorf("ListRoutes exceeded maxPages=%d for Routes.List; truncating.", maxPages) } return routes, nil }
[ "func", "(", "gce", "*", "Cloud", ")", "ListRoutes", "(", "clusterName", "string", ")", "(", "[", "]", "*", "cloudprovider", ".", "Route", ",", "error", ")", "{", "var", "routes", "[", "]", "*", "cloudprovider", ".", "Route", "\n", "pageToken", ":=", "\"\"", "\n", "page", ":=", "0", "\n", "for", ";", "page", "==", "0", "||", "(", "pageToken", "!=", "\"\"", "&&", "page", "<", "maxPages", ")", ";", "page", "++", "{", "listCall", ":=", "gce", ".", "service", ".", "Routes", ".", "List", "(", "gce", ".", "projectID", ")", "\n", "prefix", ":=", "truncateClusterName", "(", "clusterName", ")", "\n", "listCall", "=", "listCall", ".", "Filter", "(", "\"name eq \"", "+", "prefix", "+", "\"-.*\"", ")", "\n", "if", "pageToken", "!=", "\"\"", "{", "listCall", "=", "listCall", ".", "PageToken", "(", "pageToken", ")", "\n", "}", "\n", "res", ",", "err", ":=", "listCall", ".", "Do", "(", ")", "\n", "if", "err", "!=", "nil", "{", "glog", ".", "Errorf", "(", "\"Error getting routes from GCE: %v\"", ",", "err", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n", "pageToken", "=", "res", ".", "NextPageToken", "\n", "for", "_", ",", "r", ":=", "range", "res", ".", "Items", "{", "if", "r", ".", "Network", "!=", "gce", ".", "networkURL", "{", "continue", "\n", "}", "\n", "if", "r", ".", "Description", "!=", "k8sNodeRouteTag", "{", "continue", "\n", "}", "\n", "if", "!", "strings", ".", "HasPrefix", "(", "r", ".", "Name", ",", "prefix", ")", "{", "continue", "\n", "}", "\n", "target", ":=", "path", ".", "Base", "(", "r", ".", "NextHopInstance", ")", "\n", "targetNodeName", ":=", "types", ".", "NodeName", "(", "target", ")", "\n", "routes", "=", "append", "(", "routes", ",", "&", "cloudprovider", ".", "Route", "{", "Name", ":", "r", ".", "Name", ",", "TargetNode", ":", "targetNodeName", ",", "DestinationCIDR", ":", "r", ".", "DestRange", "}", ")", "\n", "}", "\n", "}", "\n", "if", "page", ">=", "maxPages", "{", "glog", ".", "Errorf", "(", "\"ListRoutes exceeded maxPages=%d for Routes.List; truncating.\"", ",", "maxPages", ")", "\n", "}", "\n", "return", "routes", ",", "nil", "\n", "}" ]
// ListRoutes lists routes
[ "ListRoutes", "lists", "routes" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L2345-L2386
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
GetZone
func (gce *Cloud) GetZone() (cloudprovider.Zone, error) { return cloudprovider.Zone{ FailureDomain: gce.localZone, Region: gce.region, }, nil }
go
func (gce *Cloud) GetZone() (cloudprovider.Zone, error) { return cloudprovider.Zone{ FailureDomain: gce.localZone, Region: gce.region, }, nil }
[ "func", "(", "gce", "*", "Cloud", ")", "GetZone", "(", ")", "(", "cloudprovider", ".", "Zone", ",", "error", ")", "{", "return", "cloudprovider", ".", "Zone", "{", "FailureDomain", ":", "gce", ".", "localZone", ",", "Region", ":", "gce", ".", "region", ",", "}", ",", "nil", "\n", "}" ]
// GetZone gets a zone
[ "GetZone", "gets", "a", "zone" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L2429-L2434
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
DeleteDisk
func (gce *Cloud) DeleteDisk(diskToDelete string) error { err := gce.doDeleteDisk(diskToDelete) if isGCEError(err, "resourceInUseByAnotherResource") { return volume.NewDeletedVolumeInUseError(err.Error()) } if err == cloudprovider.ErrDiskNotFound { return nil } return err }
go
func (gce *Cloud) DeleteDisk(diskToDelete string) error { err := gce.doDeleteDisk(diskToDelete) if isGCEError(err, "resourceInUseByAnotherResource") { return volume.NewDeletedVolumeInUseError(err.Error()) } if err == cloudprovider.ErrDiskNotFound { return nil } return err }
[ "func", "(", "gce", "*", "Cloud", ")", "DeleteDisk", "(", "diskToDelete", "string", ")", "error", "{", "err", ":=", "gce", ".", "doDeleteDisk", "(", "diskToDelete", ")", "\n", "if", "isGCEError", "(", "err", ",", "\"resourceInUseByAnotherResource\"", ")", "{", "return", "volume", ".", "NewDeletedVolumeInUseError", "(", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n", "if", "err", "==", "cloudprovider", ".", "ErrDiskNotFound", "{", "return", "nil", "\n", "}", "\n", "return", "err", "\n", "}" ]
// DeleteDisk deletes a disk
[ "DeleteDisk", "deletes", "a", "disk" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L2518-L2528
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
AttachDisk
func (gce *Cloud) AttachDisk(diskName string, nodeName types.NodeName, readOnly bool) error { instanceName := mapNodeNameToInstanceName(nodeName) instance, err := gce.getInstanceByName(instanceName) if err != nil { return fmt.Errorf("error getting instance %q", instanceName) } disk, err := gce.getDiskByName(diskName, instance.Zone) if err != nil { return err } readWrite := "READ_WRITE" if readOnly { readWrite = "READ_ONLY" } attachedDisk := gce.convertDiskToAttachedDisk(disk, readWrite) attachOp, err := gce.service.Instances.AttachDisk(gce.projectID, disk.Zone, instance.Name, attachedDisk).Do() if err != nil { return err } return gce.waitForZoneOp(attachOp, disk.Zone) }
go
func (gce *Cloud) AttachDisk(diskName string, nodeName types.NodeName, readOnly bool) error { instanceName := mapNodeNameToInstanceName(nodeName) instance, err := gce.getInstanceByName(instanceName) if err != nil { return fmt.Errorf("error getting instance %q", instanceName) } disk, err := gce.getDiskByName(diskName, instance.Zone) if err != nil { return err } readWrite := "READ_WRITE" if readOnly { readWrite = "READ_ONLY" } attachedDisk := gce.convertDiskToAttachedDisk(disk, readWrite) attachOp, err := gce.service.Instances.AttachDisk(gce.projectID, disk.Zone, instance.Name, attachedDisk).Do() if err != nil { return err } return gce.waitForZoneOp(attachOp, disk.Zone) }
[ "func", "(", "gce", "*", "Cloud", ")", "AttachDisk", "(", "diskName", "string", ",", "nodeName", "types", ".", "NodeName", ",", "readOnly", "bool", ")", "error", "{", "instanceName", ":=", "mapNodeNameToInstanceName", "(", "nodeName", ")", "\n", "instance", ",", "err", ":=", "gce", ".", "getInstanceByName", "(", "instanceName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"error getting instance %q\"", ",", "instanceName", ")", "\n", "}", "\n", "disk", ",", "err", ":=", "gce", ".", "getDiskByName", "(", "diskName", ",", "instance", ".", "Zone", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "readWrite", ":=", "\"READ_WRITE\"", "\n", "if", "readOnly", "{", "readWrite", "=", "\"READ_ONLY\"", "\n", "}", "\n", "attachedDisk", ":=", "gce", ".", "convertDiskToAttachedDisk", "(", "disk", ",", "readWrite", ")", "\n", "attachOp", ",", "err", ":=", "gce", ".", "service", ".", "Instances", ".", "AttachDisk", "(", "gce", ".", "projectID", ",", "disk", ".", "Zone", ",", "instance", ".", "Name", ",", "attachedDisk", ")", ".", "Do", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "gce", ".", "waitForZoneOp", "(", "attachOp", ",", "disk", ".", "Zone", ")", "\n", "}" ]
// AttachDisk attaches a disk
[ "AttachDisk", "attaches", "a", "disk" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L2594-L2616
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
DetachDisk
func (gce *Cloud) DetachDisk(devicePath string, nodeName types.NodeName) error { instanceName := mapNodeNameToInstanceName(nodeName) inst, err := gce.getInstanceByName(instanceName) if err != nil { if err == cloudprovider.ErrInstanceNotFound { // If instance no longer exists, safe to assume volume is not attached. glog.Warningf( "Instance %q does not exist. DetachDisk will assume PD %q is not attached to it.", instanceName, devicePath) return nil } return fmt.Errorf("error getting instance %q", instanceName) } detachOp, err := gce.service.Instances.DetachDisk(gce.projectID, inst.Zone, inst.Name, devicePath).Do() if err != nil { return err } return gce.waitForZoneOp(detachOp, inst.Zone) }
go
func (gce *Cloud) DetachDisk(devicePath string, nodeName types.NodeName) error { instanceName := mapNodeNameToInstanceName(nodeName) inst, err := gce.getInstanceByName(instanceName) if err != nil { if err == cloudprovider.ErrInstanceNotFound { // If instance no longer exists, safe to assume volume is not attached. glog.Warningf( "Instance %q does not exist. DetachDisk will assume PD %q is not attached to it.", instanceName, devicePath) return nil } return fmt.Errorf("error getting instance %q", instanceName) } detachOp, err := gce.service.Instances.DetachDisk(gce.projectID, inst.Zone, inst.Name, devicePath).Do() if err != nil { return err } return gce.waitForZoneOp(detachOp, inst.Zone) }
[ "func", "(", "gce", "*", "Cloud", ")", "DetachDisk", "(", "devicePath", "string", ",", "nodeName", "types", ".", "NodeName", ")", "error", "{", "instanceName", ":=", "mapNodeNameToInstanceName", "(", "nodeName", ")", "\n", "inst", ",", "err", ":=", "gce", ".", "getInstanceByName", "(", "instanceName", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "==", "cloudprovider", ".", "ErrInstanceNotFound", "{", "glog", ".", "Warningf", "(", "\"Instance %q does not exist. DetachDisk will assume PD %q is not attached to it.\"", ",", "instanceName", ",", "devicePath", ")", "\n", "return", "nil", "\n", "}", "\n", "return", "fmt", ".", "Errorf", "(", "\"error getting instance %q\"", ",", "instanceName", ")", "\n", "}", "\n", "detachOp", ",", "err", ":=", "gce", ".", "service", ".", "Instances", ".", "DetachDisk", "(", "gce", ".", "projectID", ",", "inst", ".", "Zone", ",", "inst", ".", "Name", ",", "devicePath", ")", ".", "Do", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "gce", ".", "waitForZoneOp", "(", "detachOp", ",", "inst", ".", "Zone", ")", "\n", "}" ]
// DetachDisk detaches a disk
[ "DetachDisk", "detaches", "a", "disk" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L2619-L2641
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
DiskIsAttached
func (gce *Cloud) DiskIsAttached(diskName string, nodeName types.NodeName) (bool, error) { instanceName := mapNodeNameToInstanceName(nodeName) instance, err := gce.getInstanceByName(instanceName) if err != nil { if err == cloudprovider.ErrInstanceNotFound { // If instance no longer exists, safe to assume volume is not attached. glog.Warningf( "Instance %q does not exist. DiskIsAttached will assume PD %q is not attached to it.", instanceName, diskName) return false, nil } return false, err } for _, disk := range instance.Disks { if disk.DeviceName == diskName { // Disk is still attached to node return true, nil } } return false, nil }
go
func (gce *Cloud) DiskIsAttached(diskName string, nodeName types.NodeName) (bool, error) { instanceName := mapNodeNameToInstanceName(nodeName) instance, err := gce.getInstanceByName(instanceName) if err != nil { if err == cloudprovider.ErrInstanceNotFound { // If instance no longer exists, safe to assume volume is not attached. glog.Warningf( "Instance %q does not exist. DiskIsAttached will assume PD %q is not attached to it.", instanceName, diskName) return false, nil } return false, err } for _, disk := range instance.Disks { if disk.DeviceName == diskName { // Disk is still attached to node return true, nil } } return false, nil }
[ "func", "(", "gce", "*", "Cloud", ")", "DiskIsAttached", "(", "diskName", "string", ",", "nodeName", "types", ".", "NodeName", ")", "(", "bool", ",", "error", ")", "{", "instanceName", ":=", "mapNodeNameToInstanceName", "(", "nodeName", ")", "\n", "instance", ",", "err", ":=", "gce", ".", "getInstanceByName", "(", "instanceName", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "==", "cloudprovider", ".", "ErrInstanceNotFound", "{", "glog", ".", "Warningf", "(", "\"Instance %q does not exist. DiskIsAttached will assume PD %q is not attached to it.\"", ",", "instanceName", ",", "diskName", ")", "\n", "return", "false", ",", "nil", "\n", "}", "\n", "return", "false", ",", "err", "\n", "}", "\n", "for", "_", ",", "disk", ":=", "range", "instance", ".", "Disks", "{", "if", "disk", ".", "DeviceName", "==", "diskName", "{", "return", "true", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "false", ",", "nil", "\n", "}" ]
// DiskIsAttached checks if disk is attached
[ "DiskIsAttached", "checks", "if", "disk", "is", "attached" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L2644-L2668
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
getDiskByNameUnknownZone
func (gce *Cloud) getDiskByNameUnknownZone(diskName string) (*gceDisk, error) { // Note: this is the gotcha right now with GCE PD support: // disk names are not unique per-region. // (I can create two volumes with name "myvol" in e.g. us-central1-b & us-central1-f) // For now, this is simply undefined behaviour. // // In future, we will have to require users to qualify their disk // "us-central1-a/mydisk". We could do this for them as part of // admission control, but that might be a little weird (values changing // on create) var found *gceDisk for _, zone := range gce.managedZones { disk, err := gce.findDiskByName(diskName, zone) if err != nil { return nil, err } // findDiskByName returns (nil,nil) if the disk doesn't exist, so we can't // assume that a disk was found unless disk is non-nil. if disk == nil { continue } if found != nil { return nil, fmt.Errorf("GCE persistent disk name was found in multiple zones: %q", diskName) } found = disk } if found != nil { return found, nil } glog.Warningf("GCE persistent disk %q not found in managed zones (%s)", diskName, strings.Join(gce.managedZones, ",")) return nil, cloudprovider.ErrDiskNotFound }
go
func (gce *Cloud) getDiskByNameUnknownZone(diskName string) (*gceDisk, error) { // Note: this is the gotcha right now with GCE PD support: // disk names are not unique per-region. // (I can create two volumes with name "myvol" in e.g. us-central1-b & us-central1-f) // For now, this is simply undefined behaviour. // // In future, we will have to require users to qualify their disk // "us-central1-a/mydisk". We could do this for them as part of // admission control, but that might be a little weird (values changing // on create) var found *gceDisk for _, zone := range gce.managedZones { disk, err := gce.findDiskByName(diskName, zone) if err != nil { return nil, err } // findDiskByName returns (nil,nil) if the disk doesn't exist, so we can't // assume that a disk was found unless disk is non-nil. if disk == nil { continue } if found != nil { return nil, fmt.Errorf("GCE persistent disk name was found in multiple zones: %q", diskName) } found = disk } if found != nil { return found, nil } glog.Warningf("GCE persistent disk %q not found in managed zones (%s)", diskName, strings.Join(gce.managedZones, ",")) return nil, cloudprovider.ErrDiskNotFound }
[ "func", "(", "gce", "*", "Cloud", ")", "getDiskByNameUnknownZone", "(", "diskName", "string", ")", "(", "*", "gceDisk", ",", "error", ")", "{", "var", "found", "*", "gceDisk", "\n", "for", "_", ",", "zone", ":=", "range", "gce", ".", "managedZones", "{", "disk", ",", "err", ":=", "gce", ".", "findDiskByName", "(", "diskName", ",", "zone", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "disk", "==", "nil", "{", "continue", "\n", "}", "\n", "if", "found", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"GCE persistent disk name was found in multiple zones: %q\"", ",", "diskName", ")", "\n", "}", "\n", "found", "=", "disk", "\n", "}", "\n", "if", "found", "!=", "nil", "{", "return", "found", ",", "nil", "\n", "}", "\n", "glog", ".", "Warningf", "(", "\"GCE persistent disk %q not found in managed zones (%s)\"", ",", "diskName", ",", "strings", ".", "Join", "(", "gce", ".", "managedZones", ",", "\",\"", ")", ")", "\n", "return", "nil", ",", "cloudprovider", ".", "ErrDiskNotFound", "\n", "}" ]
// Scans all managed zones to return the GCE PD // Prefer getDiskByName, if the zone can be established // Return cloudprovider.ErrDiskNotFound if the given disk cannot be found in any zone
[ "Scans", "all", "managed", "zones", "to", "return", "the", "GCE", "PD", "Prefer", "getDiskByName", "if", "the", "zone", "can", "be", "established", "Return", "cloudprovider", ".", "ErrDiskNotFound", "if", "the", "given", "disk", "cannot", "be", "found", "in", "any", "zone" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L2733-L2765
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
convertDiskToAttachedDisk
func (gce *Cloud) convertDiskToAttachedDisk(disk *gceDisk, readWrite string) *compute.AttachedDisk { return &compute.AttachedDisk{ DeviceName: disk.Name, Kind: disk.Kind, Mode: readWrite, Source: "https://" + path.Join("www.googleapis.com/compute/v1/projects/", gce.projectID, "zones", disk.Zone, "disks", disk.Name), Type: "PERSISTENT", } }
go
func (gce *Cloud) convertDiskToAttachedDisk(disk *gceDisk, readWrite string) *compute.AttachedDisk { return &compute.AttachedDisk{ DeviceName: disk.Name, Kind: disk.Kind, Mode: readWrite, Source: "https://" + path.Join("www.googleapis.com/compute/v1/projects/", gce.projectID, "zones", disk.Zone, "disks", disk.Name), Type: "PERSISTENT", } }
[ "func", "(", "gce", "*", "Cloud", ")", "convertDiskToAttachedDisk", "(", "disk", "*", "gceDisk", ",", "readWrite", "string", ")", "*", "compute", ".", "AttachedDisk", "{", "return", "&", "compute", ".", "AttachedDisk", "{", "DeviceName", ":", "disk", ".", "Name", ",", "Kind", ":", "disk", ".", "Kind", ",", "Mode", ":", "readWrite", ",", "Source", ":", "\"https://\"", "+", "path", ".", "Join", "(", "\"www.googleapis.com/compute/v1/projects/\"", ",", "gce", ".", "projectID", ",", "\"zones\"", ",", "disk", ".", "Zone", ",", "\"disks\"", ",", "disk", ".", "Name", ")", ",", "Type", ":", "\"PERSISTENT\"", ",", "}", "\n", "}" ]
// Converts a Disk resource to an AttachedDisk resource.
[ "Converts", "a", "Disk", "resource", "to", "an", "AttachedDisk", "resource", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L2780-L2788
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
CreateDiskFromSnapshot
func (gce *Cloud) CreateDiskFromSnapshot(snapshot string, name string, diskType string, zone string, sizeGb int64, tags map[string]string) error { // Do not allow creation of PDs in zones that are not managed. Such PDs // then cannot be deleted by DeleteDisk. isManaged := false for _, managedZone := range gce.managedZones { if zone == managedZone { isManaged = true break } } if !isManaged { return fmt.Errorf("kubernetes does not manage zone %q", zone) } tagsStr, err := gce.encodeDiskTags(tags) if err != nil { return fmt.Errorf("encode disk tag error %v", err) } switch diskType { case DiskTypeSSD, DiskTypeStandard: // noop case "": diskType = diskTypeDefault default: return fmt.Errorf("invalid GCE disk type %q", diskType) } diskTypeURI := fmt.Sprintf(diskTypeURITemplate, gce.projectID, zone, diskType) snapshotName := "global/snapshots/" + snapshot diskToCreate := &compute.Disk{ Name: name, SizeGb: sizeGb, Description: tagsStr, Type: diskTypeURI, SourceSnapshot: snapshotName, } glog.Infof("Create disk from snapshot diskToCreate %+v", diskToCreate) createOp, err := gce.service.Disks.Insert(gce.projectID, zone, diskToCreate).Do() glog.Infof("Create disk from snapshot operation %v, err %v", createOp, err) if err != nil { if isGCEError(err, "alreadyExists") { glog.Warningf("GCE PD %q already exists, reusing", name) return nil } return err } err = gce.waitForZoneOp(createOp, zone) if isGCEError(err, "alreadyExists") { glog.Warningf("GCE PD %q already exists, reusing", name) return nil } return err }
go
func (gce *Cloud) CreateDiskFromSnapshot(snapshot string, name string, diskType string, zone string, sizeGb int64, tags map[string]string) error { // Do not allow creation of PDs in zones that are not managed. Such PDs // then cannot be deleted by DeleteDisk. isManaged := false for _, managedZone := range gce.managedZones { if zone == managedZone { isManaged = true break } } if !isManaged { return fmt.Errorf("kubernetes does not manage zone %q", zone) } tagsStr, err := gce.encodeDiskTags(tags) if err != nil { return fmt.Errorf("encode disk tag error %v", err) } switch diskType { case DiskTypeSSD, DiskTypeStandard: // noop case "": diskType = diskTypeDefault default: return fmt.Errorf("invalid GCE disk type %q", diskType) } diskTypeURI := fmt.Sprintf(diskTypeURITemplate, gce.projectID, zone, diskType) snapshotName := "global/snapshots/" + snapshot diskToCreate := &compute.Disk{ Name: name, SizeGb: sizeGb, Description: tagsStr, Type: diskTypeURI, SourceSnapshot: snapshotName, } glog.Infof("Create disk from snapshot diskToCreate %+v", diskToCreate) createOp, err := gce.service.Disks.Insert(gce.projectID, zone, diskToCreate).Do() glog.Infof("Create disk from snapshot operation %v, err %v", createOp, err) if err != nil { if isGCEError(err, "alreadyExists") { glog.Warningf("GCE PD %q already exists, reusing", name) return nil } return err } err = gce.waitForZoneOp(createOp, zone) if isGCEError(err, "alreadyExists") { glog.Warningf("GCE PD %q already exists, reusing", name) return nil } return err }
[ "func", "(", "gce", "*", "Cloud", ")", "CreateDiskFromSnapshot", "(", "snapshot", "string", ",", "name", "string", ",", "diskType", "string", ",", "zone", "string", ",", "sizeGb", "int64", ",", "tags", "map", "[", "string", "]", "string", ")", "error", "{", "isManaged", ":=", "false", "\n", "for", "_", ",", "managedZone", ":=", "range", "gce", ".", "managedZones", "{", "if", "zone", "==", "managedZone", "{", "isManaged", "=", "true", "\n", "break", "\n", "}", "\n", "}", "\n", "if", "!", "isManaged", "{", "return", "fmt", ".", "Errorf", "(", "\"kubernetes does not manage zone %q\"", ",", "zone", ")", "\n", "}", "\n", "tagsStr", ",", "err", ":=", "gce", ".", "encodeDiskTags", "(", "tags", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"encode disk tag error %v\"", ",", "err", ")", "\n", "}", "\n", "switch", "diskType", "{", "case", "DiskTypeSSD", ",", "DiskTypeStandard", ":", "case", "\"\"", ":", "diskType", "=", "diskTypeDefault", "\n", "default", ":", "return", "fmt", ".", "Errorf", "(", "\"invalid GCE disk type %q\"", ",", "diskType", ")", "\n", "}", "\n", "diskTypeURI", ":=", "fmt", ".", "Sprintf", "(", "diskTypeURITemplate", ",", "gce", ".", "projectID", ",", "zone", ",", "diskType", ")", "\n", "snapshotName", ":=", "\"global/snapshots/\"", "+", "snapshot", "\n", "diskToCreate", ":=", "&", "compute", ".", "Disk", "{", "Name", ":", "name", ",", "SizeGb", ":", "sizeGb", ",", "Description", ":", "tagsStr", ",", "Type", ":", "diskTypeURI", ",", "SourceSnapshot", ":", "snapshotName", ",", "}", "\n", "glog", ".", "Infof", "(", "\"Create disk from snapshot diskToCreate %+v\"", ",", "diskToCreate", ")", "\n", "createOp", ",", "err", ":=", "gce", ".", "service", ".", "Disks", ".", "Insert", "(", "gce", ".", "projectID", ",", "zone", ",", "diskToCreate", ")", ".", "Do", "(", ")", "\n", "glog", ".", "Infof", "(", "\"Create disk from snapshot operation %v, err %v\"", ",", "createOp", ",", "err", ")", "\n", "if", "err", "!=", "nil", "{", "if", "isGCEError", "(", "err", ",", "\"alreadyExists\"", ")", "{", "glog", ".", "Warningf", "(", "\"GCE PD %q already exists, reusing\"", ",", "name", ")", "\n", "return", "nil", "\n", "}", "\n", "return", "err", "\n", "}", "\n", "err", "=", "gce", ".", "waitForZoneOp", "(", "createOp", ",", "zone", ")", "\n", "if", "isGCEError", "(", "err", ",", "\"alreadyExists\"", ")", "{", "glog", ".", "Warningf", "(", "\"GCE PD %q already exists, reusing\"", ",", "name", ")", "\n", "return", "nil", "\n", "}", "\n", "return", "err", "\n", "}" ]
// CreateDiskFromSnapshot create a disk from snapshot
[ "CreateDiskFromSnapshot", "create", "a", "disk", "from", "snapshot" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L2797-L2853
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
DescribeSnapshot
func (gce *Cloud) DescribeSnapshot(snapshotToGet string) (status string, isCompleted bool, err error) { snapshot, err := gce.getSnapshotByName(snapshotToGet) if err != nil { return "", false, err } //no snapshot is found if snapshot == nil { return "", false, fmt.Errorf("snapshot %s is not found", snapshotToGet) } if snapshot.Status == "READY" { return snapshot.Status, true, nil } return snapshot.Status, false, nil }
go
func (gce *Cloud) DescribeSnapshot(snapshotToGet string) (status string, isCompleted bool, err error) { snapshot, err := gce.getSnapshotByName(snapshotToGet) if err != nil { return "", false, err } //no snapshot is found if snapshot == nil { return "", false, fmt.Errorf("snapshot %s is not found", snapshotToGet) } if snapshot.Status == "READY" { return snapshot.Status, true, nil } return snapshot.Status, false, nil }
[ "func", "(", "gce", "*", "Cloud", ")", "DescribeSnapshot", "(", "snapshotToGet", "string", ")", "(", "status", "string", ",", "isCompleted", "bool", ",", "err", "error", ")", "{", "snapshot", ",", "err", ":=", "gce", ".", "getSnapshotByName", "(", "snapshotToGet", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "false", ",", "err", "\n", "}", "\n", "if", "snapshot", "==", "nil", "{", "return", "\"\"", ",", "false", ",", "fmt", ".", "Errorf", "(", "\"snapshot %s is not found\"", ",", "snapshotToGet", ")", "\n", "}", "\n", "if", "snapshot", ".", "Status", "==", "\"READY\"", "{", "return", "snapshot", ".", "Status", ",", "true", ",", "nil", "\n", "}", "\n", "return", "snapshot", ".", "Status", ",", "false", ",", "nil", "\n", "}" ]
// DescribeSnapshot checks the status of a snapshot
[ "DescribeSnapshot", "checks", "the", "status", "of", "a", "snapshot" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L2856-L2869
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
FindSnapshot
func (gce *Cloud) FindSnapshot(tags map[string]string) ([]string, []string, error) { var snapshotIDs, statuses []string return snapshotIDs, statuses, nil }
go
func (gce *Cloud) FindSnapshot(tags map[string]string) ([]string, []string, error) { var snapshotIDs, statuses []string return snapshotIDs, statuses, nil }
[ "func", "(", "gce", "*", "Cloud", ")", "FindSnapshot", "(", "tags", "map", "[", "string", "]", "string", ")", "(", "[", "]", "string", ",", "[", "]", "string", ",", "error", ")", "{", "var", "snapshotIDs", ",", "statuses", "[", "]", "string", "\n", "return", "snapshotIDs", ",", "statuses", ",", "nil", "\n", "}" ]
// FindSnapshot returns the found snapshots
[ "FindSnapshot", "returns", "the", "found", "snapshots" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L2872-L2875
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
DeleteSnapshot
func (gce *Cloud) DeleteSnapshot(snapshotToDelete string) error { snapshot, err := gce.getSnapshotByName(snapshotToDelete) if err != nil { return err } //no snapshot is found if snapshot == nil { return nil } deleteOp, err := gce.service.Snapshots.Delete(gce.projectID, snapshotToDelete).Do() if err != nil { return err } return gce.waitForGlobalOp(deleteOp) }
go
func (gce *Cloud) DeleteSnapshot(snapshotToDelete string) error { snapshot, err := gce.getSnapshotByName(snapshotToDelete) if err != nil { return err } //no snapshot is found if snapshot == nil { return nil } deleteOp, err := gce.service.Snapshots.Delete(gce.projectID, snapshotToDelete).Do() if err != nil { return err } return gce.waitForGlobalOp(deleteOp) }
[ "func", "(", "gce", "*", "Cloud", ")", "DeleteSnapshot", "(", "snapshotToDelete", "string", ")", "error", "{", "snapshot", ",", "err", ":=", "gce", ".", "getSnapshotByName", "(", "snapshotToDelete", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "snapshot", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "deleteOp", ",", "err", ":=", "gce", ".", "service", ".", "Snapshots", ".", "Delete", "(", "gce", ".", "projectID", ",", "snapshotToDelete", ")", ".", "Do", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "gce", ".", "waitForGlobalOp", "(", "deleteOp", ")", "\n", "}" ]
// DeleteSnapshot deletes a snapshot
[ "DeleteSnapshot", "deletes", "a", "snapshot" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L2878-L2894
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
CreateSnapshot
func (gce *Cloud) CreateSnapshot(diskName string, zone string, snapshotName string, tags map[string]string) error { isManaged := false for _, managedZone := range gce.managedZones { if zone == managedZone { isManaged = true break } } if !isManaged { return fmt.Errorf("kubernetes does not manage zone %q", zone) } tagsStr, err := gce.encodeDiskTags(tags) if err != nil { glog.Infof("CreateSnapshot err %v", err) return err } snapshotToCreate := &compute.Snapshot{ Name: snapshotName, Description: tagsStr, } glog.V(4).Infof("Create snapshot project %s, zone %s, diskName %s, snapshotToCreate %+v", gce.projectID, zone, diskName, snapshotToCreate) createOp, err := gce.service.Disks.CreateSnapshot(gce.projectID, zone, diskName, snapshotToCreate).Do() glog.V(4).Infof("Create snapshot operation %v", createOp) return err }
go
func (gce *Cloud) CreateSnapshot(diskName string, zone string, snapshotName string, tags map[string]string) error { isManaged := false for _, managedZone := range gce.managedZones { if zone == managedZone { isManaged = true break } } if !isManaged { return fmt.Errorf("kubernetes does not manage zone %q", zone) } tagsStr, err := gce.encodeDiskTags(tags) if err != nil { glog.Infof("CreateSnapshot err %v", err) return err } snapshotToCreate := &compute.Snapshot{ Name: snapshotName, Description: tagsStr, } glog.V(4).Infof("Create snapshot project %s, zone %s, diskName %s, snapshotToCreate %+v", gce.projectID, zone, diskName, snapshotToCreate) createOp, err := gce.service.Disks.CreateSnapshot(gce.projectID, zone, diskName, snapshotToCreate).Do() glog.V(4).Infof("Create snapshot operation %v", createOp) return err }
[ "func", "(", "gce", "*", "Cloud", ")", "CreateSnapshot", "(", "diskName", "string", ",", "zone", "string", ",", "snapshotName", "string", ",", "tags", "map", "[", "string", "]", "string", ")", "error", "{", "isManaged", ":=", "false", "\n", "for", "_", ",", "managedZone", ":=", "range", "gce", ".", "managedZones", "{", "if", "zone", "==", "managedZone", "{", "isManaged", "=", "true", "\n", "break", "\n", "}", "\n", "}", "\n", "if", "!", "isManaged", "{", "return", "fmt", ".", "Errorf", "(", "\"kubernetes does not manage zone %q\"", ",", "zone", ")", "\n", "}", "\n", "tagsStr", ",", "err", ":=", "gce", ".", "encodeDiskTags", "(", "tags", ")", "\n", "if", "err", "!=", "nil", "{", "glog", ".", "Infof", "(", "\"CreateSnapshot err %v\"", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n", "snapshotToCreate", ":=", "&", "compute", ".", "Snapshot", "{", "Name", ":", "snapshotName", ",", "Description", ":", "tagsStr", ",", "}", "\n", "glog", ".", "V", "(", "4", ")", ".", "Infof", "(", "\"Create snapshot project %s, zone %s, diskName %s, snapshotToCreate %+v\"", ",", "gce", ".", "projectID", ",", "zone", ",", "diskName", ",", "snapshotToCreate", ")", "\n", "createOp", ",", "err", ":=", "gce", ".", "service", ".", "Disks", ".", "CreateSnapshot", "(", "gce", ".", "projectID", ",", "zone", ",", "diskName", ",", "snapshotToCreate", ")", ".", "Do", "(", ")", "\n", "glog", ".", "V", "(", "4", ")", ".", "Infof", "(", "\"Create snapshot operation %v\"", ",", "createOp", ")", "\n", "return", "err", "\n", "}" ]
// CreateSnapshot creates a snapshot
[ "CreateSnapshot", "creates", "a", "snapshot" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L2913-L2938
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
ListClusters
func (gce *Cloud) ListClusters() ([]string, error) { allClusters := []string{} for _, zone := range gce.managedZones { clusters, err := gce.listClustersInZone(zone) if err != nil { return nil, err } // TODO: Scoping? Do we need to qualify the cluster name? allClusters = append(allClusters, clusters...) } return allClusters, nil }
go
func (gce *Cloud) ListClusters() ([]string, error) { allClusters := []string{} for _, zone := range gce.managedZones { clusters, err := gce.listClustersInZone(zone) if err != nil { return nil, err } // TODO: Scoping? Do we need to qualify the cluster name? allClusters = append(allClusters, clusters...) } return allClusters, nil }
[ "func", "(", "gce", "*", "Cloud", ")", "ListClusters", "(", ")", "(", "[", "]", "string", ",", "error", ")", "{", "allClusters", ":=", "[", "]", "string", "{", "}", "\n", "for", "_", ",", "zone", ":=", "range", "gce", ".", "managedZones", "{", "clusters", ",", "err", ":=", "gce", ".", "listClustersInZone", "(", "zone", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "allClusters", "=", "append", "(", "allClusters", ",", "clusters", "...", ")", "\n", "}", "\n", "return", "allClusters", ",", "nil", "\n", "}" ]
// ListClusters lists clusters
[ "ListClusters", "lists", "clusters" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L2954-L2967
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
getInstancesByNames
func (gce *Cloud) getInstancesByNames(names []string) ([]*gceInstance, error) { instances := make(map[string]*gceInstance) remaining := len(names) nodeInstancePrefix := gce.nodeInstancePrefix for _, name := range names { name = canonicalizeInstanceName(name) if !strings.HasPrefix(name, gce.nodeInstancePrefix) { glog.Warningf("instance '%s' does not conform to prefix '%s', removing filter", name, gce.nodeInstancePrefix) nodeInstancePrefix = "" } instances[name] = nil } for _, zone := range gce.managedZones { if remaining == 0 { break } pageToken := "" page := 0 for ; page == 0 || (pageToken != "" && page < maxPages); page++ { listCall := gce.service.Instances.List(gce.projectID, zone) if nodeInstancePrefix != "" { // Add the filter for hosts listCall = listCall.Filter("name eq " + nodeInstancePrefix + ".*") } // TODO(zmerlynn): Internal bug 29524655 // listCall = listCall.Fields("items(name,id,disks,machineType)") if pageToken != "" { listCall.PageToken(pageToken) } res, err := listCall.Do() if err != nil { return nil, err } pageToken = res.NextPageToken for _, i := range res.Items { name := i.Name if _, ok := instances[name]; !ok { continue } instance := &gceInstance{ Zone: zone, Name: name, ID: i.Id, Disks: i.Disks, Type: lastComponent(i.MachineType), } instances[name] = instance remaining-- } } if page >= maxPages { glog.Errorf("getInstancesByNames exceeded maxPages=%d for Instances.List: truncating.", maxPages) } } instanceArray := make([]*gceInstance, len(names)) for i, name := range names { name = canonicalizeInstanceName(name) instance := instances[name] if instance == nil { glog.Errorf("Failed to retrieve instance: %q", name) return nil, cloudprovider.ErrInstanceNotFound } instanceArray[i] = instances[name] } return instanceArray, nil }
go
func (gce *Cloud) getInstancesByNames(names []string) ([]*gceInstance, error) { instances := make(map[string]*gceInstance) remaining := len(names) nodeInstancePrefix := gce.nodeInstancePrefix for _, name := range names { name = canonicalizeInstanceName(name) if !strings.HasPrefix(name, gce.nodeInstancePrefix) { glog.Warningf("instance '%s' does not conform to prefix '%s', removing filter", name, gce.nodeInstancePrefix) nodeInstancePrefix = "" } instances[name] = nil } for _, zone := range gce.managedZones { if remaining == 0 { break } pageToken := "" page := 0 for ; page == 0 || (pageToken != "" && page < maxPages); page++ { listCall := gce.service.Instances.List(gce.projectID, zone) if nodeInstancePrefix != "" { // Add the filter for hosts listCall = listCall.Filter("name eq " + nodeInstancePrefix + ".*") } // TODO(zmerlynn): Internal bug 29524655 // listCall = listCall.Fields("items(name,id,disks,machineType)") if pageToken != "" { listCall.PageToken(pageToken) } res, err := listCall.Do() if err != nil { return nil, err } pageToken = res.NextPageToken for _, i := range res.Items { name := i.Name if _, ok := instances[name]; !ok { continue } instance := &gceInstance{ Zone: zone, Name: name, ID: i.Id, Disks: i.Disks, Type: lastComponent(i.MachineType), } instances[name] = instance remaining-- } } if page >= maxPages { glog.Errorf("getInstancesByNames exceeded maxPages=%d for Instances.List: truncating.", maxPages) } } instanceArray := make([]*gceInstance, len(names)) for i, name := range names { name = canonicalizeInstanceName(name) instance := instances[name] if instance == nil { glog.Errorf("Failed to retrieve instance: %q", name) return nil, cloudprovider.ErrInstanceNotFound } instanceArray[i] = instances[name] } return instanceArray, nil }
[ "func", "(", "gce", "*", "Cloud", ")", "getInstancesByNames", "(", "names", "[", "]", "string", ")", "(", "[", "]", "*", "gceInstance", ",", "error", ")", "{", "instances", ":=", "make", "(", "map", "[", "string", "]", "*", "gceInstance", ")", "\n", "remaining", ":=", "len", "(", "names", ")", "\n", "nodeInstancePrefix", ":=", "gce", ".", "nodeInstancePrefix", "\n", "for", "_", ",", "name", ":=", "range", "names", "{", "name", "=", "canonicalizeInstanceName", "(", "name", ")", "\n", "if", "!", "strings", ".", "HasPrefix", "(", "name", ",", "gce", ".", "nodeInstancePrefix", ")", "{", "glog", ".", "Warningf", "(", "\"instance '%s' does not conform to prefix '%s', removing filter\"", ",", "name", ",", "gce", ".", "nodeInstancePrefix", ")", "\n", "nodeInstancePrefix", "=", "\"\"", "\n", "}", "\n", "instances", "[", "name", "]", "=", "nil", "\n", "}", "\n", "for", "_", ",", "zone", ":=", "range", "gce", ".", "managedZones", "{", "if", "remaining", "==", "0", "{", "break", "\n", "}", "\n", "pageToken", ":=", "\"\"", "\n", "page", ":=", "0", "\n", "for", ";", "page", "==", "0", "||", "(", "pageToken", "!=", "\"\"", "&&", "page", "<", "maxPages", ")", ";", "page", "++", "{", "listCall", ":=", "gce", ".", "service", ".", "Instances", ".", "List", "(", "gce", ".", "projectID", ",", "zone", ")", "\n", "if", "nodeInstancePrefix", "!=", "\"\"", "{", "listCall", "=", "listCall", ".", "Filter", "(", "\"name eq \"", "+", "nodeInstancePrefix", "+", "\".*\"", ")", "\n", "}", "\n", "if", "pageToken", "!=", "\"\"", "{", "listCall", ".", "PageToken", "(", "pageToken", ")", "\n", "}", "\n", "res", ",", "err", ":=", "listCall", ".", "Do", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "pageToken", "=", "res", ".", "NextPageToken", "\n", "for", "_", ",", "i", ":=", "range", "res", ".", "Items", "{", "name", ":=", "i", ".", "Name", "\n", "if", "_", ",", "ok", ":=", "instances", "[", "name", "]", ";", "!", "ok", "{", "continue", "\n", "}", "\n", "instance", ":=", "&", "gceInstance", "{", "Zone", ":", "zone", ",", "Name", ":", "name", ",", "ID", ":", "i", ".", "Id", ",", "Disks", ":", "i", ".", "Disks", ",", "Type", ":", "lastComponent", "(", "i", ".", "MachineType", ")", ",", "}", "\n", "instances", "[", "name", "]", "=", "instance", "\n", "remaining", "--", "\n", "}", "\n", "}", "\n", "if", "page", ">=", "maxPages", "{", "glog", ".", "Errorf", "(", "\"getInstancesByNames exceeded maxPages=%d for Instances.List: truncating.\"", ",", "maxPages", ")", "\n", "}", "\n", "}", "\n", "instanceArray", ":=", "make", "(", "[", "]", "*", "gceInstance", ",", "len", "(", "names", ")", ")", "\n", "for", "i", ",", "name", ":=", "range", "names", "{", "name", "=", "canonicalizeInstanceName", "(", "name", ")", "\n", "instance", ":=", "instances", "[", "name", "]", "\n", "if", "instance", "==", "nil", "{", "glog", ".", "Errorf", "(", "\"Failed to retrieve instance: %q\"", ",", "name", ")", "\n", "return", "nil", ",", "cloudprovider", ".", "ErrInstanceNotFound", "\n", "}", "\n", "instanceArray", "[", "i", "]", "=", "instances", "[", "name", "]", "\n", "}", "\n", "return", "instanceArray", ",", "nil", "\n", "}" ]
// Gets the named instances, returning cloudprovider.ErrInstanceNotFound if any instance is not found
[ "Gets", "the", "named", "instances", "returning", "cloudprovider", ".", "ErrInstanceNotFound", "if", "any", "instance", "is", "not", "found" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L2989-L3063
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/gce/gce.go
getInstanceByName
func (gce *Cloud) getInstanceByName(name string) (*gceInstance, error) { // Avoid changing behaviour when not managing multiple zones for _, zone := range gce.managedZones { name = canonicalizeInstanceName(name) res, err := gce.service.Instances.Get(gce.projectID, zone, name).Do() if err != nil { glog.Errorf("getInstanceByName: failed to get instance %s; err: %v", name, err) if isHTTPErrorCode(err, http.StatusNotFound) { continue } return nil, err } return &gceInstance{ Zone: lastComponent(res.Zone), Name: res.Name, ID: res.Id, Disks: res.Disks, Type: lastComponent(res.MachineType), }, nil } return nil, cloudprovider.ErrInstanceNotFound }
go
func (gce *Cloud) getInstanceByName(name string) (*gceInstance, error) { // Avoid changing behaviour when not managing multiple zones for _, zone := range gce.managedZones { name = canonicalizeInstanceName(name) res, err := gce.service.Instances.Get(gce.projectID, zone, name).Do() if err != nil { glog.Errorf("getInstanceByName: failed to get instance %s; err: %v", name, err) if isHTTPErrorCode(err, http.StatusNotFound) { continue } return nil, err } return &gceInstance{ Zone: lastComponent(res.Zone), Name: res.Name, ID: res.Id, Disks: res.Disks, Type: lastComponent(res.MachineType), }, nil } return nil, cloudprovider.ErrInstanceNotFound }
[ "func", "(", "gce", "*", "Cloud", ")", "getInstanceByName", "(", "name", "string", ")", "(", "*", "gceInstance", ",", "error", ")", "{", "for", "_", ",", "zone", ":=", "range", "gce", ".", "managedZones", "{", "name", "=", "canonicalizeInstanceName", "(", "name", ")", "\n", "res", ",", "err", ":=", "gce", ".", "service", ".", "Instances", ".", "Get", "(", "gce", ".", "projectID", ",", "zone", ",", "name", ")", ".", "Do", "(", ")", "\n", "if", "err", "!=", "nil", "{", "glog", ".", "Errorf", "(", "\"getInstanceByName: failed to get instance %s; err: %v\"", ",", "name", ",", "err", ")", "\n", "if", "isHTTPErrorCode", "(", "err", ",", "http", ".", "StatusNotFound", ")", "{", "continue", "\n", "}", "\n", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "gceInstance", "{", "Zone", ":", "lastComponent", "(", "res", ".", "Zone", ")", ",", "Name", ":", "res", ".", "Name", ",", "ID", ":", "res", ".", "Id", ",", "Disks", ":", "res", ".", "Disks", ",", "Type", ":", "lastComponent", "(", "res", ".", "MachineType", ")", ",", "}", ",", "nil", "\n", "}", "\n", "return", "nil", ",", "cloudprovider", ".", "ErrInstanceNotFound", "\n", "}" ]
// Gets the named instance, returning cloudprovider.ErrInstanceNotFound if the instance is not found
[ "Gets", "the", "named", "instance", "returning", "cloudprovider", ".", "ErrInstanceNotFound", "if", "the", "instance", "is", "not", "found" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/gce/gce.go#L3066-L3088
train
kubernetes-incubator/external-storage
repo-infra/kazel/kazel.go
Set
func (a Attrs) Set(name string, expr bzl.Expr) { a[name] = expr }
go
func (a Attrs) Set(name string, expr bzl.Expr) { a[name] = expr }
[ "func", "(", "a", "Attrs", ")", "Set", "(", "name", "string", ",", "expr", "bzl", ".", "Expr", ")", "{", "a", "[", "name", "]", "=", "expr", "\n", "}" ]
// Set sets the named attribute to the provided bazel expression.
[ "Set", "sets", "the", "named", "attribute", "to", "the", "provided", "bazel", "expression", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/repo-infra/kazel/kazel.go#L510-L512
train
kubernetes-incubator/external-storage
repo-infra/kazel/kazel.go
SetList
func (a Attrs) SetList(name string, expr *bzl.ListExpr) { if len(expr.List) == 0 { return } a[name] = expr }
go
func (a Attrs) SetList(name string, expr *bzl.ListExpr) { if len(expr.List) == 0 { return } a[name] = expr }
[ "func", "(", "a", "Attrs", ")", "SetList", "(", "name", "string", ",", "expr", "*", "bzl", ".", "ListExpr", ")", "{", "if", "len", "(", "expr", ".", "List", ")", "==", "0", "{", "return", "\n", "}", "\n", "a", "[", "name", "]", "=", "expr", "\n", "}" ]
// SetList sets the named attribute to the provided bazel expression list.
[ "SetList", "sets", "the", "named", "attribute", "to", "the", "provided", "bazel", "expression", "list", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/repo-infra/kazel/kazel.go#L515-L520
train
kubernetes-incubator/external-storage
repo-infra/kazel/kazel.go
findBuildFile
func findBuildFile(pkgPath string) (bool, string) { options := []string{"BUILD.bazel", "BUILD"} for _, b := range options { path := filepath.Join(pkgPath, b) info, err := os.Stat(path) if err == nil && !info.IsDir() { return true, path } } return false, filepath.Join(pkgPath, "BUILD") }
go
func findBuildFile(pkgPath string) (bool, string) { options := []string{"BUILD.bazel", "BUILD"} for _, b := range options { path := filepath.Join(pkgPath, b) info, err := os.Stat(path) if err == nil && !info.IsDir() { return true, path } } return false, filepath.Join(pkgPath, "BUILD") }
[ "func", "findBuildFile", "(", "pkgPath", "string", ")", "(", "bool", ",", "string", ")", "{", "options", ":=", "[", "]", "string", "{", "\"BUILD.bazel\"", ",", "\"BUILD\"", "}", "\n", "for", "_", ",", "b", ":=", "range", "options", "{", "path", ":=", "filepath", ".", "Join", "(", "pkgPath", ",", "b", ")", "\n", "info", ",", "err", ":=", "os", ".", "Stat", "(", "path", ")", "\n", "if", "err", "==", "nil", "&&", "!", "info", ".", "IsDir", "(", ")", "{", "return", "true", ",", "path", "\n", "}", "\n", "}", "\n", "return", "false", ",", "filepath", ".", "Join", "(", "pkgPath", ",", "\"BUILD\"", ")", "\n", "}" ]
// findBuildFile determines the name of a preexisting BUILD file, returning // a default if no such file exists.
[ "findBuildFile", "determines", "the", "name", "of", "a", "preexisting", "BUILD", "file", "returning", "a", "default", "if", "no", "such", "file", "exists", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/repo-infra/kazel/kazel.go#L616-L626
train
kubernetes-incubator/external-storage
repo-infra/kazel/kazel.go
ReconcileRules
func ReconcileRules(pkgPath string, rules []*bzl.Rule, managedAttrs []string, dryRun bool) (bool, error) { _, path := findBuildFile(pkgPath) info, err := os.Stat(path) if err != nil && os.IsNotExist(err) { f := &bzl.File{} writeHeaders(f) reconcileLoad(f, rules) writeRules(f, rules) return writeFile(path, f, false, dryRun) } else if err != nil { return false, err } if info.IsDir() { return false, fmt.Errorf("%q cannot be a directory", path) } b, err := ioutil.ReadFile(path) if err != nil { return false, err } f, err := bzl.Parse(path, b) if err != nil { return false, err } oldRules := make(map[string]*bzl.Rule) for _, r := range f.Rules("") { oldRules[r.Name()] = r } for _, r := range rules { o, ok := oldRules[r.Name()] if !ok { f.Stmt = append(f.Stmt, r.Call) continue } if !RuleIsManaged(o) { continue } reconcileAttr := func(o, n *bzl.Rule, name string) { if e := n.Attr(name); e != nil { o.SetAttr(name, e) } else { o.DelAttr(name) } } for _, attr := range managedAttrs { reconcileAttr(o, r, attr) } delete(oldRules, r.Name()) } for _, r := range oldRules { if !RuleIsManaged(r) { continue } f.DelRules(r.Kind(), r.Name()) } reconcileLoad(f, f.Rules("")) return writeFile(path, f, true, dryRun) }
go
func ReconcileRules(pkgPath string, rules []*bzl.Rule, managedAttrs []string, dryRun bool) (bool, error) { _, path := findBuildFile(pkgPath) info, err := os.Stat(path) if err != nil && os.IsNotExist(err) { f := &bzl.File{} writeHeaders(f) reconcileLoad(f, rules) writeRules(f, rules) return writeFile(path, f, false, dryRun) } else if err != nil { return false, err } if info.IsDir() { return false, fmt.Errorf("%q cannot be a directory", path) } b, err := ioutil.ReadFile(path) if err != nil { return false, err } f, err := bzl.Parse(path, b) if err != nil { return false, err } oldRules := make(map[string]*bzl.Rule) for _, r := range f.Rules("") { oldRules[r.Name()] = r } for _, r := range rules { o, ok := oldRules[r.Name()] if !ok { f.Stmt = append(f.Stmt, r.Call) continue } if !RuleIsManaged(o) { continue } reconcileAttr := func(o, n *bzl.Rule, name string) { if e := n.Attr(name); e != nil { o.SetAttr(name, e) } else { o.DelAttr(name) } } for _, attr := range managedAttrs { reconcileAttr(o, r, attr) } delete(oldRules, r.Name()) } for _, r := range oldRules { if !RuleIsManaged(r) { continue } f.DelRules(r.Kind(), r.Name()) } reconcileLoad(f, f.Rules("")) return writeFile(path, f, true, dryRun) }
[ "func", "ReconcileRules", "(", "pkgPath", "string", ",", "rules", "[", "]", "*", "bzl", ".", "Rule", ",", "managedAttrs", "[", "]", "string", ",", "dryRun", "bool", ")", "(", "bool", ",", "error", ")", "{", "_", ",", "path", ":=", "findBuildFile", "(", "pkgPath", ")", "\n", "info", ",", "err", ":=", "os", ".", "Stat", "(", "path", ")", "\n", "if", "err", "!=", "nil", "&&", "os", ".", "IsNotExist", "(", "err", ")", "{", "f", ":=", "&", "bzl", ".", "File", "{", "}", "\n", "writeHeaders", "(", "f", ")", "\n", "reconcileLoad", "(", "f", ",", "rules", ")", "\n", "writeRules", "(", "f", ",", "rules", ")", "\n", "return", "writeFile", "(", "path", ",", "f", ",", "false", ",", "dryRun", ")", "\n", "}", "else", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "if", "info", ".", "IsDir", "(", ")", "{", "return", "false", ",", "fmt", ".", "Errorf", "(", "\"%q cannot be a directory\"", ",", "path", ")", "\n", "}", "\n", "b", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "f", ",", "err", ":=", "bzl", ".", "Parse", "(", "path", ",", "b", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "oldRules", ":=", "make", "(", "map", "[", "string", "]", "*", "bzl", ".", "Rule", ")", "\n", "for", "_", ",", "r", ":=", "range", "f", ".", "Rules", "(", "\"\"", ")", "{", "oldRules", "[", "r", ".", "Name", "(", ")", "]", "=", "r", "\n", "}", "\n", "for", "_", ",", "r", ":=", "range", "rules", "{", "o", ",", "ok", ":=", "oldRules", "[", "r", ".", "Name", "(", ")", "]", "\n", "if", "!", "ok", "{", "f", ".", "Stmt", "=", "append", "(", "f", ".", "Stmt", ",", "r", ".", "Call", ")", "\n", "continue", "\n", "}", "\n", "if", "!", "RuleIsManaged", "(", "o", ")", "{", "continue", "\n", "}", "\n", "reconcileAttr", ":=", "func", "(", "o", ",", "n", "*", "bzl", ".", "Rule", ",", "name", "string", ")", "{", "if", "e", ":=", "n", ".", "Attr", "(", "name", ")", ";", "e", "!=", "nil", "{", "o", ".", "SetAttr", "(", "name", ",", "e", ")", "\n", "}", "else", "{", "o", ".", "DelAttr", "(", "name", ")", "\n", "}", "\n", "}", "\n", "for", "_", ",", "attr", ":=", "range", "managedAttrs", "{", "reconcileAttr", "(", "o", ",", "r", ",", "attr", ")", "\n", "}", "\n", "delete", "(", "oldRules", ",", "r", ".", "Name", "(", ")", ")", "\n", "}", "\n", "for", "_", ",", "r", ":=", "range", "oldRules", "{", "if", "!", "RuleIsManaged", "(", "r", ")", "{", "continue", "\n", "}", "\n", "f", ".", "DelRules", "(", "r", ".", "Kind", "(", ")", ",", "r", ".", "Name", "(", ")", ")", "\n", "}", "\n", "reconcileLoad", "(", "f", ",", "f", ".", "Rules", "(", "\"\"", ")", ")", "\n", "return", "writeFile", "(", "path", ",", "f", ",", "true", ",", "dryRun", ")", "\n", "}" ]
// ReconcileRules reconciles, simplifies, and writes the rules for the specified package, adding // additional dependency rules as needed.
[ "ReconcileRules", "reconciles", "simplifies", "and", "writes", "the", "rules", "for", "the", "specified", "package", "adding", "additional", "dependency", "rules", "as", "needed", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/repo-infra/kazel/kazel.go#L630-L688
train
kubernetes-incubator/external-storage
repo-infra/kazel/kazel.go
RuleIsManaged
func RuleIsManaged(r *bzl.Rule) bool { var automanaged bool for _, tag := range r.AttrStrings("tags") { if tag == automanagedTag { automanaged = true break } } return automanaged }
go
func RuleIsManaged(r *bzl.Rule) bool { var automanaged bool for _, tag := range r.AttrStrings("tags") { if tag == automanagedTag { automanaged = true break } } return automanaged }
[ "func", "RuleIsManaged", "(", "r", "*", "bzl", ".", "Rule", ")", "bool", "{", "var", "automanaged", "bool", "\n", "for", "_", ",", "tag", ":=", "range", "r", ".", "AttrStrings", "(", "\"tags\"", ")", "{", "if", "tag", "==", "automanagedTag", "{", "automanaged", "=", "true", "\n", "break", "\n", "}", "\n", "}", "\n", "return", "automanaged", "\n", "}" ]
// RuleIsManaged returns whether the provided rule is managed by this tool, // based on the tags set on the rule.
[ "RuleIsManaged", "returns", "whether", "the", "provided", "rule", "is", "managed", "by", "this", "tool", "based", "on", "the", "tags", "set", "on", "the", "rule", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/repo-infra/kazel/kazel.go#L729-L738
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/plugins.go
CloudProviders
func CloudProviders() []string { names := []string{} providersMutex.Lock() defer providersMutex.Unlock() for name := range providers { names = append(names, name) } return names }
go
func CloudProviders() []string { names := []string{} providersMutex.Lock() defer providersMutex.Unlock() for name := range providers { names = append(names, name) } return names }
[ "func", "CloudProviders", "(", ")", "[", "]", "string", "{", "names", ":=", "[", "]", "string", "{", "}", "\n", "providersMutex", ".", "Lock", "(", ")", "\n", "defer", "providersMutex", ".", "Unlock", "(", ")", "\n", "for", "name", ":=", "range", "providers", "{", "names", "=", "append", "(", "names", ",", "name", ")", "\n", "}", "\n", "return", "names", "\n", "}" ]
// CloudProviders returns the name of all registered cloud providers in a // string slice
[ "CloudProviders", "returns", "the", "name", "of", "all", "registered", "cloud", "providers", "in", "a", "string", "slice" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/plugins.go#L65-L73
train
kubernetes-incubator/external-storage
local-volume/provisioner/pkg/util/volume_util_linux.go
GetBlockCapacityByte
func (u *volumeUtil) GetBlockCapacityByte(fullPath string) (int64, error) { file, err := os.OpenFile(fullPath, os.O_RDONLY, 0) if err != nil { return 0, err } defer file.Close() var size int64 // Get size of block device into 64 bit int. // Ref: http://www.microhowto.info/howto/get_the_size_of_a_linux_block_special_device_in_c.html if _, _, err := unix.Syscall(unix.SYS_IOCTL, file.Fd(), unix.BLKGETSIZE64, uintptr(unsafe.Pointer(&size))); err != 0 { return 0, err } return size, err }
go
func (u *volumeUtil) GetBlockCapacityByte(fullPath string) (int64, error) { file, err := os.OpenFile(fullPath, os.O_RDONLY, 0) if err != nil { return 0, err } defer file.Close() var size int64 // Get size of block device into 64 bit int. // Ref: http://www.microhowto.info/howto/get_the_size_of_a_linux_block_special_device_in_c.html if _, _, err := unix.Syscall(unix.SYS_IOCTL, file.Fd(), unix.BLKGETSIZE64, uintptr(unsafe.Pointer(&size))); err != 0 { return 0, err } return size, err }
[ "func", "(", "u", "*", "volumeUtil", ")", "GetBlockCapacityByte", "(", "fullPath", "string", ")", "(", "int64", ",", "error", ")", "{", "file", ",", "err", ":=", "os", ".", "OpenFile", "(", "fullPath", ",", "os", ".", "O_RDONLY", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "defer", "file", ".", "Close", "(", ")", "\n", "var", "size", "int64", "\n", "if", "_", ",", "_", ",", "err", ":=", "unix", ".", "Syscall", "(", "unix", ".", "SYS_IOCTL", ",", "file", ".", "Fd", "(", ")", ",", "unix", ".", "BLKGETSIZE64", ",", "uintptr", "(", "unsafe", ".", "Pointer", "(", "&", "size", ")", ")", ")", ";", "err", "!=", "0", "{", "return", "0", ",", "err", "\n", "}", "\n", "return", "size", ",", "err", "\n", "}" ]
// GetBlockCapacityByte returns capacity in bytes of a block device. // fullPath is the pathname of block device.
[ "GetBlockCapacityByte", "returns", "capacity", "in", "bytes", "of", "a", "block", "device", ".", "fullPath", "is", "the", "pathname", "of", "block", "device", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/util/volume_util_linux.go#L30-L45
train
kubernetes-incubator/external-storage
local-volume/provisioner/pkg/common/common.go
CreateLocalPVSpec
func CreateLocalPVSpec(config *LocalPVConfig) *v1.PersistentVolume { pv := &v1.PersistentVolume{ ObjectMeta: metav1.ObjectMeta{ Name: config.Name, Labels: config.Labels, Annotations: map[string]string{ AnnProvisionedBy: config.ProvisionerName, }, }, Spec: v1.PersistentVolumeSpec{ PersistentVolumeReclaimPolicy: config.ReclaimPolicy, Capacity: v1.ResourceList{ v1.ResourceName(v1.ResourceStorage): *resource.NewQuantity(int64(config.Capacity), resource.BinarySI), }, PersistentVolumeSource: v1.PersistentVolumeSource{ Local: &v1.LocalVolumeSource{ Path: config.HostPath, FSType: config.FsType, }, }, AccessModes: []v1.PersistentVolumeAccessMode{ v1.ReadWriteOnce, }, StorageClassName: config.StorageClass, VolumeMode: &config.VolumeMode, MountOptions: config.MountOptions, }, } if config.UseAlphaAPI { pv.ObjectMeta.Annotations[AlphaStorageNodeAffinityAnnotation] = config.AffinityAnn } else { pv.Spec.NodeAffinity = config.NodeAffinity } return pv }
go
func CreateLocalPVSpec(config *LocalPVConfig) *v1.PersistentVolume { pv := &v1.PersistentVolume{ ObjectMeta: metav1.ObjectMeta{ Name: config.Name, Labels: config.Labels, Annotations: map[string]string{ AnnProvisionedBy: config.ProvisionerName, }, }, Spec: v1.PersistentVolumeSpec{ PersistentVolumeReclaimPolicy: config.ReclaimPolicy, Capacity: v1.ResourceList{ v1.ResourceName(v1.ResourceStorage): *resource.NewQuantity(int64(config.Capacity), resource.BinarySI), }, PersistentVolumeSource: v1.PersistentVolumeSource{ Local: &v1.LocalVolumeSource{ Path: config.HostPath, FSType: config.FsType, }, }, AccessModes: []v1.PersistentVolumeAccessMode{ v1.ReadWriteOnce, }, StorageClassName: config.StorageClass, VolumeMode: &config.VolumeMode, MountOptions: config.MountOptions, }, } if config.UseAlphaAPI { pv.ObjectMeta.Annotations[AlphaStorageNodeAffinityAnnotation] = config.AffinityAnn } else { pv.Spec.NodeAffinity = config.NodeAffinity } return pv }
[ "func", "CreateLocalPVSpec", "(", "config", "*", "LocalPVConfig", ")", "*", "v1", ".", "PersistentVolume", "{", "pv", ":=", "&", "v1", ".", "PersistentVolume", "{", "ObjectMeta", ":", "metav1", ".", "ObjectMeta", "{", "Name", ":", "config", ".", "Name", ",", "Labels", ":", "config", ".", "Labels", ",", "Annotations", ":", "map", "[", "string", "]", "string", "{", "AnnProvisionedBy", ":", "config", ".", "ProvisionerName", ",", "}", ",", "}", ",", "Spec", ":", "v1", ".", "PersistentVolumeSpec", "{", "PersistentVolumeReclaimPolicy", ":", "config", ".", "ReclaimPolicy", ",", "Capacity", ":", "v1", ".", "ResourceList", "{", "v1", ".", "ResourceName", "(", "v1", ".", "ResourceStorage", ")", ":", "*", "resource", ".", "NewQuantity", "(", "int64", "(", "config", ".", "Capacity", ")", ",", "resource", ".", "BinarySI", ")", ",", "}", ",", "PersistentVolumeSource", ":", "v1", ".", "PersistentVolumeSource", "{", "Local", ":", "&", "v1", ".", "LocalVolumeSource", "{", "Path", ":", "config", ".", "HostPath", ",", "FSType", ":", "config", ".", "FsType", ",", "}", ",", "}", ",", "AccessModes", ":", "[", "]", "v1", ".", "PersistentVolumeAccessMode", "{", "v1", ".", "ReadWriteOnce", ",", "}", ",", "StorageClassName", ":", "config", ".", "StorageClass", ",", "VolumeMode", ":", "&", "config", ".", "VolumeMode", ",", "MountOptions", ":", "config", ".", "MountOptions", ",", "}", ",", "}", "\n", "if", "config", ".", "UseAlphaAPI", "{", "pv", ".", "ObjectMeta", ".", "Annotations", "[", "AlphaStorageNodeAffinityAnnotation", "]", "=", "config", ".", "AffinityAnn", "\n", "}", "else", "{", "pv", ".", "Spec", ".", "NodeAffinity", "=", "config", ".", "NodeAffinity", "\n", "}", "\n", "return", "pv", "\n", "}" ]
// CreateLocalPVSpec returns a PV spec that can be used for PV creation
[ "CreateLocalPVSpec", "returns", "a", "PV", "spec", "that", "can", "be", "used", "for", "PV", "creation" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/common/common.go#L201-L235
train
kubernetes-incubator/external-storage
local-volume/provisioner/pkg/common/common.go
GetVolumeConfigFromConfigMap
func GetVolumeConfigFromConfigMap(client *kubernetes.Clientset, namespace, name string, provisionerConfig *ProvisionerConfiguration) error { configMap, err := client.CoreV1().ConfigMaps(namespace).Get(name, metav1.GetOptions{}) if err != nil { return err } err = ConfigMapDataToVolumeConfig(configMap.Data, provisionerConfig) return err }
go
func GetVolumeConfigFromConfigMap(client *kubernetes.Clientset, namespace, name string, provisionerConfig *ProvisionerConfiguration) error { configMap, err := client.CoreV1().ConfigMaps(namespace).Get(name, metav1.GetOptions{}) if err != nil { return err } err = ConfigMapDataToVolumeConfig(configMap.Data, provisionerConfig) return err }
[ "func", "GetVolumeConfigFromConfigMap", "(", "client", "*", "kubernetes", ".", "Clientset", ",", "namespace", ",", "name", "string", ",", "provisionerConfig", "*", "ProvisionerConfiguration", ")", "error", "{", "configMap", ",", "err", ":=", "client", ".", "CoreV1", "(", ")", ".", "ConfigMaps", "(", "namespace", ")", ".", "Get", "(", "name", ",", "metav1", ".", "GetOptions", "{", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "err", "=", "ConfigMapDataToVolumeConfig", "(", "configMap", ".", "Data", ",", "provisionerConfig", ")", "\n", "return", "err", "\n", "}" ]
// GetVolumeConfigFromConfigMap gets volume configuration from given configmap.
[ "GetVolumeConfigFromConfigMap", "gets", "volume", "configuration", "from", "given", "configmap", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/common/common.go#L248-L255
train
kubernetes-incubator/external-storage
local-volume/provisioner/pkg/common/common.go
VolumeConfigToConfigMapData
func VolumeConfigToConfigMapData(config *ProvisionerConfiguration) (map[string]string, error) { configMapData := make(map[string]string) val, err := yaml.Marshal(config.StorageClassConfig) if err != nil { return nil, fmt.Errorf("unable to Marshal volume config: %v", err) } configMapData[ProvisonerStorageClassConfig] = string(val) if len(config.NodeLabelsForPV) > 0 { nodeLabels, nlErr := yaml.Marshal(config.NodeLabelsForPV) if nlErr != nil { return nil, fmt.Errorf("unable to Marshal node label: %v", nlErr) } configMapData[ProvisionerNodeLabelsForPV] = string(nodeLabels) } ver, err := yaml.Marshal(config.UseAlphaAPI) if err != nil { return nil, fmt.Errorf("unable to Marshal API version config: %v", err) } configMapData[ProvisionerUseAlphaAPI] = string(ver) return configMapData, nil }
go
func VolumeConfigToConfigMapData(config *ProvisionerConfiguration) (map[string]string, error) { configMapData := make(map[string]string) val, err := yaml.Marshal(config.StorageClassConfig) if err != nil { return nil, fmt.Errorf("unable to Marshal volume config: %v", err) } configMapData[ProvisonerStorageClassConfig] = string(val) if len(config.NodeLabelsForPV) > 0 { nodeLabels, nlErr := yaml.Marshal(config.NodeLabelsForPV) if nlErr != nil { return nil, fmt.Errorf("unable to Marshal node label: %v", nlErr) } configMapData[ProvisionerNodeLabelsForPV] = string(nodeLabels) } ver, err := yaml.Marshal(config.UseAlphaAPI) if err != nil { return nil, fmt.Errorf("unable to Marshal API version config: %v", err) } configMapData[ProvisionerUseAlphaAPI] = string(ver) return configMapData, nil }
[ "func", "VolumeConfigToConfigMapData", "(", "config", "*", "ProvisionerConfiguration", ")", "(", "map", "[", "string", "]", "string", ",", "error", ")", "{", "configMapData", ":=", "make", "(", "map", "[", "string", "]", "string", ")", "\n", "val", ",", "err", ":=", "yaml", ".", "Marshal", "(", "config", ".", "StorageClassConfig", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"unable to Marshal volume config: %v\"", ",", "err", ")", "\n", "}", "\n", "configMapData", "[", "ProvisonerStorageClassConfig", "]", "=", "string", "(", "val", ")", "\n", "if", "len", "(", "config", ".", "NodeLabelsForPV", ")", ">", "0", "{", "nodeLabels", ",", "nlErr", ":=", "yaml", ".", "Marshal", "(", "config", ".", "NodeLabelsForPV", ")", "\n", "if", "nlErr", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"unable to Marshal node label: %v\"", ",", "nlErr", ")", "\n", "}", "\n", "configMapData", "[", "ProvisionerNodeLabelsForPV", "]", "=", "string", "(", "nodeLabels", ")", "\n", "}", "\n", "ver", ",", "err", ":=", "yaml", ".", "Marshal", "(", "config", ".", "UseAlphaAPI", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"unable to Marshal API version config: %v\"", ",", "err", ")", "\n", "}", "\n", "configMapData", "[", "ProvisionerUseAlphaAPI", "]", "=", "string", "(", "ver", ")", "\n", "return", "configMapData", ",", "nil", "\n", "}" ]
// VolumeConfigToConfigMapData converts volume config to configmap data.
[ "VolumeConfigToConfigMapData", "converts", "volume", "config", "to", "configmap", "data", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/common/common.go#L258-L279
train
kubernetes-incubator/external-storage
local-volume/provisioner/pkg/common/common.go
ConfigMapDataToVolumeConfig
func ConfigMapDataToVolumeConfig(data map[string]string, provisionerConfig *ProvisionerConfiguration) error { rawYaml := "" for key, val := range data { rawYaml += key rawYaml += ": \n" rawYaml += insertSpaces(string(val)) } if err := yaml.Unmarshal([]byte(rawYaml), provisionerConfig); err != nil { return fmt.Errorf("fail to Unmarshal yaml due to: %#v", err) } for class, config := range provisionerConfig.StorageClassConfig { if config.BlockCleanerCommand == nil { // Supply a default block cleaner command. config.BlockCleanerCommand = []string{DefaultBlockCleanerCommand} } else { // Validate that array is non empty. if len(config.BlockCleanerCommand) < 1 { return fmt.Errorf("Invalid empty block cleaner command for class %v", class) } } if config.MountDir == "" || config.HostDir == "" { return fmt.Errorf("Storage Class %v is misconfigured, missing HostDir or MountDir parameter", class) } if config.VolumeMode == "" { config.VolumeMode = DefaultVolumeMode } volumeMode := v1.PersistentVolumeMode(config.VolumeMode) if volumeMode != v1.PersistentVolumeBlock && volumeMode != v1.PersistentVolumeFilesystem { return fmt.Errorf("unsupported volume mode %s", config.VolumeMode) } provisionerConfig.StorageClassConfig[class] = config glog.Infof("StorageClass %q configured with MountDir %q, HostDir %q, VolumeMode %q, FsType %q, BlockCleanerCommand %q", class, config.MountDir, config.HostDir, config.VolumeMode, config.FsType, config.BlockCleanerCommand) } return nil }
go
func ConfigMapDataToVolumeConfig(data map[string]string, provisionerConfig *ProvisionerConfiguration) error { rawYaml := "" for key, val := range data { rawYaml += key rawYaml += ": \n" rawYaml += insertSpaces(string(val)) } if err := yaml.Unmarshal([]byte(rawYaml), provisionerConfig); err != nil { return fmt.Errorf("fail to Unmarshal yaml due to: %#v", err) } for class, config := range provisionerConfig.StorageClassConfig { if config.BlockCleanerCommand == nil { // Supply a default block cleaner command. config.BlockCleanerCommand = []string{DefaultBlockCleanerCommand} } else { // Validate that array is non empty. if len(config.BlockCleanerCommand) < 1 { return fmt.Errorf("Invalid empty block cleaner command for class %v", class) } } if config.MountDir == "" || config.HostDir == "" { return fmt.Errorf("Storage Class %v is misconfigured, missing HostDir or MountDir parameter", class) } if config.VolumeMode == "" { config.VolumeMode = DefaultVolumeMode } volumeMode := v1.PersistentVolumeMode(config.VolumeMode) if volumeMode != v1.PersistentVolumeBlock && volumeMode != v1.PersistentVolumeFilesystem { return fmt.Errorf("unsupported volume mode %s", config.VolumeMode) } provisionerConfig.StorageClassConfig[class] = config glog.Infof("StorageClass %q configured with MountDir %q, HostDir %q, VolumeMode %q, FsType %q, BlockCleanerCommand %q", class, config.MountDir, config.HostDir, config.VolumeMode, config.FsType, config.BlockCleanerCommand) } return nil }
[ "func", "ConfigMapDataToVolumeConfig", "(", "data", "map", "[", "string", "]", "string", ",", "provisionerConfig", "*", "ProvisionerConfiguration", ")", "error", "{", "rawYaml", ":=", "\"\"", "\n", "for", "key", ",", "val", ":=", "range", "data", "{", "rawYaml", "+=", "key", "\n", "rawYaml", "+=", "\": \\n\"", "\n", "\\n", "\n", "}", "\n", "rawYaml", "+=", "insertSpaces", "(", "string", "(", "val", ")", ")", "\n", "if", "err", ":=", "yaml", ".", "Unmarshal", "(", "[", "]", "byte", "(", "rawYaml", ")", ",", "provisionerConfig", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"fail to Unmarshal yaml due to: %#v\"", ",", "err", ")", "\n", "}", "\n", "for", "class", ",", "config", ":=", "range", "provisionerConfig", ".", "StorageClassConfig", "{", "if", "config", ".", "BlockCleanerCommand", "==", "nil", "{", "config", ".", "BlockCleanerCommand", "=", "[", "]", "string", "{", "DefaultBlockCleanerCommand", "}", "\n", "}", "else", "{", "if", "len", "(", "config", ".", "BlockCleanerCommand", ")", "<", "1", "{", "return", "fmt", ".", "Errorf", "(", "\"Invalid empty block cleaner command for class %v\"", ",", "class", ")", "\n", "}", "\n", "}", "\n", "if", "config", ".", "MountDir", "==", "\"\"", "||", "config", ".", "HostDir", "==", "\"\"", "{", "return", "fmt", ".", "Errorf", "(", "\"Storage Class %v is misconfigured, missing HostDir or MountDir parameter\"", ",", "class", ")", "\n", "}", "\n", "if", "config", ".", "VolumeMode", "==", "\"\"", "{", "config", ".", "VolumeMode", "=", "DefaultVolumeMode", "\n", "}", "\n", "volumeMode", ":=", "v1", ".", "PersistentVolumeMode", "(", "config", ".", "VolumeMode", ")", "\n", "if", "volumeMode", "!=", "v1", ".", "PersistentVolumeBlock", "&&", "volumeMode", "!=", "v1", ".", "PersistentVolumeFilesystem", "{", "return", "fmt", ".", "Errorf", "(", "\"unsupported volume mode %s\"", ",", "config", ".", "VolumeMode", ")", "\n", "}", "\n", "provisionerConfig", ".", "StorageClassConfig", "[", "class", "]", "=", "config", "\n", "glog", ".", "Infof", "(", "\"StorageClass %q configured with MountDir %q, HostDir %q, VolumeMode %q, FsType %q, BlockCleanerCommand %q\"", ",", "class", ",", "config", ".", "MountDir", ",", "config", ".", "HostDir", ",", "config", ".", "VolumeMode", ",", "config", ".", "FsType", ",", "config", ".", "BlockCleanerCommand", ")", "\n", "}", "\n", "}" ]
// ConfigMapDataToVolumeConfig converts configmap data to volume config.
[ "ConfigMapDataToVolumeConfig", "converts", "configmap", "data", "to", "volume", "config", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/common/common.go#L282-L325
train
kubernetes-incubator/external-storage
local-volume/provisioner/pkg/common/common.go
LoadProvisionerConfigs
func LoadProvisionerConfigs(configPath string, provisionerConfig *ProvisionerConfiguration) error { files, err := ioutil.ReadDir(configPath) if err != nil { return err } data := make(map[string]string) for _, file := range files { if !file.IsDir() { if strings.Compare(file.Name(), "..data") != 0 { fileContents, err := ioutil.ReadFile(path.Join(configPath, file.Name())) if err != nil { glog.Infof("Could not read file: %s due to: %v", path.Join(configPath, file.Name()), err) return err } data[file.Name()] = string(fileContents) } } } return ConfigMapDataToVolumeConfig(data, provisionerConfig) }
go
func LoadProvisionerConfigs(configPath string, provisionerConfig *ProvisionerConfiguration) error { files, err := ioutil.ReadDir(configPath) if err != nil { return err } data := make(map[string]string) for _, file := range files { if !file.IsDir() { if strings.Compare(file.Name(), "..data") != 0 { fileContents, err := ioutil.ReadFile(path.Join(configPath, file.Name())) if err != nil { glog.Infof("Could not read file: %s due to: %v", path.Join(configPath, file.Name()), err) return err } data[file.Name()] = string(fileContents) } } } return ConfigMapDataToVolumeConfig(data, provisionerConfig) }
[ "func", "LoadProvisionerConfigs", "(", "configPath", "string", ",", "provisionerConfig", "*", "ProvisionerConfiguration", ")", "error", "{", "files", ",", "err", ":=", "ioutil", ".", "ReadDir", "(", "configPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "data", ":=", "make", "(", "map", "[", "string", "]", "string", ")", "\n", "for", "_", ",", "file", ":=", "range", "files", "{", "if", "!", "file", ".", "IsDir", "(", ")", "{", "if", "strings", ".", "Compare", "(", "file", ".", "Name", "(", ")", ",", "\"..data\"", ")", "!=", "0", "{", "fileContents", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "path", ".", "Join", "(", "configPath", ",", "file", ".", "Name", "(", ")", ")", ")", "\n", "if", "err", "!=", "nil", "{", "glog", ".", "Infof", "(", "\"Could not read file: %s due to: %v\"", ",", "path", ".", "Join", "(", "configPath", ",", "file", ".", "Name", "(", ")", ")", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n", "data", "[", "file", ".", "Name", "(", ")", "]", "=", "string", "(", "fileContents", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "ConfigMapDataToVolumeConfig", "(", "data", ",", "provisionerConfig", ")", "\n", "}" ]
// LoadProvisionerConfigs loads all configuration into a string and unmarshal it into ProvisionerConfiguration struct. // The configuration is stored in the configmap which is mounted as a volume.
[ "LoadProvisionerConfigs", "loads", "all", "configuration", "into", "a", "string", "and", "unmarshal", "it", "into", "ProvisionerConfiguration", "struct", ".", "The", "configuration", "is", "stored", "in", "the", "configmap", "which", "is", "mounted", "as", "a", "volume", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/common/common.go#L339-L358
train
kubernetes-incubator/external-storage
local-volume/provisioner/pkg/common/common.go
SetupClient
func SetupClient() *kubernetes.Clientset { var config *rest.Config var err error kubeconfigFile := os.Getenv(KubeConfigEnv) if kubeconfigFile != "" { config, err = BuildConfigFromFlags("", kubeconfigFile) if err != nil { glog.Fatalf("Error creating config from %s specified file: %s %v\n", KubeConfigEnv, kubeconfigFile, err) } glog.Infof("Creating client using kubeconfig file %s", kubeconfigFile) } else { config, err = InClusterConfig() if err != nil { glog.Fatalf("Error creating InCluster config: %v\n", err) } glog.Infof("Creating client using in-cluster config") } clientset, err := kubernetes.NewForConfig(config) if err != nil { glog.Fatalf("Error creating clientset: %v\n", err) } return clientset }
go
func SetupClient() *kubernetes.Clientset { var config *rest.Config var err error kubeconfigFile := os.Getenv(KubeConfigEnv) if kubeconfigFile != "" { config, err = BuildConfigFromFlags("", kubeconfigFile) if err != nil { glog.Fatalf("Error creating config from %s specified file: %s %v\n", KubeConfigEnv, kubeconfigFile, err) } glog.Infof("Creating client using kubeconfig file %s", kubeconfigFile) } else { config, err = InClusterConfig() if err != nil { glog.Fatalf("Error creating InCluster config: %v\n", err) } glog.Infof("Creating client using in-cluster config") } clientset, err := kubernetes.NewForConfig(config) if err != nil { glog.Fatalf("Error creating clientset: %v\n", err) } return clientset }
[ "func", "SetupClient", "(", ")", "*", "kubernetes", ".", "Clientset", "{", "var", "config", "*", "rest", ".", "Config", "\n", "var", "err", "error", "\n", "kubeconfigFile", ":=", "os", ".", "Getenv", "(", "KubeConfigEnv", ")", "\n", "if", "kubeconfigFile", "!=", "\"\"", "{", "config", ",", "err", "=", "BuildConfigFromFlags", "(", "\"\"", ",", "kubeconfigFile", ")", "\n", "if", "err", "!=", "nil", "{", "glog", ".", "Fatalf", "(", "\"Error creating config from %s specified file: %s %v\\n\"", ",", "\\n", ",", "KubeConfigEnv", ",", "kubeconfigFile", ")", "\n", "}", "\n", "err", "\n", "}", "else", "glog", ".", "Infof", "(", "\"Creating client using kubeconfig file %s\"", ",", "kubeconfigFile", ")", "\n", "{", "config", ",", "err", "=", "InClusterConfig", "(", ")", "\n", "if", "err", "!=", "nil", "{", "glog", ".", "Fatalf", "(", "\"Error creating InCluster config: %v\\n\"", ",", "\\n", ")", "\n", "}", "\n", "err", "\n", "}", "\n", "glog", ".", "Infof", "(", "\"Creating client using in-cluster config\"", ")", "\n", "clientset", ",", "err", ":=", "kubernetes", ".", "NewForConfig", "(", "config", ")", "\n", "}" ]
// SetupClient created client using either in-cluster configuration or if KUBECONFIG environment variable is specified then using that config.
[ "SetupClient", "created", "client", "using", "either", "in", "-", "cluster", "configuration", "or", "if", "KUBECONFIG", "environment", "variable", "is", "specified", "then", "using", "that", "config", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/common/common.go#L361-L386
train
kubernetes-incubator/external-storage
local-volume/provisioner/pkg/common/common.go
GenerateMountName
func GenerateMountName(mount *MountConfig) string { h := fnv.New32a() h.Write([]byte(mount.HostDir)) h.Write([]byte(mount.MountDir)) return fmt.Sprintf("mount-%x", h.Sum32()) }
go
func GenerateMountName(mount *MountConfig) string { h := fnv.New32a() h.Write([]byte(mount.HostDir)) h.Write([]byte(mount.MountDir)) return fmt.Sprintf("mount-%x", h.Sum32()) }
[ "func", "GenerateMountName", "(", "mount", "*", "MountConfig", ")", "string", "{", "h", ":=", "fnv", ".", "New32a", "(", ")", "\n", "h", ".", "Write", "(", "[", "]", "byte", "(", "mount", ".", "HostDir", ")", ")", "\n", "h", ".", "Write", "(", "[", "]", "byte", "(", "mount", ".", "MountDir", ")", ")", "\n", "return", "fmt", ".", "Sprintf", "(", "\"mount-%x\"", ",", "h", ".", "Sum32", "(", ")", ")", "\n", "}" ]
// GenerateMountName generates a volumeMount.name for pod spec, based on volume configuration.
[ "GenerateMountName", "generates", "a", "volumeMount", ".", "name", "for", "pod", "spec", "based", "on", "volume", "configuration", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/common/common.go#L389-L394
train
kubernetes-incubator/external-storage
local-volume/provisioner/pkg/common/common.go
GetVolumeMode
func GetVolumeMode(volUtil util.VolumeUtil, fullPath string) (v1.PersistentVolumeMode, error) { isdir, errdir := volUtil.IsDir(fullPath) if isdir { return v1.PersistentVolumeFilesystem, nil } // check for Block before returning errdir isblk, errblk := volUtil.IsBlock(fullPath) if isblk { return v1.PersistentVolumeBlock, nil } if errdir == nil && errblk == nil { return "", fmt.Errorf("Skipping file %q: not a directory nor block device", fullPath) } // report the first error found if errdir != nil { return "", fmt.Errorf("Directory check for %q failed: %s", fullPath, errdir) } return "", fmt.Errorf("Block device check for %q failed: %s", fullPath, errblk) }
go
func GetVolumeMode(volUtil util.VolumeUtil, fullPath string) (v1.PersistentVolumeMode, error) { isdir, errdir := volUtil.IsDir(fullPath) if isdir { return v1.PersistentVolumeFilesystem, nil } // check for Block before returning errdir isblk, errblk := volUtil.IsBlock(fullPath) if isblk { return v1.PersistentVolumeBlock, nil } if errdir == nil && errblk == nil { return "", fmt.Errorf("Skipping file %q: not a directory nor block device", fullPath) } // report the first error found if errdir != nil { return "", fmt.Errorf("Directory check for %q failed: %s", fullPath, errdir) } return "", fmt.Errorf("Block device check for %q failed: %s", fullPath, errblk) }
[ "func", "GetVolumeMode", "(", "volUtil", "util", ".", "VolumeUtil", ",", "fullPath", "string", ")", "(", "v1", ".", "PersistentVolumeMode", ",", "error", ")", "{", "isdir", ",", "errdir", ":=", "volUtil", ".", "IsDir", "(", "fullPath", ")", "\n", "if", "isdir", "{", "return", "v1", ".", "PersistentVolumeFilesystem", ",", "nil", "\n", "}", "\n", "isblk", ",", "errblk", ":=", "volUtil", ".", "IsBlock", "(", "fullPath", ")", "\n", "if", "isblk", "{", "return", "v1", ".", "PersistentVolumeBlock", ",", "nil", "\n", "}", "\n", "if", "errdir", "==", "nil", "&&", "errblk", "==", "nil", "{", "return", "\"\"", ",", "fmt", ".", "Errorf", "(", "\"Skipping file %q: not a directory nor block device\"", ",", "fullPath", ")", "\n", "}", "\n", "if", "errdir", "!=", "nil", "{", "return", "\"\"", ",", "fmt", ".", "Errorf", "(", "\"Directory check for %q failed: %s\"", ",", "fullPath", ",", "errdir", ")", "\n", "}", "\n", "return", "\"\"", ",", "fmt", ".", "Errorf", "(", "\"Block device check for %q failed: %s\"", ",", "fullPath", ",", "errblk", ")", "\n", "}" ]
// GetVolumeMode check volume mode of given path.
[ "GetVolumeMode", "check", "volume", "mode", "of", "given", "path", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/common/common.go#L397-L417
train
kubernetes-incubator/external-storage
nfs/pkg/volume/delete.go
Delete
func (p *nfsProvisioner) Delete(volume *v1.PersistentVolume) error { // Ignore the call if this provisioner was not the one to provision the // volume. It doesn't even attempt to delete it, so it's neither a success // (nil error) nor failure (any other error) provisioned, err := p.provisioned(volume) if err != nil { return fmt.Errorf("error determining if this provisioner was the one to provision volume %q: %v", volume.Name, err) } if !provisioned { strerr := fmt.Sprintf("this provisioner id %s didn't provision volume %q and so can't delete it; id %s did & can", p.identity, volume.Name, volume.Annotations[annProvisionerID]) return &controller.IgnoredError{Reason: strerr} } err = p.deleteDirectory(volume) if err != nil { return fmt.Errorf("error deleting volume's backing path: %v", err) } err = p.deleteExport(volume) if err != nil { return fmt.Errorf("deleted the volume's backing path but error deleting export: %v", err) } err = p.deleteQuota(volume) if err != nil { return fmt.Errorf("deleted the volume's backing path & export but error deleting quota: %v", err) } return nil }
go
func (p *nfsProvisioner) Delete(volume *v1.PersistentVolume) error { // Ignore the call if this provisioner was not the one to provision the // volume. It doesn't even attempt to delete it, so it's neither a success // (nil error) nor failure (any other error) provisioned, err := p.provisioned(volume) if err != nil { return fmt.Errorf("error determining if this provisioner was the one to provision volume %q: %v", volume.Name, err) } if !provisioned { strerr := fmt.Sprintf("this provisioner id %s didn't provision volume %q and so can't delete it; id %s did & can", p.identity, volume.Name, volume.Annotations[annProvisionerID]) return &controller.IgnoredError{Reason: strerr} } err = p.deleteDirectory(volume) if err != nil { return fmt.Errorf("error deleting volume's backing path: %v", err) } err = p.deleteExport(volume) if err != nil { return fmt.Errorf("deleted the volume's backing path but error deleting export: %v", err) } err = p.deleteQuota(volume) if err != nil { return fmt.Errorf("deleted the volume's backing path & export but error deleting quota: %v", err) } return nil }
[ "func", "(", "p", "*", "nfsProvisioner", ")", "Delete", "(", "volume", "*", "v1", ".", "PersistentVolume", ")", "error", "{", "provisioned", ",", "err", ":=", "p", ".", "provisioned", "(", "volume", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"error determining if this provisioner was the one to provision volume %q: %v\"", ",", "volume", ".", "Name", ",", "err", ")", "\n", "}", "\n", "if", "!", "provisioned", "{", "strerr", ":=", "fmt", ".", "Sprintf", "(", "\"this provisioner id %s didn't provision volume %q and so can't delete it; id %s did & can\"", ",", "p", ".", "identity", ",", "volume", ".", "Name", ",", "volume", ".", "Annotations", "[", "annProvisionerID", "]", ")", "\n", "return", "&", "controller", ".", "IgnoredError", "{", "Reason", ":", "strerr", "}", "\n", "}", "\n", "err", "=", "p", ".", "deleteDirectory", "(", "volume", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"error deleting volume's backing path: %v\"", ",", "err", ")", "\n", "}", "\n", "err", "=", "p", ".", "deleteExport", "(", "volume", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"deleted the volume's backing path but error deleting export: %v\"", ",", "err", ")", "\n", "}", "\n", "err", "=", "p", ".", "deleteQuota", "(", "volume", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"deleted the volume's backing path & export but error deleting quota: %v\"", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Delete removes the directory that was created by Provision backing the given // PV and removes its export from the NFS server.
[ "Delete", "removes", "the", "directory", "that", "was", "created", "by", "Provision", "backing", "the", "given", "PV", "and", "removes", "its", "export", "from", "the", "NFS", "server", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/nfs/pkg/volume/delete.go#L31-L60
train
kubernetes-incubator/external-storage
digitalocean/pkg/volume/provision.go
NewDigitalOceanProvisioner
func NewDigitalOceanProvisioner(ctx context.Context, client kubernetes.Interface, doClient *godo.Client) controller.Provisioner { var identity types.UID provisioner := &digitaloceanProvisioner{ client: client, doClient: doClient, ctx: ctx, identity: identity, } return provisioner }
go
func NewDigitalOceanProvisioner(ctx context.Context, client kubernetes.Interface, doClient *godo.Client) controller.Provisioner { var identity types.UID provisioner := &digitaloceanProvisioner{ client: client, doClient: doClient, ctx: ctx, identity: identity, } return provisioner }
[ "func", "NewDigitalOceanProvisioner", "(", "ctx", "context", ".", "Context", ",", "client", "kubernetes", ".", "Interface", ",", "doClient", "*", "godo", ".", "Client", ")", "controller", ".", "Provisioner", "{", "var", "identity", "types", ".", "UID", "\n", "provisioner", ":=", "&", "digitaloceanProvisioner", "{", "client", ":", "client", ",", "doClient", ":", "doClient", ",", "ctx", ":", "ctx", ",", "identity", ":", "identity", ",", "}", "\n", "return", "provisioner", "\n", "}" ]
// NewDigitalOceanProvisioner creates a new DigitalOcean provisioner
[ "NewDigitalOceanProvisioner", "creates", "a", "new", "DigitalOcean", "provisioner" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/digitalocean/pkg/volume/provision.go#L50-L61
train
kubernetes-incubator/external-storage
iscsi/targetd/provisioner/iscsi-provisioner.go
getAccessModes
func (p *iscsiProvisioner) getAccessModes() []v1.PersistentVolumeAccessMode { return []v1.PersistentVolumeAccessMode{ v1.ReadWriteOnce, v1.ReadOnlyMany, } }
go
func (p *iscsiProvisioner) getAccessModes() []v1.PersistentVolumeAccessMode { return []v1.PersistentVolumeAccessMode{ v1.ReadWriteOnce, v1.ReadOnlyMany, } }
[ "func", "(", "p", "*", "iscsiProvisioner", ")", "getAccessModes", "(", ")", "[", "]", "v1", ".", "PersistentVolumeAccessMode", "{", "return", "[", "]", "v1", ".", "PersistentVolumeAccessMode", "{", "v1", ".", "ReadWriteOnce", ",", "v1", ".", "ReadOnlyMany", ",", "}", "\n", "}" ]
// getAccessModes returns access modes iscsi volume supported.
[ "getAccessModes", "returns", "access", "modes", "iscsi", "volume", "supported", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/iscsi/targetd/provisioner/iscsi-provisioner.go#L104-L109
train
kubernetes-incubator/external-storage
iscsi/targetd/provisioner/iscsi-provisioner.go
getFirstAvailableLun
func getFirstAvailableLun(exportList exportList) (int32, error) { sort.Sort(exportList) log.Debug("sorted export List: ", exportList) //this is sloppy way to remove duplicates uniqueExport := make(map[int32]export) for _, export := range exportList { uniqueExport[export.Lun] = export } log.Debug("unique luns sorted export List: ", uniqueExport) //this is a sloppy way to get the list of luns luns := make([]int, len(uniqueExport), len(uniqueExport)) i := 0 for _, export := range uniqueExport { luns[i] = int(export.Lun) i++ } log.Debug("lun list: ", luns) if len(luns) >= 255 { return -1, errors.New("255 luns allocated no more luns available") } var sluns sort.IntSlice sluns = luns[0:] sort.Sort(sluns) log.Debug("sorted lun list: ", sluns) lun := int32(len(sluns)) for i, clun := range sluns { if i < int(clun) { lun = int32(i) break } } return lun, nil }
go
func getFirstAvailableLun(exportList exportList) (int32, error) { sort.Sort(exportList) log.Debug("sorted export List: ", exportList) //this is sloppy way to remove duplicates uniqueExport := make(map[int32]export) for _, export := range exportList { uniqueExport[export.Lun] = export } log.Debug("unique luns sorted export List: ", uniqueExport) //this is a sloppy way to get the list of luns luns := make([]int, len(uniqueExport), len(uniqueExport)) i := 0 for _, export := range uniqueExport { luns[i] = int(export.Lun) i++ } log.Debug("lun list: ", luns) if len(luns) >= 255 { return -1, errors.New("255 luns allocated no more luns available") } var sluns sort.IntSlice sluns = luns[0:] sort.Sort(sluns) log.Debug("sorted lun list: ", sluns) lun := int32(len(sluns)) for i, clun := range sluns { if i < int(clun) { lun = int32(i) break } } return lun, nil }
[ "func", "getFirstAvailableLun", "(", "exportList", "exportList", ")", "(", "int32", ",", "error", ")", "{", "sort", ".", "Sort", "(", "exportList", ")", "\n", "log", ".", "Debug", "(", "\"sorted export List: \"", ",", "exportList", ")", "\n", "uniqueExport", ":=", "make", "(", "map", "[", "int32", "]", "export", ")", "\n", "for", "_", ",", "export", ":=", "range", "exportList", "{", "uniqueExport", "[", "export", ".", "Lun", "]", "=", "export", "\n", "}", "\n", "log", ".", "Debug", "(", "\"unique luns sorted export List: \"", ",", "uniqueExport", ")", "\n", "luns", ":=", "make", "(", "[", "]", "int", ",", "len", "(", "uniqueExport", ")", ",", "len", "(", "uniqueExport", ")", ")", "\n", "i", ":=", "0", "\n", "for", "_", ",", "export", ":=", "range", "uniqueExport", "{", "luns", "[", "i", "]", "=", "int", "(", "export", ".", "Lun", ")", "\n", "i", "++", "\n", "}", "\n", "log", ".", "Debug", "(", "\"lun list: \"", ",", "luns", ")", "\n", "if", "len", "(", "luns", ")", ">=", "255", "{", "return", "-", "1", ",", "errors", ".", "New", "(", "\"255 luns allocated no more luns available\"", ")", "\n", "}", "\n", "var", "sluns", "sort", ".", "IntSlice", "\n", "sluns", "=", "luns", "[", "0", ":", "]", "\n", "sort", ".", "Sort", "(", "sluns", ")", "\n", "log", ".", "Debug", "(", "\"sorted lun list: \"", ",", "sluns", ")", "\n", "lun", ":=", "int32", "(", "len", "(", "sluns", ")", ")", "\n", "for", "i", ",", "clun", ":=", "range", "sluns", "{", "if", "i", "<", "int", "(", "clun", ")", "{", "lun", "=", "int32", "(", "i", ")", "\n", "break", "\n", "}", "\n", "}", "\n", "return", "lun", ",", "nil", "\n", "}" ]
// getFirstAvailableLun gets first available Lun.
[ "getFirstAvailableLun", "gets", "first", "available", "Lun", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/iscsi/targetd/provisioner/iscsi-provisioner.go#L312-L348
train
kubernetes-incubator/external-storage
iscsi/targetd/provisioner/iscsi-provisioner.go
volDestroy
func (p *iscsiProvisioner) volDestroy(vol string, pool string) error { client, err := p.getConnection() defer client.Close() if err != nil { log.Warnln(err) return err } args := volDestroyArgs{ Pool: pool, Name: vol, } err = client.Call("vol_destroy", args, nil) return err }
go
func (p *iscsiProvisioner) volDestroy(vol string, pool string) error { client, err := p.getConnection() defer client.Close() if err != nil { log.Warnln(err) return err } args := volDestroyArgs{ Pool: pool, Name: vol, } err = client.Call("vol_destroy", args, nil) return err }
[ "func", "(", "p", "*", "iscsiProvisioner", ")", "volDestroy", "(", "vol", "string", ",", "pool", "string", ")", "error", "{", "client", ",", "err", ":=", "p", ".", "getConnection", "(", ")", "\n", "defer", "client", ".", "Close", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Warnln", "(", "err", ")", "\n", "return", "err", "\n", "}", "\n", "args", ":=", "volDestroyArgs", "{", "Pool", ":", "pool", ",", "Name", ":", "vol", ",", "}", "\n", "err", "=", "client", ".", "Call", "(", "\"vol_destroy\"", ",", "args", ",", "nil", ")", "\n", "return", "err", "\n", "}" ]
// volDestroy removes calls vol_destroy targetd API to remove volume.
[ "volDestroy", "removes", "calls", "vol_destroy", "targetd", "API", "to", "remove", "volume", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/iscsi/targetd/provisioner/iscsi-provisioner.go#L351-L364
train
kubernetes-incubator/external-storage
iscsi/targetd/provisioner/iscsi-provisioner.go
exportDestroy
func (p *iscsiProvisioner) exportDestroy(vol string, pool string, initiator string) error { client, err := p.getConnection() defer client.Close() if err != nil { log.Warnln(err) return err } args := exportDestroyArgs{ Pool: pool, Vol: vol, InitiatorWwn: initiator, } err = client.Call("export_destroy", args, nil) return err }
go
func (p *iscsiProvisioner) exportDestroy(vol string, pool string, initiator string) error { client, err := p.getConnection() defer client.Close() if err != nil { log.Warnln(err) return err } args := exportDestroyArgs{ Pool: pool, Vol: vol, InitiatorWwn: initiator, } err = client.Call("export_destroy", args, nil) return err }
[ "func", "(", "p", "*", "iscsiProvisioner", ")", "exportDestroy", "(", "vol", "string", ",", "pool", "string", ",", "initiator", "string", ")", "error", "{", "client", ",", "err", ":=", "p", ".", "getConnection", "(", ")", "\n", "defer", "client", ".", "Close", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Warnln", "(", "err", ")", "\n", "return", "err", "\n", "}", "\n", "args", ":=", "exportDestroyArgs", "{", "Pool", ":", "pool", ",", "Vol", ":", "vol", ",", "InitiatorWwn", ":", "initiator", ",", "}", "\n", "err", "=", "client", ".", "Call", "(", "\"export_destroy\"", ",", "args", ",", "nil", ")", "\n", "return", "err", "\n", "}" ]
// exportDestroy calls export_destroy targetd API to remove export of volume.
[ "exportDestroy", "calls", "export_destroy", "targetd", "API", "to", "remove", "export", "of", "volume", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/iscsi/targetd/provisioner/iscsi-provisioner.go#L367-L381
train
kubernetes-incubator/external-storage
iscsi/targetd/provisioner/iscsi-provisioner.go
volCreate
func (p *iscsiProvisioner) volCreate(name string, size int64, pool string) error { client, err := p.getConnection() defer client.Close() if err != nil { log.Warnln(err) return err } args := volCreateArgs{ Pool: pool, Name: name, Size: size, } err = client.Call("vol_create", args, nil) return err }
go
func (p *iscsiProvisioner) volCreate(name string, size int64, pool string) error { client, err := p.getConnection() defer client.Close() if err != nil { log.Warnln(err) return err } args := volCreateArgs{ Pool: pool, Name: name, Size: size, } err = client.Call("vol_create", args, nil) return err }
[ "func", "(", "p", "*", "iscsiProvisioner", ")", "volCreate", "(", "name", "string", ",", "size", "int64", ",", "pool", "string", ")", "error", "{", "client", ",", "err", ":=", "p", ".", "getConnection", "(", ")", "\n", "defer", "client", ".", "Close", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Warnln", "(", "err", ")", "\n", "return", "err", "\n", "}", "\n", "args", ":=", "volCreateArgs", "{", "Pool", ":", "pool", ",", "Name", ":", "name", ",", "Size", ":", "size", ",", "}", "\n", "err", "=", "client", ".", "Call", "(", "\"vol_create\"", ",", "args", ",", "nil", ")", "\n", "return", "err", "\n", "}" ]
// volCreate calls vol_create targetd API to create a volume.
[ "volCreate", "calls", "vol_create", "targetd", "API", "to", "create", "a", "volume", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/iscsi/targetd/provisioner/iscsi-provisioner.go#L384-L398
train
kubernetes-incubator/external-storage
iscsi/targetd/provisioner/iscsi-provisioner.go
exportCreate
func (p *iscsiProvisioner) exportCreate(vol string, lun int32, pool string, initiator string) error { client, err := p.getConnection() defer client.Close() if err != nil { log.Warnln(err) return err } args := exportCreateArgs{ Pool: pool, Vol: vol, InitiatorWwn: initiator, Lun: lun, } err = client.Call("export_create", args, nil) return err }
go
func (p *iscsiProvisioner) exportCreate(vol string, lun int32, pool string, initiator string) error { client, err := p.getConnection() defer client.Close() if err != nil { log.Warnln(err) return err } args := exportCreateArgs{ Pool: pool, Vol: vol, InitiatorWwn: initiator, Lun: lun, } err = client.Call("export_create", args, nil) return err }
[ "func", "(", "p", "*", "iscsiProvisioner", ")", "exportCreate", "(", "vol", "string", ",", "lun", "int32", ",", "pool", "string", ",", "initiator", "string", ")", "error", "{", "client", ",", "err", ":=", "p", ".", "getConnection", "(", ")", "\n", "defer", "client", ".", "Close", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Warnln", "(", "err", ")", "\n", "return", "err", "\n", "}", "\n", "args", ":=", "exportCreateArgs", "{", "Pool", ":", "pool", ",", "Vol", ":", "vol", ",", "InitiatorWwn", ":", "initiator", ",", "Lun", ":", "lun", ",", "}", "\n", "err", "=", "client", ".", "Call", "(", "\"export_create\"", ",", "args", ",", "nil", ")", "\n", "return", "err", "\n", "}" ]
// exportCreate calls export_create targetd API to create an export of volume.
[ "exportCreate", "calls", "export_create", "targetd", "API", "to", "create", "an", "export", "of", "volume", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/iscsi/targetd/provisioner/iscsi-provisioner.go#L401-L416
train
kubernetes-incubator/external-storage
iscsi/targetd/provisioner/iscsi-provisioner.go
exportList
func (p *iscsiProvisioner) exportList() (exportList, error) { client, err := p.getConnection() defer client.Close() if err != nil { log.Warnln(err) return nil, err } var result1 exportList err = client.Call("export_list", nil, &result1) return result1, err }
go
func (p *iscsiProvisioner) exportList() (exportList, error) { client, err := p.getConnection() defer client.Close() if err != nil { log.Warnln(err) return nil, err } var result1 exportList err = client.Call("export_list", nil, &result1) return result1, err }
[ "func", "(", "p", "*", "iscsiProvisioner", ")", "exportList", "(", ")", "(", "exportList", ",", "error", ")", "{", "client", ",", "err", ":=", "p", ".", "getConnection", "(", ")", "\n", "defer", "client", ".", "Close", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Warnln", "(", "err", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n", "var", "result1", "exportList", "\n", "err", "=", "client", ".", "Call", "(", "\"export_list\"", ",", "nil", ",", "&", "result1", ")", "\n", "return", "result1", ",", "err", "\n", "}" ]
// exportList lists calls export_list targetd API to get export objects.
[ "exportList", "lists", "calls", "export_list", "targetd", "API", "to", "get", "export", "objects", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/iscsi/targetd/provisioner/iscsi-provisioner.go#L419-L429
train
kubernetes-incubator/external-storage
repo-infra/kazel/sourcerer.go
walkSource
func (v *Vendorer) walkSource(pkgPath string) ([]string, error) { // clean pkgPath since we access v.newRules directly pkgPath = filepath.Clean(pkgPath) for _, r := range v.skippedPaths { if r.Match([]byte(pkgPath)) { return nil, nil } } files, err := ioutil.ReadDir(pkgPath) if err != nil { return nil, err } // Find any children packages we need to include in an all-srcs rule. var children []string for _, f := range files { if f.IsDir() { c, err := v.walkSource(filepath.Join(pkgPath, f.Name())) if err != nil { return nil, err } children = append(children, c...) } } // This path is a package either if we've added rules or if a BUILD file already exists. _, hasRules := v.newRules[pkgPath] isPkg := hasRules if !isPkg { isPkg, _ = findBuildFile(pkgPath) } if !isPkg { // This directory isn't a package (doesn't contain a BUILD file), // but there might be subdirectories that are packages, // so pass that up to our parent. return children, nil } // Enforce formatting the BUILD file, even if we're not adding srcs rules if !hasRules { v.addRules(pkgPath, nil) } if !v.cfg.AddSourcesRules { return nil, nil } pkgSrcsExpr := &bzl.LiteralExpr{Token: `glob(["**"])`} if pkgPath == "." { pkgSrcsExpr = &bzl.LiteralExpr{Token: `glob(["**"], exclude=["bazel-*/**", ".git/**"])`} } v.addRules(pkgPath, []*bzl.Rule{ newRule(RuleTypeFileGroup, func(_ ruleType) string { return pkgSrcsTarget }, map[string]bzl.Expr{ "srcs": pkgSrcsExpr, "visibility": asExpr([]string{"//visibility:private"}), }), newRule(RuleTypeFileGroup, func(_ ruleType) string { return allSrcsTarget }, map[string]bzl.Expr{ "srcs": asExpr(append(children, fmt.Sprintf(":%s", pkgSrcsTarget))), }), }) return []string{fmt.Sprintf("//%s:%s", pkgPath, allSrcsTarget)}, nil }
go
func (v *Vendorer) walkSource(pkgPath string) ([]string, error) { // clean pkgPath since we access v.newRules directly pkgPath = filepath.Clean(pkgPath) for _, r := range v.skippedPaths { if r.Match([]byte(pkgPath)) { return nil, nil } } files, err := ioutil.ReadDir(pkgPath) if err != nil { return nil, err } // Find any children packages we need to include in an all-srcs rule. var children []string for _, f := range files { if f.IsDir() { c, err := v.walkSource(filepath.Join(pkgPath, f.Name())) if err != nil { return nil, err } children = append(children, c...) } } // This path is a package either if we've added rules or if a BUILD file already exists. _, hasRules := v.newRules[pkgPath] isPkg := hasRules if !isPkg { isPkg, _ = findBuildFile(pkgPath) } if !isPkg { // This directory isn't a package (doesn't contain a BUILD file), // but there might be subdirectories that are packages, // so pass that up to our parent. return children, nil } // Enforce formatting the BUILD file, even if we're not adding srcs rules if !hasRules { v.addRules(pkgPath, nil) } if !v.cfg.AddSourcesRules { return nil, nil } pkgSrcsExpr := &bzl.LiteralExpr{Token: `glob(["**"])`} if pkgPath == "." { pkgSrcsExpr = &bzl.LiteralExpr{Token: `glob(["**"], exclude=["bazel-*/**", ".git/**"])`} } v.addRules(pkgPath, []*bzl.Rule{ newRule(RuleTypeFileGroup, func(_ ruleType) string { return pkgSrcsTarget }, map[string]bzl.Expr{ "srcs": pkgSrcsExpr, "visibility": asExpr([]string{"//visibility:private"}), }), newRule(RuleTypeFileGroup, func(_ ruleType) string { return allSrcsTarget }, map[string]bzl.Expr{ "srcs": asExpr(append(children, fmt.Sprintf(":%s", pkgSrcsTarget))), }), }) return []string{fmt.Sprintf("//%s:%s", pkgPath, allSrcsTarget)}, nil }
[ "func", "(", "v", "*", "Vendorer", ")", "walkSource", "(", "pkgPath", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "pkgPath", "=", "filepath", ".", "Clean", "(", "pkgPath", ")", "\n", "for", "_", ",", "r", ":=", "range", "v", ".", "skippedPaths", "{", "if", "r", ".", "Match", "(", "[", "]", "byte", "(", "pkgPath", ")", ")", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "}", "\n", "files", ",", "err", ":=", "ioutil", ".", "ReadDir", "(", "pkgPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "var", "children", "[", "]", "string", "\n", "for", "_", ",", "f", ":=", "range", "files", "{", "if", "f", ".", "IsDir", "(", ")", "{", "c", ",", "err", ":=", "v", ".", "walkSource", "(", "filepath", ".", "Join", "(", "pkgPath", ",", "f", ".", "Name", "(", ")", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "children", "=", "append", "(", "children", ",", "c", "...", ")", "\n", "}", "\n", "}", "\n", "_", ",", "hasRules", ":=", "v", ".", "newRules", "[", "pkgPath", "]", "\n", "isPkg", ":=", "hasRules", "\n", "if", "!", "isPkg", "{", "isPkg", ",", "_", "=", "findBuildFile", "(", "pkgPath", ")", "\n", "}", "\n", "if", "!", "isPkg", "{", "return", "children", ",", "nil", "\n", "}", "\n", "if", "!", "hasRules", "{", "v", ".", "addRules", "(", "pkgPath", ",", "nil", ")", "\n", "}", "\n", "if", "!", "v", ".", "cfg", ".", "AddSourcesRules", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "pkgSrcsExpr", ":=", "&", "bzl", ".", "LiteralExpr", "{", "Token", ":", "`glob([\"**\"])`", "}", "\n", "if", "pkgPath", "==", "\".\"", "{", "pkgSrcsExpr", "=", "&", "bzl", ".", "LiteralExpr", "{", "Token", ":", "`glob([\"**\"], exclude=[\"bazel-*/**\", \".git/**\"])`", "}", "\n", "}", "\n", "v", ".", "addRules", "(", "pkgPath", ",", "[", "]", "*", "bzl", ".", "Rule", "{", "newRule", "(", "RuleTypeFileGroup", ",", "func", "(", "_", "ruleType", ")", "string", "{", "return", "pkgSrcsTarget", "}", ",", "map", "[", "string", "]", "bzl", ".", "Expr", "{", "\"srcs\"", ":", "pkgSrcsExpr", ",", "\"visibility\"", ":", "asExpr", "(", "[", "]", "string", "{", "\"//visibility:private\"", "}", ")", ",", "}", ")", ",", "newRule", "(", "RuleTypeFileGroup", ",", "func", "(", "_", "ruleType", ")", "string", "{", "return", "allSrcsTarget", "}", ",", "map", "[", "string", "]", "bzl", ".", "Expr", "{", "\"srcs\"", ":", "asExpr", "(", "append", "(", "children", ",", "fmt", ".", "Sprintf", "(", "\":%s\"", ",", "pkgSrcsTarget", ")", ")", ")", ",", "}", ")", ",", "}", ")", "\n", "return", "[", "]", "string", "{", "fmt", ".", "Sprintf", "(", "\"//%s:%s\"", ",", "pkgPath", ",", "allSrcsTarget", ")", "}", ",", "nil", "\n", "}" ]
// walkSource walks the source tree recursively from pkgPath, adding // any BUILD files to v.newRules to be formatted. // // If AddSourcesRules is enabled in the kazel config, then we additionally add // package-sources and recursive all-srcs filegroups rules to every BUILD file. // // Returns the list of children all-srcs targets that should be added to the // all-srcs rule of the enclosing package.
[ "walkSource", "walks", "the", "source", "tree", "recursively", "from", "pkgPath", "adding", "any", "BUILD", "files", "to", "v", ".", "newRules", "to", "be", "formatted", ".", "If", "AddSourcesRules", "is", "enabled", "in", "the", "kazel", "config", "then", "we", "additionally", "add", "package", "-", "sources", "and", "recursive", "all", "-", "srcs", "filegroups", "rules", "to", "every", "BUILD", "file", ".", "Returns", "the", "list", "of", "children", "all", "-", "srcs", "targets", "that", "should", "be", "added", "to", "the", "all", "-", "srcs", "rule", "of", "the", "enclosing", "package", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/repo-infra/kazel/sourcerer.go#L40-L107
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/openstack/openstack_client.go
NewNetworkV2
func (os *OpenStack) NewNetworkV2() (*gophercloud.ServiceClient, error) { network, err := openstack.NewNetworkV2(os.provider, gophercloud.EndpointOpts{ Region: os.region, }) if err != nil { glog.Warningf("Failed to find network v2 endpoint: %v", err) return nil, err } return network, nil }
go
func (os *OpenStack) NewNetworkV2() (*gophercloud.ServiceClient, error) { network, err := openstack.NewNetworkV2(os.provider, gophercloud.EndpointOpts{ Region: os.region, }) if err != nil { glog.Warningf("Failed to find network v2 endpoint: %v", err) return nil, err } return network, nil }
[ "func", "(", "os", "*", "OpenStack", ")", "NewNetworkV2", "(", ")", "(", "*", "gophercloud", ".", "ServiceClient", ",", "error", ")", "{", "network", ",", "err", ":=", "openstack", ".", "NewNetworkV2", "(", "os", ".", "provider", ",", "gophercloud", ".", "EndpointOpts", "{", "Region", ":", "os", ".", "region", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "glog", ".", "Warningf", "(", "\"Failed to find network v2 endpoint: %v\"", ",", "err", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n", "return", "network", ",", "nil", "\n", "}" ]
// NewNetworkV2 creates a new Network V2 endpoint
[ "NewNetworkV2", "creates", "a", "new", "Network", "V2", "endpoint" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/openstack/openstack_client.go#L27-L36
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/openstack/openstack_client.go
NewComputeV2
func (os *OpenStack) NewComputeV2() (*gophercloud.ServiceClient, error) { compute, err := openstack.NewComputeV2(os.provider, gophercloud.EndpointOpts{ Region: os.region, }) if err != nil { glog.Warningf("Failed to find compute v2 endpoint: %v", err) return nil, err } return compute, nil }
go
func (os *OpenStack) NewComputeV2() (*gophercloud.ServiceClient, error) { compute, err := openstack.NewComputeV2(os.provider, gophercloud.EndpointOpts{ Region: os.region, }) if err != nil { glog.Warningf("Failed to find compute v2 endpoint: %v", err) return nil, err } return compute, nil }
[ "func", "(", "os", "*", "OpenStack", ")", "NewComputeV2", "(", ")", "(", "*", "gophercloud", ".", "ServiceClient", ",", "error", ")", "{", "compute", ",", "err", ":=", "openstack", ".", "NewComputeV2", "(", "os", ".", "provider", ",", "gophercloud", ".", "EndpointOpts", "{", "Region", ":", "os", ".", "region", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "glog", ".", "Warningf", "(", "\"Failed to find compute v2 endpoint: %v\"", ",", "err", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n", "return", "compute", ",", "nil", "\n", "}" ]
// NewComputeV2 creates a new Compute V2 endpoint
[ "NewComputeV2", "creates", "a", "new", "Compute", "V2", "endpoint" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/openstack/openstack_client.go#L39-L48
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/openstack/openstack_volumes.go
OperationPending
func (os *OpenStack) OperationPending(diskName string) (bool, string, error) { volume, err := os.getVolume(diskName) if err != nil { return false, "", err } volumeStatus := volume.Status if volumeStatus == VolumeErrorStatus { glog.Errorf("status of volume %s is %s", diskName, volumeStatus) return false, volumeStatus, nil } if volumeStatus == VolumeAvailableStatus || volumeStatus == VolumeInUseStatus || volumeStatus == VolumeDeletedStatus { return false, volume.Status, nil } return true, volumeStatus, nil }
go
func (os *OpenStack) OperationPending(diskName string) (bool, string, error) { volume, err := os.getVolume(diskName) if err != nil { return false, "", err } volumeStatus := volume.Status if volumeStatus == VolumeErrorStatus { glog.Errorf("status of volume %s is %s", diskName, volumeStatus) return false, volumeStatus, nil } if volumeStatus == VolumeAvailableStatus || volumeStatus == VolumeInUseStatus || volumeStatus == VolumeDeletedStatus { return false, volume.Status, nil } return true, volumeStatus, nil }
[ "func", "(", "os", "*", "OpenStack", ")", "OperationPending", "(", "diskName", "string", ")", "(", "bool", ",", "string", ",", "error", ")", "{", "volume", ",", "err", ":=", "os", ".", "getVolume", "(", "diskName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "\"\"", ",", "err", "\n", "}", "\n", "volumeStatus", ":=", "volume", ".", "Status", "\n", "if", "volumeStatus", "==", "VolumeErrorStatus", "{", "glog", ".", "Errorf", "(", "\"status of volume %s is %s\"", ",", "diskName", ",", "volumeStatus", ")", "\n", "return", "false", ",", "volumeStatus", ",", "nil", "\n", "}", "\n", "if", "volumeStatus", "==", "VolumeAvailableStatus", "||", "volumeStatus", "==", "VolumeInUseStatus", "||", "volumeStatus", "==", "VolumeDeletedStatus", "{", "return", "false", ",", "volume", ".", "Status", ",", "nil", "\n", "}", "\n", "return", "true", ",", "volumeStatus", ",", "nil", "\n", "}" ]
// OperationPending checks status, makes sure we're not in error state
[ "OperationPending", "checks", "status", "makes", "sure", "we", "re", "not", "in", "error", "state" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/openstack/openstack_volumes.go#L135-L149
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/openstack/openstack_volumes.go
AttachDisk
func (os *OpenStack) AttachDisk(instanceID, volumeID string) (string, error) { volume, err := os.getVolume(volumeID) if err != nil { return "", err } if volume.Status != VolumeAvailableStatus { errmsg := fmt.Sprintf("volume %s status is %s, not %s, can not be attached to instance %s.", volume.Name, volume.Status, VolumeAvailableStatus, instanceID) glog.Error(errmsg) return "", errors.New(errmsg) } cClient, err := os.NewComputeV2() if err != nil { return "", err } if volume.AttachedServerID != "" { if instanceID == volume.AttachedServerID { glog.V(4).Infof("Disk %s is already attached to instance %s", volumeID, instanceID) return volume.ID, nil } glog.V(2).Infof("Disk %s is attached to a different instance (%s), detaching", volumeID, volume.AttachedServerID) err = os.DetachDisk(volume.AttachedServerID, volumeID) if err != nil { return "", err } } // add read only flag here if possible spothanis _, err = volumeattach.Create(cClient, instanceID, &volumeattach.CreateOpts{ VolumeID: volume.ID, }).Extract() if err != nil { glog.Errorf("Failed to attach %s volume to %s compute: %v", volumeID, instanceID, err) return "", err } glog.V(2).Infof("Successfully attached %s volume to %s compute", volumeID, instanceID) return volume.ID, nil }
go
func (os *OpenStack) AttachDisk(instanceID, volumeID string) (string, error) { volume, err := os.getVolume(volumeID) if err != nil { return "", err } if volume.Status != VolumeAvailableStatus { errmsg := fmt.Sprintf("volume %s status is %s, not %s, can not be attached to instance %s.", volume.Name, volume.Status, VolumeAvailableStatus, instanceID) glog.Error(errmsg) return "", errors.New(errmsg) } cClient, err := os.NewComputeV2() if err != nil { return "", err } if volume.AttachedServerID != "" { if instanceID == volume.AttachedServerID { glog.V(4).Infof("Disk %s is already attached to instance %s", volumeID, instanceID) return volume.ID, nil } glog.V(2).Infof("Disk %s is attached to a different instance (%s), detaching", volumeID, volume.AttachedServerID) err = os.DetachDisk(volume.AttachedServerID, volumeID) if err != nil { return "", err } } // add read only flag here if possible spothanis _, err = volumeattach.Create(cClient, instanceID, &volumeattach.CreateOpts{ VolumeID: volume.ID, }).Extract() if err != nil { glog.Errorf("Failed to attach %s volume to %s compute: %v", volumeID, instanceID, err) return "", err } glog.V(2).Infof("Successfully attached %s volume to %s compute", volumeID, instanceID) return volume.ID, nil }
[ "func", "(", "os", "*", "OpenStack", ")", "AttachDisk", "(", "instanceID", ",", "volumeID", "string", ")", "(", "string", ",", "error", ")", "{", "volume", ",", "err", ":=", "os", ".", "getVolume", "(", "volumeID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "err", "\n", "}", "\n", "if", "volume", ".", "Status", "!=", "VolumeAvailableStatus", "{", "errmsg", ":=", "fmt", ".", "Sprintf", "(", "\"volume %s status is %s, not %s, can not be attached to instance %s.\"", ",", "volume", ".", "Name", ",", "volume", ".", "Status", ",", "VolumeAvailableStatus", ",", "instanceID", ")", "\n", "glog", ".", "Error", "(", "errmsg", ")", "\n", "return", "\"\"", ",", "errors", ".", "New", "(", "errmsg", ")", "\n", "}", "\n", "cClient", ",", "err", ":=", "os", ".", "NewComputeV2", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "err", "\n", "}", "\n", "if", "volume", ".", "AttachedServerID", "!=", "\"\"", "{", "if", "instanceID", "==", "volume", ".", "AttachedServerID", "{", "glog", ".", "V", "(", "4", ")", ".", "Infof", "(", "\"Disk %s is already attached to instance %s\"", ",", "volumeID", ",", "instanceID", ")", "\n", "return", "volume", ".", "ID", ",", "nil", "\n", "}", "\n", "glog", ".", "V", "(", "2", ")", ".", "Infof", "(", "\"Disk %s is attached to a different instance (%s), detaching\"", ",", "volumeID", ",", "volume", ".", "AttachedServerID", ")", "\n", "err", "=", "os", ".", "DetachDisk", "(", "volume", ".", "AttachedServerID", ",", "volumeID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "err", "\n", "}", "\n", "}", "\n", "_", ",", "err", "=", "volumeattach", ".", "Create", "(", "cClient", ",", "instanceID", ",", "&", "volumeattach", ".", "CreateOpts", "{", "VolumeID", ":", "volume", ".", "ID", ",", "}", ")", ".", "Extract", "(", ")", "\n", "if", "err", "!=", "nil", "{", "glog", ".", "Errorf", "(", "\"Failed to attach %s volume to %s compute: %v\"", ",", "volumeID", ",", "instanceID", ",", "err", ")", "\n", "return", "\"\"", ",", "err", "\n", "}", "\n", "glog", ".", "V", "(", "2", ")", ".", "Infof", "(", "\"Successfully attached %s volume to %s compute\"", ",", "volumeID", ",", "instanceID", ")", "\n", "return", "volume", ".", "ID", ",", "nil", "\n", "}" ]
// AttachDisk attaches specified cinder volume to the compute running kubelet
[ "AttachDisk", "attaches", "specified", "cinder", "volume", "to", "the", "compute", "running", "kubelet" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/openstack/openstack_volumes.go#L152-L189
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/openstack/openstack_volumes.go
DeleteVolume
func (os *OpenStack) DeleteVolume(volumeID string) error { used, err := os.diskIsUsed(volumeID) if err != nil { return err } if used { msg := fmt.Sprintf("Cannot delete the volume %q, it's still attached to a node", volumeID) return k8sVolume.NewDeletedVolumeInUseError(msg) } volumes, err := os.volumeService("") if err != nil || volumes == nil { glog.Errorf("Unable to initialize cinder client for region: %s", os.region) return err } err = volumes.deleteVolume(volumeID) if err != nil { glog.Errorf("Cannot delete volume %s: %v", volumeID, err) } return nil }
go
func (os *OpenStack) DeleteVolume(volumeID string) error { used, err := os.diskIsUsed(volumeID) if err != nil { return err } if used { msg := fmt.Sprintf("Cannot delete the volume %q, it's still attached to a node", volumeID) return k8sVolume.NewDeletedVolumeInUseError(msg) } volumes, err := os.volumeService("") if err != nil || volumes == nil { glog.Errorf("Unable to initialize cinder client for region: %s", os.region) return err } err = volumes.deleteVolume(volumeID) if err != nil { glog.Errorf("Cannot delete volume %s: %v", volumeID, err) } return nil }
[ "func", "(", "os", "*", "OpenStack", ")", "DeleteVolume", "(", "volumeID", "string", ")", "error", "{", "used", ",", "err", ":=", "os", ".", "diskIsUsed", "(", "volumeID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "used", "{", "msg", ":=", "fmt", ".", "Sprintf", "(", "\"Cannot delete the volume %q, it's still attached to a node\"", ",", "volumeID", ")", "\n", "return", "k8sVolume", ".", "NewDeletedVolumeInUseError", "(", "msg", ")", "\n", "}", "\n", "volumes", ",", "err", ":=", "os", ".", "volumeService", "(", "\"\"", ")", "\n", "if", "err", "!=", "nil", "||", "volumes", "==", "nil", "{", "glog", ".", "Errorf", "(", "\"Unable to initialize cinder client for region: %s\"", ",", "os", ".", "region", ")", "\n", "return", "err", "\n", "}", "\n", "err", "=", "volumes", ".", "deleteVolume", "(", "volumeID", ")", "\n", "if", "err", "!=", "nil", "{", "glog", ".", "Errorf", "(", "\"Cannot delete volume %s: %v\"", ",", "volumeID", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// DeleteVolume deletes the specified volume
[ "DeleteVolume", "deletes", "the", "specified", "volume" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/openstack/openstack_volumes.go#L291-L313
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/openstack/openstack_volumes.go
GetAttachmentDiskPath
func (os *OpenStack) GetAttachmentDiskPath(instanceID, volumeID string) (string, error) { // See issue #33128 - Cinder does not always tell you the right device path, as such // we must only use this value as a last resort. volume, err := os.getVolume(volumeID) if err != nil { return "", err } if volume.Status != VolumeInUseStatus { errmsg := fmt.Sprintf("can not get device path of volume %s, its status is %s.", volume.Name, volume.Status) glog.Error(errmsg) return "", errors.New(errmsg) } if volume.AttachedServerID != "" { if instanceID == volume.AttachedServerID { // Attachment[0]["device"] points to the device path // see http://developer.openstack.org/api-ref-blockstorage-v1.html return volume.AttachedDevice, nil } errMsg := fmt.Sprintf("Disk %q is attached to a different compute: %q, should be detached before proceeding", volumeID, volume.AttachedServerID) glog.Error(errMsg) return "", errors.New(errMsg) } return "", fmt.Errorf("volume %s has no ServerId", volumeID) }
go
func (os *OpenStack) GetAttachmentDiskPath(instanceID, volumeID string) (string, error) { // See issue #33128 - Cinder does not always tell you the right device path, as such // we must only use this value as a last resort. volume, err := os.getVolume(volumeID) if err != nil { return "", err } if volume.Status != VolumeInUseStatus { errmsg := fmt.Sprintf("can not get device path of volume %s, its status is %s.", volume.Name, volume.Status) glog.Error(errmsg) return "", errors.New(errmsg) } if volume.AttachedServerID != "" { if instanceID == volume.AttachedServerID { // Attachment[0]["device"] points to the device path // see http://developer.openstack.org/api-ref-blockstorage-v1.html return volume.AttachedDevice, nil } errMsg := fmt.Sprintf("Disk %q is attached to a different compute: %q, should be detached before proceeding", volumeID, volume.AttachedServerID) glog.Error(errMsg) return "", errors.New(errMsg) } return "", fmt.Errorf("volume %s has no ServerId", volumeID) }
[ "func", "(", "os", "*", "OpenStack", ")", "GetAttachmentDiskPath", "(", "instanceID", ",", "volumeID", "string", ")", "(", "string", ",", "error", ")", "{", "volume", ",", "err", ":=", "os", ".", "getVolume", "(", "volumeID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "err", "\n", "}", "\n", "if", "volume", ".", "Status", "!=", "VolumeInUseStatus", "{", "errmsg", ":=", "fmt", ".", "Sprintf", "(", "\"can not get device path of volume %s, its status is %s.\"", ",", "volume", ".", "Name", ",", "volume", ".", "Status", ")", "\n", "glog", ".", "Error", "(", "errmsg", ")", "\n", "return", "\"\"", ",", "errors", ".", "New", "(", "errmsg", ")", "\n", "}", "\n", "if", "volume", ".", "AttachedServerID", "!=", "\"\"", "{", "if", "instanceID", "==", "volume", ".", "AttachedServerID", "{", "return", "volume", ".", "AttachedDevice", ",", "nil", "\n", "}", "\n", "errMsg", ":=", "fmt", ".", "Sprintf", "(", "\"Disk %q is attached to a different compute: %q, should be detached before proceeding\"", ",", "volumeID", ",", "volume", ".", "AttachedServerID", ")", "\n", "glog", ".", "Error", "(", "errMsg", ")", "\n", "return", "\"\"", ",", "errors", ".", "New", "(", "errMsg", ")", "\n", "}", "\n", "return", "\"\"", ",", "fmt", ".", "Errorf", "(", "\"volume %s has no ServerId\"", ",", "volumeID", ")", "\n", "}" ]
// GetAttachmentDiskPath retrieves device path of attached volume to the compute running kubelet, as known by cinder
[ "GetAttachmentDiskPath", "retrieves", "device", "path", "of", "attached", "volume", "to", "the", "compute", "running", "kubelet", "as", "known", "by", "cinder" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/openstack/openstack_volumes.go#L316-L339
train
kubernetes-incubator/external-storage
local-volume/provisioner/pkg/populator/populator.go
NewPopulator
func NewPopulator(config *common.RuntimeConfig) *Populator { p := &Populator{RuntimeConfig: config} sharedInformer := config.InformerFactory.Core().V1().PersistentVolumes() sharedInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { pv, ok := obj.(*v1.PersistentVolume) if !ok { glog.Errorf("Added object is not a v1.PersistentVolume type") return } p.handlePVUpdate(pv) }, UpdateFunc: func(oldObj, newObj interface{}) { newPV, ok := newObj.(*v1.PersistentVolume) if !ok { glog.Errorf("Updated object is not a v1.PersistentVolume type") return } p.handlePVUpdate(newPV) }, DeleteFunc: func(obj interface{}) { pv, ok := obj.(*v1.PersistentVolume) if !ok { glog.Errorf("Added object is not a v1.PersistentVolume type") return } p.handlePVDelete(pv) }, }) return p }
go
func NewPopulator(config *common.RuntimeConfig) *Populator { p := &Populator{RuntimeConfig: config} sharedInformer := config.InformerFactory.Core().V1().PersistentVolumes() sharedInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { pv, ok := obj.(*v1.PersistentVolume) if !ok { glog.Errorf("Added object is not a v1.PersistentVolume type") return } p.handlePVUpdate(pv) }, UpdateFunc: func(oldObj, newObj interface{}) { newPV, ok := newObj.(*v1.PersistentVolume) if !ok { glog.Errorf("Updated object is not a v1.PersistentVolume type") return } p.handlePVUpdate(newPV) }, DeleteFunc: func(obj interface{}) { pv, ok := obj.(*v1.PersistentVolume) if !ok { glog.Errorf("Added object is not a v1.PersistentVolume type") return } p.handlePVDelete(pv) }, }) return p }
[ "func", "NewPopulator", "(", "config", "*", "common", ".", "RuntimeConfig", ")", "*", "Populator", "{", "p", ":=", "&", "Populator", "{", "RuntimeConfig", ":", "config", "}", "\n", "sharedInformer", ":=", "config", ".", "InformerFactory", ".", "Core", "(", ")", ".", "V1", "(", ")", ".", "PersistentVolumes", "(", ")", "\n", "sharedInformer", ".", "Informer", "(", ")", ".", "AddEventHandler", "(", "cache", ".", "ResourceEventHandlerFuncs", "{", "AddFunc", ":", "func", "(", "obj", "interface", "{", "}", ")", "{", "pv", ",", "ok", ":=", "obj", ".", "(", "*", "v1", ".", "PersistentVolume", ")", "\n", "if", "!", "ok", "{", "glog", ".", "Errorf", "(", "\"Added object is not a v1.PersistentVolume type\"", ")", "\n", "return", "\n", "}", "\n", "p", ".", "handlePVUpdate", "(", "pv", ")", "\n", "}", ",", "UpdateFunc", ":", "func", "(", "oldObj", ",", "newObj", "interface", "{", "}", ")", "{", "newPV", ",", "ok", ":=", "newObj", ".", "(", "*", "v1", ".", "PersistentVolume", ")", "\n", "if", "!", "ok", "{", "glog", ".", "Errorf", "(", "\"Updated object is not a v1.PersistentVolume type\"", ")", "\n", "return", "\n", "}", "\n", "p", ".", "handlePVUpdate", "(", "newPV", ")", "\n", "}", ",", "DeleteFunc", ":", "func", "(", "obj", "interface", "{", "}", ")", "{", "pv", ",", "ok", ":=", "obj", ".", "(", "*", "v1", ".", "PersistentVolume", ")", "\n", "if", "!", "ok", "{", "glog", ".", "Errorf", "(", "\"Added object is not a v1.PersistentVolume type\"", ")", "\n", "return", "\n", "}", "\n", "p", ".", "handlePVDelete", "(", "pv", ")", "\n", "}", ",", "}", ")", "\n", "return", "p", "\n", "}" ]
// NewPopulator returns a Populator object to update the PV cache
[ "NewPopulator", "returns", "a", "Populator", "object", "to", "update", "the", "PV", "cache" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/populator/populator.go#L33-L63
train
kubernetes-incubator/external-storage
local-volume/provisioner/pkg/util/volume_util.go
IsDir
func (u *volumeUtil) IsDir(fullPath string) (bool, error) { dir, err := os.Open(fullPath) if err != nil { return false, err } defer dir.Close() stat, err := dir.Stat() if err != nil { return false, err } return stat.IsDir(), nil }
go
func (u *volumeUtil) IsDir(fullPath string) (bool, error) { dir, err := os.Open(fullPath) if err != nil { return false, err } defer dir.Close() stat, err := dir.Stat() if err != nil { return false, err } return stat.IsDir(), nil }
[ "func", "(", "u", "*", "volumeUtil", ")", "IsDir", "(", "fullPath", "string", ")", "(", "bool", ",", "error", ")", "{", "dir", ",", "err", ":=", "os", ".", "Open", "(", "fullPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "defer", "dir", ".", "Close", "(", ")", "\n", "stat", ",", "err", ":=", "dir", ".", "Stat", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "return", "stat", ".", "IsDir", "(", ")", ",", "nil", "\n", "}" ]
// IsDir checks if the given path is a directory
[ "IsDir", "checks", "if", "the", "given", "path", "is", "a", "directory" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/util/volume_util.go#L61-L74
train
kubernetes-incubator/external-storage
local-volume/provisioner/pkg/util/volume_util.go
ReadDir
func (u *volumeUtil) ReadDir(fullPath string) ([]string, error) { dir, err := os.Open(fullPath) if err != nil { return nil, err } defer dir.Close() files, err := dir.Readdirnames(-1) if err != nil { return nil, err } return files, nil }
go
func (u *volumeUtil) ReadDir(fullPath string) ([]string, error) { dir, err := os.Open(fullPath) if err != nil { return nil, err } defer dir.Close() files, err := dir.Readdirnames(-1) if err != nil { return nil, err } return files, nil }
[ "func", "(", "u", "*", "volumeUtil", ")", "ReadDir", "(", "fullPath", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "dir", ",", "err", ":=", "os", ".", "Open", "(", "fullPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "dir", ".", "Close", "(", ")", "\n", "files", ",", "err", ":=", "dir", ".", "Readdirnames", "(", "-", "1", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "files", ",", "nil", "\n", "}" ]
// ReadDir returns a list all the files under the given directory
[ "ReadDir", "returns", "a", "list", "all", "the", "files", "under", "the", "given", "directory" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/util/volume_util.go#L77-L89
train
kubernetes-incubator/external-storage
local-volume/provisioner/pkg/util/volume_util.go
DeleteContents
func (u *volumeUtil) DeleteContents(fullPath string) error { dir, err := os.Open(fullPath) if err != nil { return err } defer dir.Close() files, err := dir.Readdirnames(-1) if err != nil { return err } errList := []error{} for _, file := range files { err = os.RemoveAll(filepath.Join(fullPath, file)) if err != nil { errList = append(errList, err) } } return utilerrors.NewAggregate(errList) }
go
func (u *volumeUtil) DeleteContents(fullPath string) error { dir, err := os.Open(fullPath) if err != nil { return err } defer dir.Close() files, err := dir.Readdirnames(-1) if err != nil { return err } errList := []error{} for _, file := range files { err = os.RemoveAll(filepath.Join(fullPath, file)) if err != nil { errList = append(errList, err) } } return utilerrors.NewAggregate(errList) }
[ "func", "(", "u", "*", "volumeUtil", ")", "DeleteContents", "(", "fullPath", "string", ")", "error", "{", "dir", ",", "err", ":=", "os", ".", "Open", "(", "fullPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "dir", ".", "Close", "(", ")", "\n", "files", ",", "err", ":=", "dir", ".", "Readdirnames", "(", "-", "1", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "errList", ":=", "[", "]", "error", "{", "}", "\n", "for", "_", ",", "file", ":=", "range", "files", "{", "err", "=", "os", ".", "RemoveAll", "(", "filepath", ".", "Join", "(", "fullPath", ",", "file", ")", ")", "\n", "if", "err", "!=", "nil", "{", "errList", "=", "append", "(", "errList", ",", "err", ")", "\n", "}", "\n", "}", "\n", "return", "utilerrors", ".", "NewAggregate", "(", "errList", ")", "\n", "}" ]
// DeleteContents deletes all the contents under the given directory
[ "DeleteContents", "deletes", "all", "the", "contents", "under", "the", "given", "directory" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/util/volume_util.go#L92-L112
train
kubernetes-incubator/external-storage
local-volume/provisioner/pkg/util/volume_util.go
GetFsCapacityByte
func (u *volumeUtil) GetFsCapacityByte(fullPath string) (int64, error) { _, capacity, _, _, _, _, err := fs.FsInfo(fullPath) return capacity, err }
go
func (u *volumeUtil) GetFsCapacityByte(fullPath string) (int64, error) { _, capacity, _, _, _, _, err := fs.FsInfo(fullPath) return capacity, err }
[ "func", "(", "u", "*", "volumeUtil", ")", "GetFsCapacityByte", "(", "fullPath", "string", ")", "(", "int64", ",", "error", ")", "{", "_", ",", "capacity", ",", "_", ",", "_", ",", "_", ",", "_", ",", "err", ":=", "fs", ".", "FsInfo", "(", "fullPath", ")", "\n", "return", "capacity", ",", "err", "\n", "}" ]
// GetFsCapacityByte returns capacity in bytes about a mounted filesystem. // fullPath is the pathname of any file within the mounted filesystem. Capacity // returned here is total capacity.
[ "GetFsCapacityByte", "returns", "capacity", "in", "bytes", "about", "a", "mounted", "filesystem", ".", "fullPath", "is", "the", "pathname", "of", "any", "file", "within", "the", "mounted", "filesystem", ".", "Capacity", "returned", "here", "is", "total", "capacity", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/util/volume_util.go#L117-L120
train
kubernetes-incubator/external-storage
local-volume/provisioner/pkg/util/volume_util.go
NewFakeVolumeUtil
func NewFakeVolumeUtil(deleteShouldFail bool, dirFiles map[string][]*FakeDirEntry) *FakeVolumeUtil { return &FakeVolumeUtil{ directoryFiles: dirFiles, deleteShouldFail: deleteShouldFail, } }
go
func NewFakeVolumeUtil(deleteShouldFail bool, dirFiles map[string][]*FakeDirEntry) *FakeVolumeUtil { return &FakeVolumeUtil{ directoryFiles: dirFiles, deleteShouldFail: deleteShouldFail, } }
[ "func", "NewFakeVolumeUtil", "(", "deleteShouldFail", "bool", ",", "dirFiles", "map", "[", "string", "]", "[", "]", "*", "FakeDirEntry", ")", "*", "FakeVolumeUtil", "{", "return", "&", "FakeVolumeUtil", "{", "directoryFiles", ":", "dirFiles", ",", "deleteShouldFail", ":", "deleteShouldFail", ",", "}", "\n", "}" ]
// NewFakeVolumeUtil returns a VolumeUtil object for use in unit testing
[ "NewFakeVolumeUtil", "returns", "a", "VolumeUtil", "object", "for", "use", "in", "unit", "testing" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/util/volume_util.go#L151-L156
train
kubernetes-incubator/external-storage
local-volume/provisioner/pkg/util/volume_util.go
ReadDir
func (u *FakeVolumeUtil) ReadDir(fullPath string) ([]string, error) { fileNames := []string{} files, found := u.directoryFiles[fullPath] if !found { return nil, fmt.Errorf("Directory %q not found", fullPath) } for _, file := range files { fileNames = append(fileNames, file.Name) } return fileNames, nil }
go
func (u *FakeVolumeUtil) ReadDir(fullPath string) ([]string, error) { fileNames := []string{} files, found := u.directoryFiles[fullPath] if !found { return nil, fmt.Errorf("Directory %q not found", fullPath) } for _, file := range files { fileNames = append(fileNames, file.Name) } return fileNames, nil }
[ "func", "(", "u", "*", "FakeVolumeUtil", ")", "ReadDir", "(", "fullPath", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "fileNames", ":=", "[", "]", "string", "{", "}", "\n", "files", ",", "found", ":=", "u", ".", "directoryFiles", "[", "fullPath", "]", "\n", "if", "!", "found", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"Directory %q not found\"", ",", "fullPath", ")", "\n", "}", "\n", "for", "_", ",", "file", ":=", "range", "files", "{", "fileNames", "=", "append", "(", "fileNames", ",", "file", ".", "Name", ")", "\n", "}", "\n", "return", "fileNames", ",", "nil", "\n", "}" ]
// ReadDir returns the list of all files under the given directory
[ "ReadDir", "returns", "the", "list", "of", "all", "files", "under", "the", "given", "directory" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/util/volume_util.go#L197-L207
train
kubernetes-incubator/external-storage
local-volume/provisioner/pkg/util/volume_util.go
DeleteContents
func (u *FakeVolumeUtil) DeleteContents(fullPath string) error { if u.deleteShouldFail { return fmt.Errorf("Fake delete contents failed") } return nil }
go
func (u *FakeVolumeUtil) DeleteContents(fullPath string) error { if u.deleteShouldFail { return fmt.Errorf("Fake delete contents failed") } return nil }
[ "func", "(", "u", "*", "FakeVolumeUtil", ")", "DeleteContents", "(", "fullPath", "string", ")", "error", "{", "if", "u", ".", "deleteShouldFail", "{", "return", "fmt", ".", "Errorf", "(", "\"Fake delete contents failed\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// DeleteContents removes all the contents under the given directory
[ "DeleteContents", "removes", "all", "the", "contents", "under", "the", "given", "directory" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/util/volume_util.go#L210-L215
train
kubernetes-incubator/external-storage
local-volume/provisioner/pkg/util/volume_util.go
GetFsCapacityByte
func (u *FakeVolumeUtil) GetFsCapacityByte(fullPath string) (int64, error) { return u.getDirEntryCapacity(fullPath, FakeEntryFile) }
go
func (u *FakeVolumeUtil) GetFsCapacityByte(fullPath string) (int64, error) { return u.getDirEntryCapacity(fullPath, FakeEntryFile) }
[ "func", "(", "u", "*", "FakeVolumeUtil", ")", "GetFsCapacityByte", "(", "fullPath", "string", ")", "(", "int64", ",", "error", ")", "{", "return", "u", ".", "getDirEntryCapacity", "(", "fullPath", ",", "FakeEntryFile", ")", "\n", "}" ]
// GetFsCapacityByte returns capacity in byte about a mounted filesystem.
[ "GetFsCapacityByte", "returns", "capacity", "in", "byte", "about", "a", "mounted", "filesystem", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/util/volume_util.go#L218-L220
train
kubernetes-incubator/external-storage
local-volume/provisioner/pkg/util/volume_util.go
GetBlockCapacityByte
func (u *FakeVolumeUtil) GetBlockCapacityByte(fullPath string) (int64, error) { return u.getDirEntryCapacity(fullPath, FakeEntryBlock) }
go
func (u *FakeVolumeUtil) GetBlockCapacityByte(fullPath string) (int64, error) { return u.getDirEntryCapacity(fullPath, FakeEntryBlock) }
[ "func", "(", "u", "*", "FakeVolumeUtil", ")", "GetBlockCapacityByte", "(", "fullPath", "string", ")", "(", "int64", ",", "error", ")", "{", "return", "u", ".", "getDirEntryCapacity", "(", "fullPath", ",", "FakeEntryBlock", ")", "\n", "}" ]
// GetBlockCapacityByte returns the space in the specified block device.
[ "GetBlockCapacityByte", "returns", "the", "space", "in", "the", "specified", "block", "device", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/util/volume_util.go#L223-L225
train
kubernetes-incubator/external-storage
local-volume/provisioner/pkg/util/volume_util.go
AddNewDirEntries
func (u *FakeVolumeUtil) AddNewDirEntries(mountDir string, dirFiles map[string][]*FakeDirEntry) { for dir, files := range dirFiles { mountedPath := filepath.Join(mountDir, dir) curFiles := u.directoryFiles[mountedPath] if curFiles == nil { curFiles = []*FakeDirEntry{} } glog.Infof("Adding to directory %q: files %v\n", dir, files) u.directoryFiles[mountedPath] = append(curFiles, files...) } }
go
func (u *FakeVolumeUtil) AddNewDirEntries(mountDir string, dirFiles map[string][]*FakeDirEntry) { for dir, files := range dirFiles { mountedPath := filepath.Join(mountDir, dir) curFiles := u.directoryFiles[mountedPath] if curFiles == nil { curFiles = []*FakeDirEntry{} } glog.Infof("Adding to directory %q: files %v\n", dir, files) u.directoryFiles[mountedPath] = append(curFiles, files...) } }
[ "func", "(", "u", "*", "FakeVolumeUtil", ")", "AddNewDirEntries", "(", "mountDir", "string", ",", "dirFiles", "map", "[", "string", "]", "[", "]", "*", "FakeDirEntry", ")", "{", "for", "dir", ",", "files", ":=", "range", "dirFiles", "{", "mountedPath", ":=", "filepath", ".", "Join", "(", "mountDir", ",", "dir", ")", "\n", "curFiles", ":=", "u", ".", "directoryFiles", "[", "mountedPath", "]", "\n", "if", "curFiles", "==", "nil", "{", "curFiles", "=", "[", "]", "*", "FakeDirEntry", "{", "}", "\n", "}", "\n", "glog", ".", "Infof", "(", "\"Adding to directory %q: files %v\\n\"", ",", "\\n", ",", "dir", ")", "\n", "files", "\n", "}", "\n", "}" ]
// AddNewDirEntries adds the given files to the current directory listing // This is only for testing
[ "AddNewDirEntries", "adds", "the", "given", "files", "to", "the", "current", "directory", "listing", "This", "is", "only", "for", "testing" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/local-volume/provisioner/pkg/util/volume_util.go#L248-L258
train
kubernetes-incubator/external-storage
snapshot/pkg/apis/crd/v1/types.go
GetSupportedVolumeFromPVSpec
func GetSupportedVolumeFromPVSpec(spec *core_v1.PersistentVolumeSpec) string { if spec.HostPath != nil { return "hostPath" } if spec.AWSElasticBlockStore != nil { return "aws_ebs" } if spec.GCEPersistentDisk != nil { return "gce-pd" } if spec.Cinder != nil { return "cinder" } if spec.Glusterfs != nil { return "glusterfs" } return "" }
go
func GetSupportedVolumeFromPVSpec(spec *core_v1.PersistentVolumeSpec) string { if spec.HostPath != nil { return "hostPath" } if spec.AWSElasticBlockStore != nil { return "aws_ebs" } if spec.GCEPersistentDisk != nil { return "gce-pd" } if spec.Cinder != nil { return "cinder" } if spec.Glusterfs != nil { return "glusterfs" } return "" }
[ "func", "GetSupportedVolumeFromPVSpec", "(", "spec", "*", "core_v1", ".", "PersistentVolumeSpec", ")", "string", "{", "if", "spec", ".", "HostPath", "!=", "nil", "{", "return", "\"hostPath\"", "\n", "}", "\n", "if", "spec", ".", "AWSElasticBlockStore", "!=", "nil", "{", "return", "\"aws_ebs\"", "\n", "}", "\n", "if", "spec", ".", "GCEPersistentDisk", "!=", "nil", "{", "return", "\"gce-pd\"", "\n", "}", "\n", "if", "spec", ".", "Cinder", "!=", "nil", "{", "return", "\"cinder\"", "\n", "}", "\n", "if", "spec", ".", "Glusterfs", "!=", "nil", "{", "return", "\"glusterfs\"", "\n", "}", "\n", "return", "\"\"", "\n", "}" ]
// GetSupportedVolumeFromPVSpec gets supported volume from PV spec
[ "GetSupportedVolumeFromPVSpec", "gets", "supported", "volume", "from", "PV", "spec" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/apis/crd/v1/types.go#L261-L278
train
kubernetes-incubator/external-storage
snapshot/pkg/apis/crd/v1/types.go
GetSupportedVolumeFromSnapshotDataSpec
func GetSupportedVolumeFromSnapshotDataSpec(spec *VolumeSnapshotDataSpec) string { if spec.HostPath != nil { return "hostPath" } if spec.AWSElasticBlockStore != nil { return "aws_ebs" } if spec.GCEPersistentDiskSnapshot != nil { return "gce-pd" } if spec.CinderSnapshot != nil { return "cinder" } if spec.GlusterSnapshotVolume != nil { return "glusterfs" } return "" }
go
func GetSupportedVolumeFromSnapshotDataSpec(spec *VolumeSnapshotDataSpec) string { if spec.HostPath != nil { return "hostPath" } if spec.AWSElasticBlockStore != nil { return "aws_ebs" } if spec.GCEPersistentDiskSnapshot != nil { return "gce-pd" } if spec.CinderSnapshot != nil { return "cinder" } if spec.GlusterSnapshotVolume != nil { return "glusterfs" } return "" }
[ "func", "GetSupportedVolumeFromSnapshotDataSpec", "(", "spec", "*", "VolumeSnapshotDataSpec", ")", "string", "{", "if", "spec", ".", "HostPath", "!=", "nil", "{", "return", "\"hostPath\"", "\n", "}", "\n", "if", "spec", ".", "AWSElasticBlockStore", "!=", "nil", "{", "return", "\"aws_ebs\"", "\n", "}", "\n", "if", "spec", ".", "GCEPersistentDiskSnapshot", "!=", "nil", "{", "return", "\"gce-pd\"", "\n", "}", "\n", "if", "spec", ".", "CinderSnapshot", "!=", "nil", "{", "return", "\"cinder\"", "\n", "}", "\n", "if", "spec", ".", "GlusterSnapshotVolume", "!=", "nil", "{", "return", "\"glusterfs\"", "\n", "}", "\n", "return", "\"\"", "\n", "}" ]
// GetSupportedVolumeFromSnapshotDataSpec gets supported volume from snapshot data spec
[ "GetSupportedVolumeFromSnapshotDataSpec", "gets", "supported", "volume", "from", "snapshot", "data", "spec" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/apis/crd/v1/types.go#L281-L298
train
kubernetes-incubator/external-storage
snapshot/pkg/apis/crd/v1/types.go
UnmarshalJSON
func (v *VolumeSnapshot) UnmarshalJSON(data []byte) error { tmp := VolumeSnapshotCopy{} err := json.Unmarshal(data, &tmp) if err != nil { return err } tmp2 := VolumeSnapshot(tmp) *v = tmp2 return nil }
go
func (v *VolumeSnapshot) UnmarshalJSON(data []byte) error { tmp := VolumeSnapshotCopy{} err := json.Unmarshal(data, &tmp) if err != nil { return err } tmp2 := VolumeSnapshot(tmp) *v = tmp2 return nil }
[ "func", "(", "v", "*", "VolumeSnapshot", ")", "UnmarshalJSON", "(", "data", "[", "]", "byte", ")", "error", "{", "tmp", ":=", "VolumeSnapshotCopy", "{", "}", "\n", "err", ":=", "json", ".", "Unmarshal", "(", "data", ",", "&", "tmp", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "tmp2", ":=", "VolumeSnapshot", "(", "tmp", ")", "\n", "*", "v", "=", "tmp2", "\n", "return", "nil", "\n", "}" ]
// UnmarshalJSON unmarshalls json data
[ "UnmarshalJSON", "unmarshalls", "json", "data" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/apis/crd/v1/types.go#L353-L362
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/openstack/openstack_snapshots.go
CreateSnapshot
func (os *OpenStack) CreateSnapshot(sourceVolumeID, name, description string, tags map[string]string) (string, string, error) { snapshots, err := os.snapshotService() if err != nil || snapshots == nil { glog.Errorf("Unable to initialize cinder client for region: %s", os.region) return "", "", fmt.Errorf("Failed to create snapshot for volume %s: %v", sourceVolumeID, err) } opts := SnapshotCreateOpts{ VolumeID: sourceVolumeID, Name: name, Description: description, } if tags != nil { opts.Metadata = tags } snapshotID, status, err := snapshots.createSnapshot(opts) if err != nil { glog.Errorf("Failed to snapshot volume %s : %v", sourceVolumeID, err) return "", "", err } glog.Infof("Created snapshot %v from volume: %v", snapshotID, sourceVolumeID) return snapshotID, status, nil }
go
func (os *OpenStack) CreateSnapshot(sourceVolumeID, name, description string, tags map[string]string) (string, string, error) { snapshots, err := os.snapshotService() if err != nil || snapshots == nil { glog.Errorf("Unable to initialize cinder client for region: %s", os.region) return "", "", fmt.Errorf("Failed to create snapshot for volume %s: %v", sourceVolumeID, err) } opts := SnapshotCreateOpts{ VolumeID: sourceVolumeID, Name: name, Description: description, } if tags != nil { opts.Metadata = tags } snapshotID, status, err := snapshots.createSnapshot(opts) if err != nil { glog.Errorf("Failed to snapshot volume %s : %v", sourceVolumeID, err) return "", "", err } glog.Infof("Created snapshot %v from volume: %v", snapshotID, sourceVolumeID) return snapshotID, status, nil }
[ "func", "(", "os", "*", "OpenStack", ")", "CreateSnapshot", "(", "sourceVolumeID", ",", "name", ",", "description", "string", ",", "tags", "map", "[", "string", "]", "string", ")", "(", "string", ",", "string", ",", "error", ")", "{", "snapshots", ",", "err", ":=", "os", ".", "snapshotService", "(", ")", "\n", "if", "err", "!=", "nil", "||", "snapshots", "==", "nil", "{", "glog", ".", "Errorf", "(", "\"Unable to initialize cinder client for region: %s\"", ",", "os", ".", "region", ")", "\n", "return", "\"\"", ",", "\"\"", ",", "fmt", ".", "Errorf", "(", "\"Failed to create snapshot for volume %s: %v\"", ",", "sourceVolumeID", ",", "err", ")", "\n", "}", "\n", "opts", ":=", "SnapshotCreateOpts", "{", "VolumeID", ":", "sourceVolumeID", ",", "Name", ":", "name", ",", "Description", ":", "description", ",", "}", "\n", "if", "tags", "!=", "nil", "{", "opts", ".", "Metadata", "=", "tags", "\n", "}", "\n", "snapshotID", ",", "status", ",", "err", ":=", "snapshots", ".", "createSnapshot", "(", "opts", ")", "\n", "if", "err", "!=", "nil", "{", "glog", ".", "Errorf", "(", "\"Failed to snapshot volume %s : %v\"", ",", "sourceVolumeID", ",", "err", ")", "\n", "return", "\"\"", ",", "\"\"", ",", "err", "\n", "}", "\n", "glog", ".", "Infof", "(", "\"Created snapshot %v from volume: %v\"", ",", "snapshotID", ",", "sourceVolumeID", ")", "\n", "return", "snapshotID", ",", "status", ",", "nil", "\n", "}" ]
// CreateSnapshot from the specified volume
[ "CreateSnapshot", "from", "the", "specified", "volume" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/openstack/openstack_snapshots.go#L144-L169
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/openstack/openstack_snapshots.go
DeleteSnapshot
func (os *OpenStack) DeleteSnapshot(snapshotID string) error { snapshots, err := os.snapshotService() if err != nil || snapshots == nil { glog.Errorf("Unable to initialize cinder client for region: %s", os.region) return err } err = snapshots.deleteSnapshot(snapshotID) if err != nil { glog.Errorf("Cannot delete snapshot %s: %v", snapshotID, err) } return nil }
go
func (os *OpenStack) DeleteSnapshot(snapshotID string) error { snapshots, err := os.snapshotService() if err != nil || snapshots == nil { glog.Errorf("Unable to initialize cinder client for region: %s", os.region) return err } err = snapshots.deleteSnapshot(snapshotID) if err != nil { glog.Errorf("Cannot delete snapshot %s: %v", snapshotID, err) } return nil }
[ "func", "(", "os", "*", "OpenStack", ")", "DeleteSnapshot", "(", "snapshotID", "string", ")", "error", "{", "snapshots", ",", "err", ":=", "os", ".", "snapshotService", "(", ")", "\n", "if", "err", "!=", "nil", "||", "snapshots", "==", "nil", "{", "glog", ".", "Errorf", "(", "\"Unable to initialize cinder client for region: %s\"", ",", "os", ".", "region", ")", "\n", "return", "err", "\n", "}", "\n", "err", "=", "snapshots", ".", "deleteSnapshot", "(", "snapshotID", ")", "\n", "if", "err", "!=", "nil", "{", "glog", ".", "Errorf", "(", "\"Cannot delete snapshot %s: %v\"", ",", "snapshotID", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// DeleteSnapshot deletes the specified snapshot
[ "DeleteSnapshot", "deletes", "the", "specified", "snapshot" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/openstack/openstack_snapshots.go#L172-L184
train
kubernetes-incubator/external-storage
snapshot/pkg/cloudprovider/providers/openstack/openstack_snapshots.go
FindSnapshot
func (os *OpenStack) FindSnapshot(tags map[string]string) ([]string, []string, error) { var snapshotIDs, statuses []string ss, err := os.snapshotService() if err != nil || ss == nil { glog.Errorf("Unable to initialize cinder client for region: %s", os.region) return snapshotIDs, statuses, fmt.Errorf("Failed to find snapshot by tags %v: %v", tags, err) } opts := SnapshotListOpts{} snapshots, err := ss.listSnapshots(opts) if err != nil { glog.Errorf("Failed to list snapshots. Error: %v", err) return snapshotIDs, statuses, err } glog.Infof("Listed [%v] snapshots.", len(snapshots)) glog.Infof("Looking for matching tags [%#v] in snapshots.", tags) // Loop around to find the snapshot with the matching input metadata // NOTE(xyang): Metadata based filtering for snapshots is supported by Cinder volume API // microversion 3.21 and above. Currently the OpenStack Cloud Provider only supports V2.0. // Revisit this later when V3.0 is supported. for _, snapshot := range snapshots { glog.Infof("Looking for matching tags in snapshot [%#v].", snapshot) namespaceVal, ok := snapshot.Metadata[ctrlsnap.CloudSnapshotCreatedForVolumeSnapshotNamespaceTag] if ok { if tags[ctrlsnap.CloudSnapshotCreatedForVolumeSnapshotNamespaceTag] == namespaceVal { nameVal, ok := snapshot.Metadata[ctrlsnap.CloudSnapshotCreatedForVolumeSnapshotNameTag] if ok { if tags[ctrlsnap.CloudSnapshotCreatedForVolumeSnapshotNameTag] == nameVal { uidVal, ok := snapshot.Metadata[ctrlsnap.CloudSnapshotCreatedForVolumeSnapshotUIDTag] if ok { if tags[ctrlsnap.CloudSnapshotCreatedForVolumeSnapshotUIDTag] == uidVal { timeVal, ok := snapshot.Metadata[ctrlsnap.CloudSnapshotCreatedForVolumeSnapshotTimestampTag] if ok { if tags[ctrlsnap.CloudSnapshotCreatedForVolumeSnapshotTimestampTag] == timeVal { snapshotIDs = append(snapshotIDs, snapshot.ID) statuses = append(statuses, snapshot.Status) glog.Infof("Add snapshot [%#v].", snapshot) } } } } } } } } } return snapshotIDs, statuses, nil }
go
func (os *OpenStack) FindSnapshot(tags map[string]string) ([]string, []string, error) { var snapshotIDs, statuses []string ss, err := os.snapshotService() if err != nil || ss == nil { glog.Errorf("Unable to initialize cinder client for region: %s", os.region) return snapshotIDs, statuses, fmt.Errorf("Failed to find snapshot by tags %v: %v", tags, err) } opts := SnapshotListOpts{} snapshots, err := ss.listSnapshots(opts) if err != nil { glog.Errorf("Failed to list snapshots. Error: %v", err) return snapshotIDs, statuses, err } glog.Infof("Listed [%v] snapshots.", len(snapshots)) glog.Infof("Looking for matching tags [%#v] in snapshots.", tags) // Loop around to find the snapshot with the matching input metadata // NOTE(xyang): Metadata based filtering for snapshots is supported by Cinder volume API // microversion 3.21 and above. Currently the OpenStack Cloud Provider only supports V2.0. // Revisit this later when V3.0 is supported. for _, snapshot := range snapshots { glog.Infof("Looking for matching tags in snapshot [%#v].", snapshot) namespaceVal, ok := snapshot.Metadata[ctrlsnap.CloudSnapshotCreatedForVolumeSnapshotNamespaceTag] if ok { if tags[ctrlsnap.CloudSnapshotCreatedForVolumeSnapshotNamespaceTag] == namespaceVal { nameVal, ok := snapshot.Metadata[ctrlsnap.CloudSnapshotCreatedForVolumeSnapshotNameTag] if ok { if tags[ctrlsnap.CloudSnapshotCreatedForVolumeSnapshotNameTag] == nameVal { uidVal, ok := snapshot.Metadata[ctrlsnap.CloudSnapshotCreatedForVolumeSnapshotUIDTag] if ok { if tags[ctrlsnap.CloudSnapshotCreatedForVolumeSnapshotUIDTag] == uidVal { timeVal, ok := snapshot.Metadata[ctrlsnap.CloudSnapshotCreatedForVolumeSnapshotTimestampTag] if ok { if tags[ctrlsnap.CloudSnapshotCreatedForVolumeSnapshotTimestampTag] == timeVal { snapshotIDs = append(snapshotIDs, snapshot.ID) statuses = append(statuses, snapshot.Status) glog.Infof("Add snapshot [%#v].", snapshot) } } } } } } } } } return snapshotIDs, statuses, nil }
[ "func", "(", "os", "*", "OpenStack", ")", "FindSnapshot", "(", "tags", "map", "[", "string", "]", "string", ")", "(", "[", "]", "string", ",", "[", "]", "string", ",", "error", ")", "{", "var", "snapshotIDs", ",", "statuses", "[", "]", "string", "\n", "ss", ",", "err", ":=", "os", ".", "snapshotService", "(", ")", "\n", "if", "err", "!=", "nil", "||", "ss", "==", "nil", "{", "glog", ".", "Errorf", "(", "\"Unable to initialize cinder client for region: %s\"", ",", "os", ".", "region", ")", "\n", "return", "snapshotIDs", ",", "statuses", ",", "fmt", ".", "Errorf", "(", "\"Failed to find snapshot by tags %v: %v\"", ",", "tags", ",", "err", ")", "\n", "}", "\n", "opts", ":=", "SnapshotListOpts", "{", "}", "\n", "snapshots", ",", "err", ":=", "ss", ".", "listSnapshots", "(", "opts", ")", "\n", "if", "err", "!=", "nil", "{", "glog", ".", "Errorf", "(", "\"Failed to list snapshots. Error: %v\"", ",", "err", ")", "\n", "return", "snapshotIDs", ",", "statuses", ",", "err", "\n", "}", "\n", "glog", ".", "Infof", "(", "\"Listed [%v] snapshots.\"", ",", "len", "(", "snapshots", ")", ")", "\n", "glog", ".", "Infof", "(", "\"Looking for matching tags [%#v] in snapshots.\"", ",", "tags", ")", "\n", "for", "_", ",", "snapshot", ":=", "range", "snapshots", "{", "glog", ".", "Infof", "(", "\"Looking for matching tags in snapshot [%#v].\"", ",", "snapshot", ")", "\n", "namespaceVal", ",", "ok", ":=", "snapshot", ".", "Metadata", "[", "ctrlsnap", ".", "CloudSnapshotCreatedForVolumeSnapshotNamespaceTag", "]", "\n", "if", "ok", "{", "if", "tags", "[", "ctrlsnap", ".", "CloudSnapshotCreatedForVolumeSnapshotNamespaceTag", "]", "==", "namespaceVal", "{", "nameVal", ",", "ok", ":=", "snapshot", ".", "Metadata", "[", "ctrlsnap", ".", "CloudSnapshotCreatedForVolumeSnapshotNameTag", "]", "\n", "if", "ok", "{", "if", "tags", "[", "ctrlsnap", ".", "CloudSnapshotCreatedForVolumeSnapshotNameTag", "]", "==", "nameVal", "{", "uidVal", ",", "ok", ":=", "snapshot", ".", "Metadata", "[", "ctrlsnap", ".", "CloudSnapshotCreatedForVolumeSnapshotUIDTag", "]", "\n", "if", "ok", "{", "if", "tags", "[", "ctrlsnap", ".", "CloudSnapshotCreatedForVolumeSnapshotUIDTag", "]", "==", "uidVal", "{", "timeVal", ",", "ok", ":=", "snapshot", ".", "Metadata", "[", "ctrlsnap", ".", "CloudSnapshotCreatedForVolumeSnapshotTimestampTag", "]", "\n", "if", "ok", "{", "if", "tags", "[", "ctrlsnap", ".", "CloudSnapshotCreatedForVolumeSnapshotTimestampTag", "]", "==", "timeVal", "{", "snapshotIDs", "=", "append", "(", "snapshotIDs", ",", "snapshot", ".", "ID", ")", "\n", "statuses", "=", "append", "(", "statuses", ",", "snapshot", ".", "Status", ")", "\n", "glog", ".", "Infof", "(", "\"Add snapshot [%#v].\"", ",", "snapshot", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "snapshotIDs", ",", "statuses", ",", "nil", "\n", "}" ]
// FindSnapshot finds snapshot by metadata
[ "FindSnapshot", "finds", "snapshot", "by", "metadata" ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/cloudprovider/providers/openstack/openstack_snapshots.go#L210-L261
train
kubernetes-incubator/external-storage
repo-infra/kazel/config.go
ReadCfg
func ReadCfg(cfgPath string) (*Cfg, error) { b, err := ioutil.ReadFile(cfgPath) if err != nil { return nil, err } var cfg Cfg if err := json.Unmarshal(b, &cfg); err != nil { return nil, err } defaultCfg(&cfg) return &cfg, nil }
go
func ReadCfg(cfgPath string) (*Cfg, error) { b, err := ioutil.ReadFile(cfgPath) if err != nil { return nil, err } var cfg Cfg if err := json.Unmarshal(b, &cfg); err != nil { return nil, err } defaultCfg(&cfg) return &cfg, nil }
[ "func", "ReadCfg", "(", "cfgPath", "string", ")", "(", "*", "Cfg", ",", "error", ")", "{", "b", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "cfgPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "var", "cfg", "Cfg", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "b", ",", "&", "cfg", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defaultCfg", "(", "&", "cfg", ")", "\n", "return", "&", "cfg", ",", "nil", "\n", "}" ]
// ReadCfg reads and unmarshals the specified json file into a Cfg struct.
[ "ReadCfg", "reads", "and", "unmarshals", "the", "specified", "json", "file", "into", "a", "Cfg", "struct", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/repo-infra/kazel/config.go#L41-L52
train
kubernetes-incubator/external-storage
repo-infra/kazel/generator.go
findOpenAPI
func (v *Vendorer) findOpenAPI(root string) ([]string, error) { finfos, err := ioutil.ReadDir(root) if err != nil { return nil, err } var res []string var includeMe bool for _, finfo := range finfos { path := filepath.Join(root, finfo.Name()) if finfo.IsDir() && (finfo.Mode()&os.ModeSymlink == 0) { children, err := v.findOpenAPI(path) if err != nil { return nil, err } res = append(res, children...) } else if strings.HasSuffix(path, ".go") && !strings.HasSuffix(path, "_test.go") { b, err := ioutil.ReadFile(path) if err != nil { return nil, err } if bytes.Contains(b, []byte(openAPIGenTag)) { includeMe = true } } } if includeMe { pkg, err := v.ctx.ImportDir(root, 0) if err != nil { return nil, err } res = append(res, pkg.ImportPath) } return res, nil }
go
func (v *Vendorer) findOpenAPI(root string) ([]string, error) { finfos, err := ioutil.ReadDir(root) if err != nil { return nil, err } var res []string var includeMe bool for _, finfo := range finfos { path := filepath.Join(root, finfo.Name()) if finfo.IsDir() && (finfo.Mode()&os.ModeSymlink == 0) { children, err := v.findOpenAPI(path) if err != nil { return nil, err } res = append(res, children...) } else if strings.HasSuffix(path, ".go") && !strings.HasSuffix(path, "_test.go") { b, err := ioutil.ReadFile(path) if err != nil { return nil, err } if bytes.Contains(b, []byte(openAPIGenTag)) { includeMe = true } } } if includeMe { pkg, err := v.ctx.ImportDir(root, 0) if err != nil { return nil, err } res = append(res, pkg.ImportPath) } return res, nil }
[ "func", "(", "v", "*", "Vendorer", ")", "findOpenAPI", "(", "root", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "finfos", ",", "err", ":=", "ioutil", ".", "ReadDir", "(", "root", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "var", "res", "[", "]", "string", "\n", "var", "includeMe", "bool", "\n", "for", "_", ",", "finfo", ":=", "range", "finfos", "{", "path", ":=", "filepath", ".", "Join", "(", "root", ",", "finfo", ".", "Name", "(", ")", ")", "\n", "if", "finfo", ".", "IsDir", "(", ")", "&&", "(", "finfo", ".", "Mode", "(", ")", "&", "os", ".", "ModeSymlink", "==", "0", ")", "{", "children", ",", "err", ":=", "v", ".", "findOpenAPI", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "res", "=", "append", "(", "res", ",", "children", "...", ")", "\n", "}", "else", "if", "strings", ".", "HasSuffix", "(", "path", ",", "\".go\"", ")", "&&", "!", "strings", ".", "HasSuffix", "(", "path", ",", "\"_test.go\"", ")", "{", "b", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "bytes", ".", "Contains", "(", "b", ",", "[", "]", "byte", "(", "openAPIGenTag", ")", ")", "{", "includeMe", "=", "true", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "includeMe", "{", "pkg", ",", "err", ":=", "v", ".", "ctx", ".", "ImportDir", "(", "root", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "res", "=", "append", "(", "res", ",", "pkg", ".", "ImportPath", ")", "\n", "}", "\n", "return", "res", ",", "nil", "\n", "}" ]
// findOpenAPI searches for all packages under root that request OpenAPI. It // returns the go import paths. It does not follow symlinks.
[ "findOpenAPI", "searches", "for", "all", "packages", "under", "root", "that", "request", "OpenAPI", ".", "It", "returns", "the", "go", "import", "paths", ".", "It", "does", "not", "follow", "symlinks", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/repo-infra/kazel/generator.go#L54-L87
train
kubernetes-incubator/external-storage
ceph/rbd/pkg/provision/provision.go
NewRBDProvisioner
func NewRBDProvisioner(client kubernetes.Interface, id string, timeout int, usePVName bool) controller.Provisioner { return &rbdProvisioner{ client: client, identity: id, rbdUtil: &RBDUtil{ timeout: timeout, }, usePVName: usePVName, } }
go
func NewRBDProvisioner(client kubernetes.Interface, id string, timeout int, usePVName bool) controller.Provisioner { return &rbdProvisioner{ client: client, identity: id, rbdUtil: &RBDUtil{ timeout: timeout, }, usePVName: usePVName, } }
[ "func", "NewRBDProvisioner", "(", "client", "kubernetes", ".", "Interface", ",", "id", "string", ",", "timeout", "int", ",", "usePVName", "bool", ")", "controller", ".", "Provisioner", "{", "return", "&", "rbdProvisioner", "{", "client", ":", "client", ",", "identity", ":", "id", ",", "rbdUtil", ":", "&", "RBDUtil", "{", "timeout", ":", "timeout", ",", "}", ",", "usePVName", ":", "usePVName", ",", "}", "\n", "}" ]
// NewRBDProvisioner creates a Provisioner that provisions Ceph RBD PVs backed by Ceph RBD images.
[ "NewRBDProvisioner", "creates", "a", "Provisioner", "that", "provisions", "Ceph", "RBD", "PVs", "backed", "by", "Ceph", "RBD", "images", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/ceph/rbd/pkg/provision/provision.go#L94-L103
train
kubernetes-incubator/external-storage
ceph/rbd/pkg/provision/provision.go
getAccessModes
func (p *rbdProvisioner) getAccessModes() []v1.PersistentVolumeAccessMode { return []v1.PersistentVolumeAccessMode{ v1.ReadWriteOnce, v1.ReadOnlyMany, } }
go
func (p *rbdProvisioner) getAccessModes() []v1.PersistentVolumeAccessMode { return []v1.PersistentVolumeAccessMode{ v1.ReadWriteOnce, v1.ReadOnlyMany, } }
[ "func", "(", "p", "*", "rbdProvisioner", ")", "getAccessModes", "(", ")", "[", "]", "v1", ".", "PersistentVolumeAccessMode", "{", "return", "[", "]", "v1", ".", "PersistentVolumeAccessMode", "{", "v1", ".", "ReadWriteOnce", ",", "v1", ".", "ReadOnlyMany", ",", "}", "\n", "}" ]
// getAccessModes returns access modes RBD volume supported.
[ "getAccessModes", "returns", "access", "modes", "RBD", "volume", "supported", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/ceph/rbd/pkg/provision/provision.go#L108-L113
train
kubernetes-incubator/external-storage
ceph/rbd/pkg/provision/provision.go
parsePVSecret
func (p *rbdProvisioner) parsePVSecret(namespace, secretName string) (string, error) { if p.client == nil { return "", fmt.Errorf("Cannot get kube client") } secrets, err := p.client.CoreV1().Secrets(namespace).Get(secretName, metav1.GetOptions{}) if err != nil { return "", err } // TODO: Should we check secret.Type, like `k8s.io/kubernetes/pkg/volume/util.GetSecretForPV` function? secret := "" for k, v := range secrets.Data { if k == secretKeyName { return string(v), nil } secret = string(v) } // If not found, the last secret in the map wins as done before return secret, nil }
go
func (p *rbdProvisioner) parsePVSecret(namespace, secretName string) (string, error) { if p.client == nil { return "", fmt.Errorf("Cannot get kube client") } secrets, err := p.client.CoreV1().Secrets(namespace).Get(secretName, metav1.GetOptions{}) if err != nil { return "", err } // TODO: Should we check secret.Type, like `k8s.io/kubernetes/pkg/volume/util.GetSecretForPV` function? secret := "" for k, v := range secrets.Data { if k == secretKeyName { return string(v), nil } secret = string(v) } // If not found, the last secret in the map wins as done before return secret, nil }
[ "func", "(", "p", "*", "rbdProvisioner", ")", "parsePVSecret", "(", "namespace", ",", "secretName", "string", ")", "(", "string", ",", "error", ")", "{", "if", "p", ".", "client", "==", "nil", "{", "return", "\"\"", ",", "fmt", ".", "Errorf", "(", "\"Cannot get kube client\"", ")", "\n", "}", "\n", "secrets", ",", "err", ":=", "p", ".", "client", ".", "CoreV1", "(", ")", ".", "Secrets", "(", "namespace", ")", ".", "Get", "(", "secretName", ",", "metav1", ".", "GetOptions", "{", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "err", "\n", "}", "\n", "secret", ":=", "\"\"", "\n", "for", "k", ",", "v", ":=", "range", "secrets", ".", "Data", "{", "if", "k", "==", "secretKeyName", "{", "return", "string", "(", "v", ")", ",", "nil", "\n", "}", "\n", "secret", "=", "string", "(", "v", ")", "\n", "}", "\n", "return", "secret", ",", "nil", "\n", "}" ]
// parsePVSecret retrives secret value for a given namespace and name.
[ "parsePVSecret", "retrives", "secret", "value", "for", "a", "given", "namespace", "and", "name", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/ceph/rbd/pkg/provision/provision.go#L310-L329
train
kubernetes-incubator/external-storage
snapshot/pkg/apis/crd/v1/zz_generated.deepcopy.go
DeepCopy
func (in *AWSElasticBlockStoreVolumeSnapshotSource) DeepCopy() *AWSElasticBlockStoreVolumeSnapshotSource { if in == nil { return nil } out := new(AWSElasticBlockStoreVolumeSnapshotSource) in.DeepCopyInto(out) return out }
go
func (in *AWSElasticBlockStoreVolumeSnapshotSource) DeepCopy() *AWSElasticBlockStoreVolumeSnapshotSource { if in == nil { return nil } out := new(AWSElasticBlockStoreVolumeSnapshotSource) in.DeepCopyInto(out) return out }
[ "func", "(", "in", "*", "AWSElasticBlockStoreVolumeSnapshotSource", ")", "DeepCopy", "(", ")", "*", "AWSElasticBlockStoreVolumeSnapshotSource", "{", "if", "in", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "out", ":=", "new", "(", "AWSElasticBlockStoreVolumeSnapshotSource", ")", "\n", "in", ".", "DeepCopyInto", "(", "out", ")", "\n", "return", "out", "\n", "}" ]
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AWSElasticBlockStoreVolumeSnapshotSource.
[ "DeepCopy", "is", "an", "autogenerated", "deepcopy", "function", "copying", "the", "receiver", "creating", "a", "new", "AWSElasticBlockStoreVolumeSnapshotSource", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/apis/crd/v1/zz_generated.deepcopy.go#L34-L41
train
kubernetes-incubator/external-storage
snapshot/pkg/apis/crd/v1/zz_generated.deepcopy.go
DeepCopy
func (in *CinderVolumeSnapshotSource) DeepCopy() *CinderVolumeSnapshotSource { if in == nil { return nil } out := new(CinderVolumeSnapshotSource) in.DeepCopyInto(out) return out }
go
func (in *CinderVolumeSnapshotSource) DeepCopy() *CinderVolumeSnapshotSource { if in == nil { return nil } out := new(CinderVolumeSnapshotSource) in.DeepCopyInto(out) return out }
[ "func", "(", "in", "*", "CinderVolumeSnapshotSource", ")", "DeepCopy", "(", ")", "*", "CinderVolumeSnapshotSource", "{", "if", "in", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "out", ":=", "new", "(", "CinderVolumeSnapshotSource", ")", "\n", "in", ".", "DeepCopyInto", "(", "out", ")", "\n", "return", "out", "\n", "}" ]
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CinderVolumeSnapshotSource.
[ "DeepCopy", "is", "an", "autogenerated", "deepcopy", "function", "copying", "the", "receiver", "creating", "a", "new", "CinderVolumeSnapshotSource", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/apis/crd/v1/zz_generated.deepcopy.go#L50-L57
train
kubernetes-incubator/external-storage
snapshot/pkg/apis/crd/v1/zz_generated.deepcopy.go
DeepCopy
func (in *GCEPersistentDiskSnapshotSource) DeepCopy() *GCEPersistentDiskSnapshotSource { if in == nil { return nil } out := new(GCEPersistentDiskSnapshotSource) in.DeepCopyInto(out) return out }
go
func (in *GCEPersistentDiskSnapshotSource) DeepCopy() *GCEPersistentDiskSnapshotSource { if in == nil { return nil } out := new(GCEPersistentDiskSnapshotSource) in.DeepCopyInto(out) return out }
[ "func", "(", "in", "*", "GCEPersistentDiskSnapshotSource", ")", "DeepCopy", "(", ")", "*", "GCEPersistentDiskSnapshotSource", "{", "if", "in", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "out", ":=", "new", "(", "GCEPersistentDiskSnapshotSource", ")", "\n", "in", ".", "DeepCopyInto", "(", "out", ")", "\n", "return", "out", "\n", "}" ]
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GCEPersistentDiskSnapshotSource.
[ "DeepCopy", "is", "an", "autogenerated", "deepcopy", "function", "copying", "the", "receiver", "creating", "a", "new", "GCEPersistentDiskSnapshotSource", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/apis/crd/v1/zz_generated.deepcopy.go#L66-L73
train
kubernetes-incubator/external-storage
snapshot/pkg/apis/crd/v1/zz_generated.deepcopy.go
DeepCopy
func (in *GlusterVolumeSnapshotSource) DeepCopy() *GlusterVolumeSnapshotSource { if in == nil { return nil } out := new(GlusterVolumeSnapshotSource) in.DeepCopyInto(out) return out }
go
func (in *GlusterVolumeSnapshotSource) DeepCopy() *GlusterVolumeSnapshotSource { if in == nil { return nil } out := new(GlusterVolumeSnapshotSource) in.DeepCopyInto(out) return out }
[ "func", "(", "in", "*", "GlusterVolumeSnapshotSource", ")", "DeepCopy", "(", ")", "*", "GlusterVolumeSnapshotSource", "{", "if", "in", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "out", ":=", "new", "(", "GlusterVolumeSnapshotSource", ")", "\n", "in", ".", "DeepCopyInto", "(", "out", ")", "\n", "return", "out", "\n", "}" ]
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GlusterVolumeSnapshotSource.
[ "DeepCopy", "is", "an", "autogenerated", "deepcopy", "function", "copying", "the", "receiver", "creating", "a", "new", "GlusterVolumeSnapshotSource", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/apis/crd/v1/zz_generated.deepcopy.go#L82-L89
train
kubernetes-incubator/external-storage
snapshot/pkg/apis/crd/v1/zz_generated.deepcopy.go
DeepCopy
func (in *HostPathVolumeSnapshotSource) DeepCopy() *HostPathVolumeSnapshotSource { if in == nil { return nil } out := new(HostPathVolumeSnapshotSource) in.DeepCopyInto(out) return out }
go
func (in *HostPathVolumeSnapshotSource) DeepCopy() *HostPathVolumeSnapshotSource { if in == nil { return nil } out := new(HostPathVolumeSnapshotSource) in.DeepCopyInto(out) return out }
[ "func", "(", "in", "*", "HostPathVolumeSnapshotSource", ")", "DeepCopy", "(", ")", "*", "HostPathVolumeSnapshotSource", "{", "if", "in", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "out", ":=", "new", "(", "HostPathVolumeSnapshotSource", ")", "\n", "in", ".", "DeepCopyInto", "(", "out", ")", "\n", "return", "out", "\n", "}" ]
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HostPathVolumeSnapshotSource.
[ "DeepCopy", "is", "an", "autogenerated", "deepcopy", "function", "copying", "the", "receiver", "creating", "a", "new", "HostPathVolumeSnapshotSource", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/apis/crd/v1/zz_generated.deepcopy.go#L98-L105
train
kubernetes-incubator/external-storage
snapshot/pkg/apis/crd/v1/zz_generated.deepcopy.go
DeepCopy
func (in *VolumeSnapshot) DeepCopy() *VolumeSnapshot { if in == nil { return nil } out := new(VolumeSnapshot) in.DeepCopyInto(out) return out }
go
func (in *VolumeSnapshot) DeepCopy() *VolumeSnapshot { if in == nil { return nil } out := new(VolumeSnapshot) in.DeepCopyInto(out) return out }
[ "func", "(", "in", "*", "VolumeSnapshot", ")", "DeepCopy", "(", ")", "*", "VolumeSnapshot", "{", "if", "in", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "out", ":=", "new", "(", "VolumeSnapshot", ")", "\n", "in", ".", "DeepCopyInto", "(", "out", ")", "\n", "return", "out", "\n", "}" ]
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VolumeSnapshot.
[ "DeepCopy", "is", "an", "autogenerated", "deepcopy", "function", "copying", "the", "receiver", "creating", "a", "new", "VolumeSnapshot", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/apis/crd/v1/zz_generated.deepcopy.go#L118-L125
train
kubernetes-incubator/external-storage
snapshot/pkg/apis/crd/v1/zz_generated.deepcopy.go
DeepCopy
func (in *VolumeSnapshotCondition) DeepCopy() *VolumeSnapshotCondition { if in == nil { return nil } out := new(VolumeSnapshotCondition) in.DeepCopyInto(out) return out }
go
func (in *VolumeSnapshotCondition) DeepCopy() *VolumeSnapshotCondition { if in == nil { return nil } out := new(VolumeSnapshotCondition) in.DeepCopyInto(out) return out }
[ "func", "(", "in", "*", "VolumeSnapshotCondition", ")", "DeepCopy", "(", ")", "*", "VolumeSnapshotCondition", "{", "if", "in", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "out", ":=", "new", "(", "VolumeSnapshotCondition", ")", "\n", "in", ".", "DeepCopyInto", "(", "out", ")", "\n", "return", "out", "\n", "}" ]
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VolumeSnapshotCondition.
[ "DeepCopy", "is", "an", "autogenerated", "deepcopy", "function", "copying", "the", "receiver", "creating", "a", "new", "VolumeSnapshotCondition", "." ]
fbfedbf60da4e5ee25a3151bfe8504f3e3281319
https://github.com/kubernetes-incubator/external-storage/blob/fbfedbf60da4e5ee25a3151bfe8504f3e3281319/snapshot/pkg/apis/crd/v1/zz_generated.deepcopy.go#L137-L144
train