repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1 value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
libopenstorage/openstorage | cluster/manager/manager.go | GetNodeIdFromIp | func (c *ClusterManager) GetNodeIdFromIp(idIp string) (string, error) {
addr := net.ParseIP(idIp)
if addr != nil { // Is an IP, lookup Id
c.nodeCacheLock.Lock()
defer c.nodeCacheLock.Unlock()
return c.nodeIdFromIp(idIp)
}
return idIp, nil // return input, assume its an Id
} | go | func (c *ClusterManager) GetNodeIdFromIp(idIp string) (string, error) {
addr := net.ParseIP(idIp)
if addr != nil { // Is an IP, lookup Id
c.nodeCacheLock.Lock()
defer c.nodeCacheLock.Unlock()
return c.nodeIdFromIp(idIp)
}
return idIp, nil // return input, assume its an Id
} | [
"func",
"(",
"c",
"*",
"ClusterManager",
")",
"GetNodeIdFromIp",
"(",
"idIp",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"addr",
":=",
"net",
".",
"ParseIP",
"(",
"idIp",
")",
"\n",
"if",
"addr",
"!=",
"nil",
"{",
"// Is an IP, lookup Id",
"c",
".",
"nodeCacheLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"nodeCacheLock",
".",
"Unlock",
"(",
")",
"\n",
"return",
"c",
".",
"nodeIdFromIp",
"(",
"idIp",
")",
"\n",
"}",
"\n\n",
"return",
"idIp",
",",
"nil",
"// return input, assume its an Id",
"\n",
"}"
] | // GetNodeIdFromIp returns a Node Id given an IP. | [
"GetNodeIdFromIp",
"returns",
"a",
"Node",
"Id",
"given",
"an",
"IP",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/cluster/manager/manager.go#L370-L379 | train |
libopenstorage/openstorage | cluster/manager/manager.go | getCurrentState | func (c *ClusterManager) getCurrentState() *api.Node {
c.selfNodeLock.Lock()
defer c.selfNodeLock.Unlock()
c.selfNode.Timestamp = time.Now()
c.selfNode.Cpu, _, _ = c.system.CpuUsage()
c.selfNode.MemTotal, c.selfNode.MemUsed, c.selfNode.MemFree = c.system.MemUsage()
c.selfNode.Timestamp = time.Now()
for e := c.listeners.Front(); e != nil; e = e.Next() {
listenerDataMap := e.Value.(cluster.ClusterListener).ListenerData()
if listenerDataMap == nil {
continue
}
for key, val := range listenerDataMap {
c.selfNode.NodeData[key] = val
}
}
nodeCopy := (&c.selfNode).Copy()
return nodeCopy
} | go | func (c *ClusterManager) getCurrentState() *api.Node {
c.selfNodeLock.Lock()
defer c.selfNodeLock.Unlock()
c.selfNode.Timestamp = time.Now()
c.selfNode.Cpu, _, _ = c.system.CpuUsage()
c.selfNode.MemTotal, c.selfNode.MemUsed, c.selfNode.MemFree = c.system.MemUsage()
c.selfNode.Timestamp = time.Now()
for e := c.listeners.Front(); e != nil; e = e.Next() {
listenerDataMap := e.Value.(cluster.ClusterListener).ListenerData()
if listenerDataMap == nil {
continue
}
for key, val := range listenerDataMap {
c.selfNode.NodeData[key] = val
}
}
nodeCopy := (&c.selfNode).Copy()
return nodeCopy
} | [
"func",
"(",
"c",
"*",
"ClusterManager",
")",
"getCurrentState",
"(",
")",
"*",
"api",
".",
"Node",
"{",
"c",
".",
"selfNodeLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"selfNodeLock",
".",
"Unlock",
"(",
")",
"\n",
"c",
".",
"selfNode",
".",
"Timestamp",
"=",
"time",
".",
"Now",
"(",
")",
"\n\n",
"c",
".",
"selfNode",
".",
"Cpu",
",",
"_",
",",
"_",
"=",
"c",
".",
"system",
".",
"CpuUsage",
"(",
")",
"\n",
"c",
".",
"selfNode",
".",
"MemTotal",
",",
"c",
".",
"selfNode",
".",
"MemUsed",
",",
"c",
".",
"selfNode",
".",
"MemFree",
"=",
"c",
".",
"system",
".",
"MemUsage",
"(",
")",
"\n\n",
"c",
".",
"selfNode",
".",
"Timestamp",
"=",
"time",
".",
"Now",
"(",
")",
"\n\n",
"for",
"e",
":=",
"c",
".",
"listeners",
".",
"Front",
"(",
")",
";",
"e",
"!=",
"nil",
";",
"e",
"=",
"e",
".",
"Next",
"(",
")",
"{",
"listenerDataMap",
":=",
"e",
".",
"Value",
".",
"(",
"cluster",
".",
"ClusterListener",
")",
".",
"ListenerData",
"(",
")",
"\n",
"if",
"listenerDataMap",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"for",
"key",
",",
"val",
":=",
"range",
"listenerDataMap",
"{",
"c",
".",
"selfNode",
".",
"NodeData",
"[",
"key",
"]",
"=",
"val",
"\n",
"}",
"\n",
"}",
"\n\n",
"nodeCopy",
":=",
"(",
"&",
"c",
".",
"selfNode",
")",
".",
"Copy",
"(",
")",
"\n",
"return",
"nodeCopy",
"\n",
"}"
] | // getCurrentState always returns the copy of selfNode that
// cluster manager maintains. It also updates the selfNode
// with latest data. | [
"getCurrentState",
"always",
"returns",
"the",
"copy",
"of",
"selfNode",
"that",
"cluster",
"manager",
"maintains",
".",
"It",
"also",
"updates",
"the",
"selfNode",
"with",
"latest",
"data",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/cluster/manager/manager.go#L384-L406 | train |
libopenstorage/openstorage | cluster/manager/manager.go | watchDB | func (c *ClusterManager) watchDB(key string, opaque interface{},
kvp *kvdb.KVPair, watchErr error) error {
db, kvdbVersion, err := readClusterInfo()
if err != nil {
logrus.Warnln("Failed to read database after update ", err)
// Exit since an update may be missed here.
os.Exit(1)
}
// Update all the listeners with the new db
for e := c.listeners.Front(); e != nil; e = e.Next() {
err := e.Value.(cluster.ClusterListener).UpdateCluster(&c.selfNode, &db)
if err != nil {
logrus.Warnln("Failed to notify ", e.Value.(cluster.ClusterListener).String())
}
}
for _, nodeEntry := range db.NodeEntries {
if nodeEntry.Status == api.Status_STATUS_DECOMMISSION {
logrus.Infof("ClusterManager watchDB, node ID "+
"%s state is Decommission.",
nodeEntry.Id)
n, found := c.getNodeCacheEntry(nodeEntry.Id)
if !found {
logrus.Errorf("ClusterManager watchDB, "+
"node ID %s not in node cache",
nodeEntry.Id)
continue
}
if n.Status == api.Status_STATUS_DECOMMISSION {
logrus.Infof("ClusterManager watchDB, "+
"node ID %s is already decommission "+
"on this node",
nodeEntry.Id)
continue
}
logrus.Infof("ClusterManager watchDB, "+
"decommsission node ID %s on this node",
nodeEntry.Id)
n.Status = api.Status_STATUS_DECOMMISSION
c.putNodeCacheEntry(nodeEntry.Id, n)
// We are getting decommissioned!!
if nodeEntry.Id == c.selfNode.Id {
// We are getting decommissioned.
// Stop the heartbeat and stop the watch
stopHeartbeat <- true
c.gossip.Stop(time.Duration(10 * time.Second))
return fmt.Errorf("stop watch")
}
}
}
c.size = db.Size
c.gossip.UpdateCluster(c.getNonDecommisionedPeers(db))
// update the nodeCache and remove any nodes not present in cluster database
c.nodeCacheLock.Lock()
defer c.nodeCacheLock.Unlock()
for _, n := range c.nodeCache {
_, found := db.NodeEntries[n.Id]
if !found {
delete(c.nodeCache, n.Id)
}
}
if watchErr != nil && c.selfNode.Status != api.Status_STATUS_DECOMMISSION {
logrus.Errorf("ClusterManager watch stopped, restarting (err: %v)",
watchErr)
c.startClusterDBWatch(kvdbVersion, kvdb.Instance())
}
return watchErr
} | go | func (c *ClusterManager) watchDB(key string, opaque interface{},
kvp *kvdb.KVPair, watchErr error) error {
db, kvdbVersion, err := readClusterInfo()
if err != nil {
logrus.Warnln("Failed to read database after update ", err)
// Exit since an update may be missed here.
os.Exit(1)
}
// Update all the listeners with the new db
for e := c.listeners.Front(); e != nil; e = e.Next() {
err := e.Value.(cluster.ClusterListener).UpdateCluster(&c.selfNode, &db)
if err != nil {
logrus.Warnln("Failed to notify ", e.Value.(cluster.ClusterListener).String())
}
}
for _, nodeEntry := range db.NodeEntries {
if nodeEntry.Status == api.Status_STATUS_DECOMMISSION {
logrus.Infof("ClusterManager watchDB, node ID "+
"%s state is Decommission.",
nodeEntry.Id)
n, found := c.getNodeCacheEntry(nodeEntry.Id)
if !found {
logrus.Errorf("ClusterManager watchDB, "+
"node ID %s not in node cache",
nodeEntry.Id)
continue
}
if n.Status == api.Status_STATUS_DECOMMISSION {
logrus.Infof("ClusterManager watchDB, "+
"node ID %s is already decommission "+
"on this node",
nodeEntry.Id)
continue
}
logrus.Infof("ClusterManager watchDB, "+
"decommsission node ID %s on this node",
nodeEntry.Id)
n.Status = api.Status_STATUS_DECOMMISSION
c.putNodeCacheEntry(nodeEntry.Id, n)
// We are getting decommissioned!!
if nodeEntry.Id == c.selfNode.Id {
// We are getting decommissioned.
// Stop the heartbeat and stop the watch
stopHeartbeat <- true
c.gossip.Stop(time.Duration(10 * time.Second))
return fmt.Errorf("stop watch")
}
}
}
c.size = db.Size
c.gossip.UpdateCluster(c.getNonDecommisionedPeers(db))
// update the nodeCache and remove any nodes not present in cluster database
c.nodeCacheLock.Lock()
defer c.nodeCacheLock.Unlock()
for _, n := range c.nodeCache {
_, found := db.NodeEntries[n.Id]
if !found {
delete(c.nodeCache, n.Id)
}
}
if watchErr != nil && c.selfNode.Status != api.Status_STATUS_DECOMMISSION {
logrus.Errorf("ClusterManager watch stopped, restarting (err: %v)",
watchErr)
c.startClusterDBWatch(kvdbVersion, kvdb.Instance())
}
return watchErr
} | [
"func",
"(",
"c",
"*",
"ClusterManager",
")",
"watchDB",
"(",
"key",
"string",
",",
"opaque",
"interface",
"{",
"}",
",",
"kvp",
"*",
"kvdb",
".",
"KVPair",
",",
"watchErr",
"error",
")",
"error",
"{",
"db",
",",
"kvdbVersion",
",",
"err",
":=",
"readClusterInfo",
"(",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Warnln",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"// Exit since an update may be missed here.",
"os",
".",
"Exit",
"(",
"1",
")",
"\n",
"}",
"\n\n",
"// Update all the listeners with the new db",
"for",
"e",
":=",
"c",
".",
"listeners",
".",
"Front",
"(",
")",
";",
"e",
"!=",
"nil",
";",
"e",
"=",
"e",
".",
"Next",
"(",
")",
"{",
"err",
":=",
"e",
".",
"Value",
".",
"(",
"cluster",
".",
"ClusterListener",
")",
".",
"UpdateCluster",
"(",
"&",
"c",
".",
"selfNode",
",",
"&",
"db",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Warnln",
"(",
"\"",
"\"",
",",
"e",
".",
"Value",
".",
"(",
"cluster",
".",
"ClusterListener",
")",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"nodeEntry",
":=",
"range",
"db",
".",
"NodeEntries",
"{",
"if",
"nodeEntry",
".",
"Status",
"==",
"api",
".",
"Status_STATUS_DECOMMISSION",
"{",
"logrus",
".",
"Infof",
"(",
"\"",
"\"",
"+",
"\"",
"\"",
",",
"nodeEntry",
".",
"Id",
")",
"\n\n",
"n",
",",
"found",
":=",
"c",
".",
"getNodeCacheEntry",
"(",
"nodeEntry",
".",
"Id",
")",
"\n",
"if",
"!",
"found",
"{",
"logrus",
".",
"Errorf",
"(",
"\"",
"\"",
"+",
"\"",
"\"",
",",
"nodeEntry",
".",
"Id",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"if",
"n",
".",
"Status",
"==",
"api",
".",
"Status_STATUS_DECOMMISSION",
"{",
"logrus",
".",
"Infof",
"(",
"\"",
"\"",
"+",
"\"",
"\"",
"+",
"\"",
"\"",
",",
"nodeEntry",
".",
"Id",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"logrus",
".",
"Infof",
"(",
"\"",
"\"",
"+",
"\"",
"\"",
",",
"nodeEntry",
".",
"Id",
")",
"\n\n",
"n",
".",
"Status",
"=",
"api",
".",
"Status_STATUS_DECOMMISSION",
"\n",
"c",
".",
"putNodeCacheEntry",
"(",
"nodeEntry",
".",
"Id",
",",
"n",
")",
"\n",
"// We are getting decommissioned!!",
"if",
"nodeEntry",
".",
"Id",
"==",
"c",
".",
"selfNode",
".",
"Id",
"{",
"// We are getting decommissioned.",
"// Stop the heartbeat and stop the watch",
"stopHeartbeat",
"<-",
"true",
"\n",
"c",
".",
"gossip",
".",
"Stop",
"(",
"time",
".",
"Duration",
"(",
"10",
"*",
"time",
".",
"Second",
")",
")",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"c",
".",
"size",
"=",
"db",
".",
"Size",
"\n\n",
"c",
".",
"gossip",
".",
"UpdateCluster",
"(",
"c",
".",
"getNonDecommisionedPeers",
"(",
"db",
")",
")",
"\n\n",
"// update the nodeCache and remove any nodes not present in cluster database",
"c",
".",
"nodeCacheLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"nodeCacheLock",
".",
"Unlock",
"(",
")",
"\n",
"for",
"_",
",",
"n",
":=",
"range",
"c",
".",
"nodeCache",
"{",
"_",
",",
"found",
":=",
"db",
".",
"NodeEntries",
"[",
"n",
".",
"Id",
"]",
"\n",
"if",
"!",
"found",
"{",
"delete",
"(",
"c",
".",
"nodeCache",
",",
"n",
".",
"Id",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"watchErr",
"!=",
"nil",
"&&",
"c",
".",
"selfNode",
".",
"Status",
"!=",
"api",
".",
"Status_STATUS_DECOMMISSION",
"{",
"logrus",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"watchErr",
")",
"\n",
"c",
".",
"startClusterDBWatch",
"(",
"kvdbVersion",
",",
"kvdb",
".",
"Instance",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"watchErr",
"\n",
"}"
] | // Get the latest config. | [
"Get",
"the",
"latest",
"config",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/cluster/manager/manager.go#L426-L504 | train |
libopenstorage/openstorage | cluster/manager/manager.go | initNodeInCluster | func (c *ClusterManager) initNodeInCluster(
clusterInfo *cluster.ClusterInfo,
self *api.Node,
exist bool,
nodeInitialized bool,
) ([]cluster.FinalizeInitCb, error) {
// If I am already in the cluster map, don't add me again.
if exist {
return nil, nil
}
if nodeInitialized {
logrus.Errorf(cluster.ErrInitNodeNotFound.Error())
return nil, cluster.ErrInitNodeNotFound
}
// Alert all listeners that we are a new node and we are initializing.
finalizeCbs := make([]cluster.FinalizeInitCb, 0)
for e := c.listeners.Front(); e != nil; e = e.Next() {
finalizeCb, err := e.Value.(cluster.ClusterListener).Init(self, clusterInfo)
if err != nil {
if self.Status != api.Status_STATUS_MAINTENANCE {
self.Status = api.Status_STATUS_ERROR
}
logrus.Warnf("Failed to initialize Init %s: %v",
e.Value.(cluster.ClusterListener).String(), err)
c.cleanupInit(clusterInfo, self)
return nil, err
}
if finalizeCb != nil {
finalizeCbs = append(finalizeCbs, finalizeCb)
}
}
return finalizeCbs, nil
} | go | func (c *ClusterManager) initNodeInCluster(
clusterInfo *cluster.ClusterInfo,
self *api.Node,
exist bool,
nodeInitialized bool,
) ([]cluster.FinalizeInitCb, error) {
// If I am already in the cluster map, don't add me again.
if exist {
return nil, nil
}
if nodeInitialized {
logrus.Errorf(cluster.ErrInitNodeNotFound.Error())
return nil, cluster.ErrInitNodeNotFound
}
// Alert all listeners that we are a new node and we are initializing.
finalizeCbs := make([]cluster.FinalizeInitCb, 0)
for e := c.listeners.Front(); e != nil; e = e.Next() {
finalizeCb, err := e.Value.(cluster.ClusterListener).Init(self, clusterInfo)
if err != nil {
if self.Status != api.Status_STATUS_MAINTENANCE {
self.Status = api.Status_STATUS_ERROR
}
logrus.Warnf("Failed to initialize Init %s: %v",
e.Value.(cluster.ClusterListener).String(), err)
c.cleanupInit(clusterInfo, self)
return nil, err
}
if finalizeCb != nil {
finalizeCbs = append(finalizeCbs, finalizeCb)
}
}
return finalizeCbs, nil
} | [
"func",
"(",
"c",
"*",
"ClusterManager",
")",
"initNodeInCluster",
"(",
"clusterInfo",
"*",
"cluster",
".",
"ClusterInfo",
",",
"self",
"*",
"api",
".",
"Node",
",",
"exist",
"bool",
",",
"nodeInitialized",
"bool",
",",
")",
"(",
"[",
"]",
"cluster",
".",
"FinalizeInitCb",
",",
"error",
")",
"{",
"// If I am already in the cluster map, don't add me again.",
"if",
"exist",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"nodeInitialized",
"{",
"logrus",
".",
"Errorf",
"(",
"cluster",
".",
"ErrInitNodeNotFound",
".",
"Error",
"(",
")",
")",
"\n",
"return",
"nil",
",",
"cluster",
".",
"ErrInitNodeNotFound",
"\n",
"}",
"\n\n",
"// Alert all listeners that we are a new node and we are initializing.",
"finalizeCbs",
":=",
"make",
"(",
"[",
"]",
"cluster",
".",
"FinalizeInitCb",
",",
"0",
")",
"\n",
"for",
"e",
":=",
"c",
".",
"listeners",
".",
"Front",
"(",
")",
";",
"e",
"!=",
"nil",
";",
"e",
"=",
"e",
".",
"Next",
"(",
")",
"{",
"finalizeCb",
",",
"err",
":=",
"e",
".",
"Value",
".",
"(",
"cluster",
".",
"ClusterListener",
")",
".",
"Init",
"(",
"self",
",",
"clusterInfo",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"self",
".",
"Status",
"!=",
"api",
".",
"Status_STATUS_MAINTENANCE",
"{",
"self",
".",
"Status",
"=",
"api",
".",
"Status_STATUS_ERROR",
"\n",
"}",
"\n",
"logrus",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"e",
".",
"Value",
".",
"(",
"cluster",
".",
"ClusterListener",
")",
".",
"String",
"(",
")",
",",
"err",
")",
"\n",
"c",
".",
"cleanupInit",
"(",
"clusterInfo",
",",
"self",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"finalizeCb",
"!=",
"nil",
"{",
"finalizeCbs",
"=",
"append",
"(",
"finalizeCbs",
",",
"finalizeCb",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"finalizeCbs",
",",
"nil",
"\n",
"}"
] | // Initialize node and alert listeners that we are initializing a node in the cluster. | [
"Initialize",
"node",
"and",
"alert",
"listeners",
"that",
"we",
"are",
"initializing",
"a",
"node",
"in",
"the",
"cluster",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/cluster/manager/manager.go#L578-L613 | train |
libopenstorage/openstorage | cluster/manager/manager.go | joinCluster | func (c *ClusterManager) joinCluster(
self *api.Node,
exist bool,
) error {
// Listeners may update initial state, so snap again.
// The cluster db may have diverged since we waited for quorum
// in between. Snapshot is created under cluster db lock to make
// sure cluster db updates do not happen during snapshot, otherwise
// there may be a mismatch between db updates from listeners and
// cluster db state.
kvdb := kvdb.Instance()
kvlock, err := kvdb.LockWithID(clusterLockKey, c.config.NodeId)
if err != nil {
logrus.Warnln("Unable to obtain cluster lock before creating snapshot: ",
err)
return err
}
initState, err := snapAndReadClusterInfo(c.snapshotPrefixes)
kvdb.Unlock(kvlock)
if err != nil {
logrus.Panicf("Fatal, Unable to create snapshot: %v", err)
return err
}
defer func() {
if initState.Collector != nil {
initState.Collector.Stop()
initState.Collector = nil
}
}()
// Alert all listeners that we are joining the cluster.
for e := c.listeners.Front(); e != nil; e = e.Next() {
err := e.Value.(cluster.ClusterListener).Join(self, initState)
if err != nil {
if self.Status != api.Status_STATUS_MAINTENANCE {
self.Status = api.Status_STATUS_ERROR
}
logrus.Warnf("Failed to initialize Join %s: %v",
e.Value.(cluster.ClusterListener).String(), err)
if exist == false {
c.cleanupInit(initState.ClusterInfo, self)
}
logrus.Errorln("Failed to join cluster.", err)
return err
}
}
selfNodeEntry, ok := initState.ClusterInfo.NodeEntries[c.config.NodeId]
if !ok {
logrus.Panicln("Fatal, Unable to find self node entry in local cache")
}
_, _, err = c.updateNodeEntryDB(selfNodeEntry, nil)
if err != nil {
return err
}
return nil
} | go | func (c *ClusterManager) joinCluster(
self *api.Node,
exist bool,
) error {
// Listeners may update initial state, so snap again.
// The cluster db may have diverged since we waited for quorum
// in between. Snapshot is created under cluster db lock to make
// sure cluster db updates do not happen during snapshot, otherwise
// there may be a mismatch between db updates from listeners and
// cluster db state.
kvdb := kvdb.Instance()
kvlock, err := kvdb.LockWithID(clusterLockKey, c.config.NodeId)
if err != nil {
logrus.Warnln("Unable to obtain cluster lock before creating snapshot: ",
err)
return err
}
initState, err := snapAndReadClusterInfo(c.snapshotPrefixes)
kvdb.Unlock(kvlock)
if err != nil {
logrus.Panicf("Fatal, Unable to create snapshot: %v", err)
return err
}
defer func() {
if initState.Collector != nil {
initState.Collector.Stop()
initState.Collector = nil
}
}()
// Alert all listeners that we are joining the cluster.
for e := c.listeners.Front(); e != nil; e = e.Next() {
err := e.Value.(cluster.ClusterListener).Join(self, initState)
if err != nil {
if self.Status != api.Status_STATUS_MAINTENANCE {
self.Status = api.Status_STATUS_ERROR
}
logrus.Warnf("Failed to initialize Join %s: %v",
e.Value.(cluster.ClusterListener).String(), err)
if exist == false {
c.cleanupInit(initState.ClusterInfo, self)
}
logrus.Errorln("Failed to join cluster.", err)
return err
}
}
selfNodeEntry, ok := initState.ClusterInfo.NodeEntries[c.config.NodeId]
if !ok {
logrus.Panicln("Fatal, Unable to find self node entry in local cache")
}
_, _, err = c.updateNodeEntryDB(selfNodeEntry, nil)
if err != nil {
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"ClusterManager",
")",
"joinCluster",
"(",
"self",
"*",
"api",
".",
"Node",
",",
"exist",
"bool",
",",
")",
"error",
"{",
"// Listeners may update initial state, so snap again.",
"// The cluster db may have diverged since we waited for quorum",
"// in between. Snapshot is created under cluster db lock to make",
"// sure cluster db updates do not happen during snapshot, otherwise",
"// there may be a mismatch between db updates from listeners and",
"// cluster db state.",
"kvdb",
":=",
"kvdb",
".",
"Instance",
"(",
")",
"\n",
"kvlock",
",",
"err",
":=",
"kvdb",
".",
"LockWithID",
"(",
"clusterLockKey",
",",
"c",
".",
"config",
".",
"NodeId",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Warnln",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"initState",
",",
"err",
":=",
"snapAndReadClusterInfo",
"(",
"c",
".",
"snapshotPrefixes",
")",
"\n",
"kvdb",
".",
"Unlock",
"(",
"kvlock",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Panicf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"initState",
".",
"Collector",
"!=",
"nil",
"{",
"initState",
".",
"Collector",
".",
"Stop",
"(",
")",
"\n",
"initState",
".",
"Collector",
"=",
"nil",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"// Alert all listeners that we are joining the cluster.",
"for",
"e",
":=",
"c",
".",
"listeners",
".",
"Front",
"(",
")",
";",
"e",
"!=",
"nil",
";",
"e",
"=",
"e",
".",
"Next",
"(",
")",
"{",
"err",
":=",
"e",
".",
"Value",
".",
"(",
"cluster",
".",
"ClusterListener",
")",
".",
"Join",
"(",
"self",
",",
"initState",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"self",
".",
"Status",
"!=",
"api",
".",
"Status_STATUS_MAINTENANCE",
"{",
"self",
".",
"Status",
"=",
"api",
".",
"Status_STATUS_ERROR",
"\n",
"}",
"\n",
"logrus",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"e",
".",
"Value",
".",
"(",
"cluster",
".",
"ClusterListener",
")",
".",
"String",
"(",
")",
",",
"err",
")",
"\n\n",
"if",
"exist",
"==",
"false",
"{",
"c",
".",
"cleanupInit",
"(",
"initState",
".",
"ClusterInfo",
",",
"self",
")",
"\n",
"}",
"\n",
"logrus",
".",
"Errorln",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"selfNodeEntry",
",",
"ok",
":=",
"initState",
".",
"ClusterInfo",
".",
"NodeEntries",
"[",
"c",
".",
"config",
".",
"NodeId",
"]",
"\n",
"if",
"!",
"ok",
"{",
"logrus",
".",
"Panicln",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"_",
",",
"_",
",",
"err",
"=",
"c",
".",
"updateNodeEntryDB",
"(",
"selfNodeEntry",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Alert all listeners that we are joining the cluster | [
"Alert",
"all",
"listeners",
"that",
"we",
"are",
"joining",
"the",
"cluster"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/cluster/manager/manager.go#L616-L673 | train |
libopenstorage/openstorage | cluster/manager/manager.go | DisableUpdates | func (c *ClusterManager) DisableUpdates() error {
logrus.Warnln("Disabling gossip updates")
c.gEnabled = false
return nil
} | go | func (c *ClusterManager) DisableUpdates() error {
logrus.Warnln("Disabling gossip updates")
c.gEnabled = false
return nil
} | [
"func",
"(",
"c",
"*",
"ClusterManager",
")",
"DisableUpdates",
"(",
")",
"error",
"{",
"logrus",
".",
"Warnln",
"(",
"\"",
"\"",
")",
"\n",
"c",
".",
"gEnabled",
"=",
"false",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // DisableUpdates disables gossip updates | [
"DisableUpdates",
"disables",
"gossip",
"updates"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/cluster/manager/manager.go#L943-L948 | train |
libopenstorage/openstorage | cluster/manager/manager.go | EnableUpdates | func (c *ClusterManager) EnableUpdates() error {
logrus.Warnln("Enabling gossip updates")
c.gEnabled = true
return nil
} | go | func (c *ClusterManager) EnableUpdates() error {
logrus.Warnln("Enabling gossip updates")
c.gEnabled = true
return nil
} | [
"func",
"(",
"c",
"*",
"ClusterManager",
")",
"EnableUpdates",
"(",
")",
"error",
"{",
"logrus",
".",
"Warnln",
"(",
"\"",
"\"",
")",
"\n",
"c",
".",
"gEnabled",
"=",
"true",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // EnableUpdates enables gossip updates | [
"EnableUpdates",
"enables",
"gossip",
"updates"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/cluster/manager/manager.go#L951-L956 | train |
libopenstorage/openstorage | cluster/manager/manager.go | GetGossipState | func (c *ClusterManager) GetGossipState() *cluster.ClusterState {
gossipStoreKey := types.StoreKey(heartbeatKey + c.config.ClusterId)
nodeValue := c.gossip.GetStoreKeyValue(gossipStoreKey)
nodes := make([]types.NodeValue, len(nodeValue), len(nodeValue))
i := 0
for _, value := range nodeValue {
nodes[i] = value
i++
}
return &cluster.ClusterState{NodeStatus: nodes}
} | go | func (c *ClusterManager) GetGossipState() *cluster.ClusterState {
gossipStoreKey := types.StoreKey(heartbeatKey + c.config.ClusterId)
nodeValue := c.gossip.GetStoreKeyValue(gossipStoreKey)
nodes := make([]types.NodeValue, len(nodeValue), len(nodeValue))
i := 0
for _, value := range nodeValue {
nodes[i] = value
i++
}
return &cluster.ClusterState{NodeStatus: nodes}
} | [
"func",
"(",
"c",
"*",
"ClusterManager",
")",
"GetGossipState",
"(",
")",
"*",
"cluster",
".",
"ClusterState",
"{",
"gossipStoreKey",
":=",
"types",
".",
"StoreKey",
"(",
"heartbeatKey",
"+",
"c",
".",
"config",
".",
"ClusterId",
")",
"\n",
"nodeValue",
":=",
"c",
".",
"gossip",
".",
"GetStoreKeyValue",
"(",
"gossipStoreKey",
")",
"\n",
"nodes",
":=",
"make",
"(",
"[",
"]",
"types",
".",
"NodeValue",
",",
"len",
"(",
"nodeValue",
")",
",",
"len",
"(",
"nodeValue",
")",
")",
"\n",
"i",
":=",
"0",
"\n",
"for",
"_",
",",
"value",
":=",
"range",
"nodeValue",
"{",
"nodes",
"[",
"i",
"]",
"=",
"value",
"\n",
"i",
"++",
"\n",
"}",
"\n\n",
"return",
"&",
"cluster",
".",
"ClusterState",
"{",
"NodeStatus",
":",
"nodes",
"}",
"\n",
"}"
] | // GetGossipState returns current gossip state | [
"GetGossipState",
"returns",
"current",
"gossip",
"state"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/cluster/manager/manager.go#L959-L970 | train |
libopenstorage/openstorage | cluster/manager/manager.go | Start | func (c *ClusterManager) Start(
clusterMaxSize int,
nodeInitialized bool,
gossipPort string,
selfClusterDomain string,
) error {
return c.StartWithConfiguration(
clusterMaxSize,
nodeInitialized,
gossipPort,
[]string{ClusterDBKey},
selfClusterDomain,
&cluster.ClusterServerConfiguration{})
} | go | func (c *ClusterManager) Start(
clusterMaxSize int,
nodeInitialized bool,
gossipPort string,
selfClusterDomain string,
) error {
return c.StartWithConfiguration(
clusterMaxSize,
nodeInitialized,
gossipPort,
[]string{ClusterDBKey},
selfClusterDomain,
&cluster.ClusterServerConfiguration{})
} | [
"func",
"(",
"c",
"*",
"ClusterManager",
")",
"Start",
"(",
"clusterMaxSize",
"int",
",",
"nodeInitialized",
"bool",
",",
"gossipPort",
"string",
",",
"selfClusterDomain",
"string",
",",
")",
"error",
"{",
"return",
"c",
".",
"StartWithConfiguration",
"(",
"clusterMaxSize",
",",
"nodeInitialized",
",",
"gossipPort",
",",
"[",
"]",
"string",
"{",
"ClusterDBKey",
"}",
",",
"selfClusterDomain",
",",
"&",
"cluster",
".",
"ClusterServerConfiguration",
"{",
"}",
")",
"\n",
"}"
] | // Start initiates the cluster manager and the cluster state machine | [
"Start",
"initiates",
"the",
"cluster",
"manager",
"and",
"the",
"cluster",
"state",
"machine"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/cluster/manager/manager.go#L1254-L1267 | train |
libopenstorage/openstorage | cluster/manager/manager.go | NodeStatus | func (c *ClusterManager) NodeStatus() (api.Status, error) {
clusterNodeStatus := c.selfNode.Status
if clusterNodeStatus != api.Status_STATUS_OK {
// Status of this node as seen by Cluster Manager is not OK
// This takes highest precedence over other listener statuses.
// Returning our status
return clusterNodeStatus, nil
}
for e := c.listeners.Front(); e != nil; e = e.Next() {
listenerStatus := e.Value.(cluster.ClusterListener).ListenerStatus()
if listenerStatus == api.Status_STATUS_NONE {
continue
}
if int(listenerStatus.StatusKind()) >= int(clusterNodeStatus.StatusKind()) {
clusterNodeStatus = listenerStatus
}
}
return clusterNodeStatus, nil
} | go | func (c *ClusterManager) NodeStatus() (api.Status, error) {
clusterNodeStatus := c.selfNode.Status
if clusterNodeStatus != api.Status_STATUS_OK {
// Status of this node as seen by Cluster Manager is not OK
// This takes highest precedence over other listener statuses.
// Returning our status
return clusterNodeStatus, nil
}
for e := c.listeners.Front(); e != nil; e = e.Next() {
listenerStatus := e.Value.(cluster.ClusterListener).ListenerStatus()
if listenerStatus == api.Status_STATUS_NONE {
continue
}
if int(listenerStatus.StatusKind()) >= int(clusterNodeStatus.StatusKind()) {
clusterNodeStatus = listenerStatus
}
}
return clusterNodeStatus, nil
} | [
"func",
"(",
"c",
"*",
"ClusterManager",
")",
"NodeStatus",
"(",
")",
"(",
"api",
".",
"Status",
",",
"error",
")",
"{",
"clusterNodeStatus",
":=",
"c",
".",
"selfNode",
".",
"Status",
"\n\n",
"if",
"clusterNodeStatus",
"!=",
"api",
".",
"Status_STATUS_OK",
"{",
"// Status of this node as seen by Cluster Manager is not OK",
"// This takes highest precedence over other listener statuses.",
"// Returning our status",
"return",
"clusterNodeStatus",
",",
"nil",
"\n",
"}",
"\n\n",
"for",
"e",
":=",
"c",
".",
"listeners",
".",
"Front",
"(",
")",
";",
"e",
"!=",
"nil",
";",
"e",
"=",
"e",
".",
"Next",
"(",
")",
"{",
"listenerStatus",
":=",
"e",
".",
"Value",
".",
"(",
"cluster",
".",
"ClusterListener",
")",
".",
"ListenerStatus",
"(",
")",
"\n",
"if",
"listenerStatus",
"==",
"api",
".",
"Status_STATUS_NONE",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"int",
"(",
"listenerStatus",
".",
"StatusKind",
"(",
")",
")",
">=",
"int",
"(",
"clusterNodeStatus",
".",
"StatusKind",
"(",
")",
")",
"{",
"clusterNodeStatus",
"=",
"listenerStatus",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"clusterNodeStatus",
",",
"nil",
"\n",
"}"
] | // NodeStatus returns the status of a node. It compares the status maintained by the
// cluster manager and the provided listener and returns the appropriate one | [
"NodeStatus",
"returns",
"the",
"status",
"of",
"a",
"node",
".",
"It",
"compares",
"the",
"status",
"maintained",
"by",
"the",
"cluster",
"manager",
"and",
"the",
"provided",
"listener",
"and",
"returns",
"the",
"appropriate",
"one"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/cluster/manager/manager.go#L1373-L1394 | train |
libopenstorage/openstorage | cluster/manager/manager.go | PeerStatus | func (c *ClusterManager) PeerStatus(listenerName string) (map[string]api.Status, error) {
statusMap := make(map[string]api.Status)
var listenerStatusMap map[string]api.Status
for e := c.listeners.Front(); e != nil; e = e.Next() {
if e.Value.(cluster.ClusterListener).String() == listenerName {
listenerStatusMap = e.Value.(cluster.ClusterListener).ListenerPeerStatus()
break
}
}
c.nodeCacheLock.Lock()
defer c.nodeCacheLock.Unlock()
// Listener failed to provide peer status
if listenerStatusMap == nil || len(listenerStatusMap) == 0 {
for _, n := range c.nodeCache {
if n.Id == c.selfNode.Id {
// skip self
continue
}
statusMap[n.Id] = n.Status
}
return statusMap, nil
}
// Compare listener's peer statuses and cluster provider's peer statuses
for _, n := range c.nodeCache {
if n.Id == c.selfNode.Id {
// Skip self
continue
}
clusterNodeStatus := n.Status
listenerNodeStatus, ok := listenerStatusMap[n.Id]
if !ok {
// Could not find listener's peer status
// Using cluster provider's peer status
statusMap[n.Id] = clusterNodeStatus
}
if int(listenerNodeStatus.StatusKind()) >= int(clusterNodeStatus.StatusKind()) {
// Use listener's peer status
statusMap[n.Id] = listenerNodeStatus
} else {
// Use the cluster provider's peer status
statusMap[n.Id] = clusterNodeStatus
}
}
return statusMap, nil
} | go | func (c *ClusterManager) PeerStatus(listenerName string) (map[string]api.Status, error) {
statusMap := make(map[string]api.Status)
var listenerStatusMap map[string]api.Status
for e := c.listeners.Front(); e != nil; e = e.Next() {
if e.Value.(cluster.ClusterListener).String() == listenerName {
listenerStatusMap = e.Value.(cluster.ClusterListener).ListenerPeerStatus()
break
}
}
c.nodeCacheLock.Lock()
defer c.nodeCacheLock.Unlock()
// Listener failed to provide peer status
if listenerStatusMap == nil || len(listenerStatusMap) == 0 {
for _, n := range c.nodeCache {
if n.Id == c.selfNode.Id {
// skip self
continue
}
statusMap[n.Id] = n.Status
}
return statusMap, nil
}
// Compare listener's peer statuses and cluster provider's peer statuses
for _, n := range c.nodeCache {
if n.Id == c.selfNode.Id {
// Skip self
continue
}
clusterNodeStatus := n.Status
listenerNodeStatus, ok := listenerStatusMap[n.Id]
if !ok {
// Could not find listener's peer status
// Using cluster provider's peer status
statusMap[n.Id] = clusterNodeStatus
}
if int(listenerNodeStatus.StatusKind()) >= int(clusterNodeStatus.StatusKind()) {
// Use listener's peer status
statusMap[n.Id] = listenerNodeStatus
} else {
// Use the cluster provider's peer status
statusMap[n.Id] = clusterNodeStatus
}
}
return statusMap, nil
} | [
"func",
"(",
"c",
"*",
"ClusterManager",
")",
"PeerStatus",
"(",
"listenerName",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"api",
".",
"Status",
",",
"error",
")",
"{",
"statusMap",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"api",
".",
"Status",
")",
"\n",
"var",
"listenerStatusMap",
"map",
"[",
"string",
"]",
"api",
".",
"Status",
"\n",
"for",
"e",
":=",
"c",
".",
"listeners",
".",
"Front",
"(",
")",
";",
"e",
"!=",
"nil",
";",
"e",
"=",
"e",
".",
"Next",
"(",
")",
"{",
"if",
"e",
".",
"Value",
".",
"(",
"cluster",
".",
"ClusterListener",
")",
".",
"String",
"(",
")",
"==",
"listenerName",
"{",
"listenerStatusMap",
"=",
"e",
".",
"Value",
".",
"(",
"cluster",
".",
"ClusterListener",
")",
".",
"ListenerPeerStatus",
"(",
")",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"c",
".",
"nodeCacheLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"nodeCacheLock",
".",
"Unlock",
"(",
")",
"\n",
"// Listener failed to provide peer status",
"if",
"listenerStatusMap",
"==",
"nil",
"||",
"len",
"(",
"listenerStatusMap",
")",
"==",
"0",
"{",
"for",
"_",
",",
"n",
":=",
"range",
"c",
".",
"nodeCache",
"{",
"if",
"n",
".",
"Id",
"==",
"c",
".",
"selfNode",
".",
"Id",
"{",
"// skip self",
"continue",
"\n",
"}",
"\n",
"statusMap",
"[",
"n",
".",
"Id",
"]",
"=",
"n",
".",
"Status",
"\n",
"}",
"\n",
"return",
"statusMap",
",",
"nil",
"\n",
"}",
"\n",
"// Compare listener's peer statuses and cluster provider's peer statuses",
"for",
"_",
",",
"n",
":=",
"range",
"c",
".",
"nodeCache",
"{",
"if",
"n",
".",
"Id",
"==",
"c",
".",
"selfNode",
".",
"Id",
"{",
"// Skip self",
"continue",
"\n",
"}",
"\n",
"clusterNodeStatus",
":=",
"n",
".",
"Status",
"\n",
"listenerNodeStatus",
",",
"ok",
":=",
"listenerStatusMap",
"[",
"n",
".",
"Id",
"]",
"\n",
"if",
"!",
"ok",
"{",
"// Could not find listener's peer status",
"// Using cluster provider's peer status",
"statusMap",
"[",
"n",
".",
"Id",
"]",
"=",
"clusterNodeStatus",
"\n",
"}",
"\n",
"if",
"int",
"(",
"listenerNodeStatus",
".",
"StatusKind",
"(",
")",
")",
">=",
"int",
"(",
"clusterNodeStatus",
".",
"StatusKind",
"(",
")",
")",
"{",
"// Use listener's peer status",
"statusMap",
"[",
"n",
".",
"Id",
"]",
"=",
"listenerNodeStatus",
"\n",
"}",
"else",
"{",
"// Use the cluster provider's peer status",
"statusMap",
"[",
"n",
".",
"Id",
"]",
"=",
"clusterNodeStatus",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"statusMap",
",",
"nil",
"\n",
"}"
] | // PeerStatus returns the status of a peer node as seen by us | [
"PeerStatus",
"returns",
"the",
"status",
"of",
"a",
"peer",
"node",
"as",
"seen",
"by",
"us"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/cluster/manager/manager.go#L1397-L1441 | train |
libopenstorage/openstorage | cluster/manager/manager.go | Enumerate | func (c *ClusterManager) Enumerate() (api.Cluster, error) {
clusterState := api.Cluster{
Id: c.config.ClusterId,
Status: c.status,
NodeId: c.selfNode.Id,
}
if c.selfNode.Status == api.Status_STATUS_NOT_IN_QUORUM ||
c.selfNode.Status == api.Status_STATUS_MAINTENANCE {
// If the node is not yet ready, query the cluster db
// for node members since gossip is not ready yet.
clusterState.Nodes = c.enumerateFromClusterDB()
} else {
clusterState.Nodes = c.enumerateFromCache()
}
// Allow listeners to add/modify data
for e := c.listeners.Front(); e != nil; e = e.Next() {
if err := e.Value.(cluster.ClusterListener).Enumerate(clusterState); err != nil {
logrus.Warnf("listener %s enumerate failed: %v",
e.Value.(cluster.ClusterListener).String(), err)
continue
}
}
return clusterState, nil
} | go | func (c *ClusterManager) Enumerate() (api.Cluster, error) {
clusterState := api.Cluster{
Id: c.config.ClusterId,
Status: c.status,
NodeId: c.selfNode.Id,
}
if c.selfNode.Status == api.Status_STATUS_NOT_IN_QUORUM ||
c.selfNode.Status == api.Status_STATUS_MAINTENANCE {
// If the node is not yet ready, query the cluster db
// for node members since gossip is not ready yet.
clusterState.Nodes = c.enumerateFromClusterDB()
} else {
clusterState.Nodes = c.enumerateFromCache()
}
// Allow listeners to add/modify data
for e := c.listeners.Front(); e != nil; e = e.Next() {
if err := e.Value.(cluster.ClusterListener).Enumerate(clusterState); err != nil {
logrus.Warnf("listener %s enumerate failed: %v",
e.Value.(cluster.ClusterListener).String(), err)
continue
}
}
return clusterState, nil
} | [
"func",
"(",
"c",
"*",
"ClusterManager",
")",
"Enumerate",
"(",
")",
"(",
"api",
".",
"Cluster",
",",
"error",
")",
"{",
"clusterState",
":=",
"api",
".",
"Cluster",
"{",
"Id",
":",
"c",
".",
"config",
".",
"ClusterId",
",",
"Status",
":",
"c",
".",
"status",
",",
"NodeId",
":",
"c",
".",
"selfNode",
".",
"Id",
",",
"}",
"\n\n",
"if",
"c",
".",
"selfNode",
".",
"Status",
"==",
"api",
".",
"Status_STATUS_NOT_IN_QUORUM",
"||",
"c",
".",
"selfNode",
".",
"Status",
"==",
"api",
".",
"Status_STATUS_MAINTENANCE",
"{",
"// If the node is not yet ready, query the cluster db",
"// for node members since gossip is not ready yet.",
"clusterState",
".",
"Nodes",
"=",
"c",
".",
"enumerateFromClusterDB",
"(",
")",
"\n",
"}",
"else",
"{",
"clusterState",
".",
"Nodes",
"=",
"c",
".",
"enumerateFromCache",
"(",
")",
"\n",
"}",
"\n\n",
"// Allow listeners to add/modify data",
"for",
"e",
":=",
"c",
".",
"listeners",
".",
"Front",
"(",
")",
";",
"e",
"!=",
"nil",
";",
"e",
"=",
"e",
".",
"Next",
"(",
")",
"{",
"if",
"err",
":=",
"e",
".",
"Value",
".",
"(",
"cluster",
".",
"ClusterListener",
")",
".",
"Enumerate",
"(",
"clusterState",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"e",
".",
"Value",
".",
"(",
"cluster",
".",
"ClusterListener",
")",
".",
"String",
"(",
")",
",",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"clusterState",
",",
"nil",
"\n",
"}"
] | // Enumerate lists all the nodes in the cluster. | [
"Enumerate",
"lists",
"all",
"the",
"nodes",
"in",
"the",
"cluster",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/cluster/manager/manager.go#L1487-L1512 | train |
libopenstorage/openstorage | cluster/manager/manager.go | SetSize | func (c *ClusterManager) SetSize(size int) error {
kvdb := kvdb.Instance()
kvlock, err := kvdb.LockWithID(clusterLockKey, c.config.NodeId)
if err != nil {
logrus.Warnln("Unable to obtain cluster lock for updating config", err)
return nil
}
defer kvdb.Unlock(kvlock)
db, _, err := readClusterInfo()
if err != nil {
return err
}
db.Size = size
_, err = writeClusterInfo(&db)
return err
} | go | func (c *ClusterManager) SetSize(size int) error {
kvdb := kvdb.Instance()
kvlock, err := kvdb.LockWithID(clusterLockKey, c.config.NodeId)
if err != nil {
logrus.Warnln("Unable to obtain cluster lock for updating config", err)
return nil
}
defer kvdb.Unlock(kvlock)
db, _, err := readClusterInfo()
if err != nil {
return err
}
db.Size = size
_, err = writeClusterInfo(&db)
return err
} | [
"func",
"(",
"c",
"*",
"ClusterManager",
")",
"SetSize",
"(",
"size",
"int",
")",
"error",
"{",
"kvdb",
":=",
"kvdb",
".",
"Instance",
"(",
")",
"\n",
"kvlock",
",",
"err",
":=",
"kvdb",
".",
"LockWithID",
"(",
"clusterLockKey",
",",
"c",
".",
"config",
".",
"NodeId",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Warnln",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"defer",
"kvdb",
".",
"Unlock",
"(",
"kvlock",
")",
"\n\n",
"db",
",",
"_",
",",
"err",
":=",
"readClusterInfo",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"db",
".",
"Size",
"=",
"size",
"\n\n",
"_",
",",
"err",
"=",
"writeClusterInfo",
"(",
"&",
"db",
")",
"\n\n",
"return",
"err",
"\n",
"}"
] | // SetSize sets the maximum number of nodes in a cluster. | [
"SetSize",
"sets",
"the",
"maximum",
"number",
"of",
"nodes",
"in",
"a",
"cluster",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/cluster/manager/manager.go#L1549-L1568 | train |
libopenstorage/openstorage | cluster/manager/manager.go | NodeRemoveDone | func (c *ClusterManager) NodeRemoveDone(nodeID string, result error) {
// XXX: only storage will make callback right now
if result != nil {
msg := fmt.Sprintf("Storage failed to decommission node %s, "+
"error %s",
nodeID,
result)
logrus.Errorf(msg)
return
}
logrus.Infof("Cluster manager node remove done: node ID %s", nodeID)
// Remove osdconfig data from etcd
if err := c.configManager.DeleteNodeConf(nodeID); err != nil {
logrus.Warn("error removing node from osdconfig:", err)
}
if err := c.deleteNodeFromDB(nodeID); err != nil {
msg := fmt.Sprintf("Failed to delete node %s "+
"from cluster database, error %s",
nodeID, err)
logrus.Errorf(msg)
}
} | go | func (c *ClusterManager) NodeRemoveDone(nodeID string, result error) {
// XXX: only storage will make callback right now
if result != nil {
msg := fmt.Sprintf("Storage failed to decommission node %s, "+
"error %s",
nodeID,
result)
logrus.Errorf(msg)
return
}
logrus.Infof("Cluster manager node remove done: node ID %s", nodeID)
// Remove osdconfig data from etcd
if err := c.configManager.DeleteNodeConf(nodeID); err != nil {
logrus.Warn("error removing node from osdconfig:", err)
}
if err := c.deleteNodeFromDB(nodeID); err != nil {
msg := fmt.Sprintf("Failed to delete node %s "+
"from cluster database, error %s",
nodeID, err)
logrus.Errorf(msg)
}
} | [
"func",
"(",
"c",
"*",
"ClusterManager",
")",
"NodeRemoveDone",
"(",
"nodeID",
"string",
",",
"result",
"error",
")",
"{",
"// XXX: only storage will make callback right now",
"if",
"result",
"!=",
"nil",
"{",
"msg",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
"+",
"\"",
"\"",
",",
"nodeID",
",",
"result",
")",
"\n",
"logrus",
".",
"Errorf",
"(",
"msg",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"logrus",
".",
"Infof",
"(",
"\"",
"\"",
",",
"nodeID",
")",
"\n\n",
"// Remove osdconfig data from etcd",
"if",
"err",
":=",
"c",
".",
"configManager",
".",
"DeleteNodeConf",
"(",
"nodeID",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Warn",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"deleteNodeFromDB",
"(",
"nodeID",
")",
";",
"err",
"!=",
"nil",
"{",
"msg",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
"+",
"\"",
"\"",
",",
"nodeID",
",",
"err",
")",
"\n",
"logrus",
".",
"Errorf",
"(",
"msg",
")",
"\n",
"}",
"\n",
"}"
] | // NodeRemoveDone is called from the listeners when their job of Node removal is done. | [
"NodeRemoveDone",
"is",
"called",
"from",
"the",
"listeners",
"when",
"their",
"job",
"of",
"Node",
"removal",
"is",
"done",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/cluster/manager/manager.go#L1771-L1795 | train |
libopenstorage/openstorage | cluster/manager/manager.go | Shutdown | func (c *ClusterManager) Shutdown() error {
db, _, err := readClusterInfo()
if err != nil {
logrus.Warnf("Could not read cluster database (%v).", err)
return err
}
// Alert all listeners that we are shutting this node down.
for e := c.listeners.Front(); e != nil; e = e.Next() {
logrus.Infof("Shutting down %s", e.Value.(cluster.ClusterListener).String())
if err := e.Value.(cluster.ClusterListener).Halt(&c.selfNode, &db); err != nil {
logrus.Warnf("Failed to shutdown %s",
e.Value.(cluster.ClusterListener).String())
}
}
return nil
} | go | func (c *ClusterManager) Shutdown() error {
db, _, err := readClusterInfo()
if err != nil {
logrus.Warnf("Could not read cluster database (%v).", err)
return err
}
// Alert all listeners that we are shutting this node down.
for e := c.listeners.Front(); e != nil; e = e.Next() {
logrus.Infof("Shutting down %s", e.Value.(cluster.ClusterListener).String())
if err := e.Value.(cluster.ClusterListener).Halt(&c.selfNode, &db); err != nil {
logrus.Warnf("Failed to shutdown %s",
e.Value.(cluster.ClusterListener).String())
}
}
return nil
} | [
"func",
"(",
"c",
"*",
"ClusterManager",
")",
"Shutdown",
"(",
")",
"error",
"{",
"db",
",",
"_",
",",
"err",
":=",
"readClusterInfo",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// Alert all listeners that we are shutting this node down.",
"for",
"e",
":=",
"c",
".",
"listeners",
".",
"Front",
"(",
")",
";",
"e",
"!=",
"nil",
";",
"e",
"=",
"e",
".",
"Next",
"(",
")",
"{",
"logrus",
".",
"Infof",
"(",
"\"",
"\"",
",",
"e",
".",
"Value",
".",
"(",
"cluster",
".",
"ClusterListener",
")",
".",
"String",
"(",
")",
")",
"\n",
"if",
"err",
":=",
"e",
".",
"Value",
".",
"(",
"cluster",
".",
"ClusterListener",
")",
".",
"Halt",
"(",
"&",
"c",
".",
"selfNode",
",",
"&",
"db",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"e",
".",
"Value",
".",
"(",
"cluster",
".",
"ClusterListener",
")",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Shutdown can be called when THIS node is gracefully shutting down. | [
"Shutdown",
"can",
"be",
"called",
"when",
"THIS",
"node",
"is",
"gracefully",
"shutting",
"down",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/cluster/manager/manager.go#L1823-L1839 | train |
libopenstorage/openstorage | cluster/manager/manager.go | InspectDomain | func (c *ClusterManager) InspectDomain(name string) (*clusterdomain.ClusterDomainInfo, error) {
return c.clusterDomainManager.InspectDomain(name)
} | go | func (c *ClusterManager) InspectDomain(name string) (*clusterdomain.ClusterDomainInfo, error) {
return c.clusterDomainManager.InspectDomain(name)
} | [
"func",
"(",
"c",
"*",
"ClusterManager",
")",
"InspectDomain",
"(",
"name",
"string",
")",
"(",
"*",
"clusterdomain",
".",
"ClusterDomainInfo",
",",
"error",
")",
"{",
"return",
"c",
".",
"clusterDomainManager",
".",
"InspectDomain",
"(",
"name",
")",
"\n",
"}"
] | // InspectDomain returns the cluster domain info for the provided argument. | [
"InspectDomain",
"returns",
"the",
"cluster",
"domain",
"info",
"for",
"the",
"provided",
"argument",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/cluster/manager/manager.go#L1906-L1908 | train |
libopenstorage/openstorage | cluster/manager/manager.go | DeleteDomain | func (c *ClusterManager) DeleteDomain(name string) error {
return c.clusterDomainManager.DeleteDomain(name)
} | go | func (c *ClusterManager) DeleteDomain(name string) error {
return c.clusterDomainManager.DeleteDomain(name)
} | [
"func",
"(",
"c",
"*",
"ClusterManager",
")",
"DeleteDomain",
"(",
"name",
"string",
")",
"error",
"{",
"return",
"c",
".",
"clusterDomainManager",
".",
"DeleteDomain",
"(",
"name",
")",
"\n",
"}"
] | // DeleteDomain deletes a cluster domain entry | [
"DeleteDomain",
"deletes",
"a",
"cluster",
"domain",
"entry"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/cluster/manager/manager.go#L1911-L1913 | train |
libopenstorage/openstorage | cluster/manager/manager.go | SchedPolicyCreate | func (c *ClusterManager) SchedPolicyCreate(name, sched string) error {
return c.schedManager.SchedPolicyCreate(name, sched)
} | go | func (c *ClusterManager) SchedPolicyCreate(name, sched string) error {
return c.schedManager.SchedPolicyCreate(name, sched)
} | [
"func",
"(",
"c",
"*",
"ClusterManager",
")",
"SchedPolicyCreate",
"(",
"name",
",",
"sched",
"string",
")",
"error",
"{",
"return",
"c",
".",
"schedManager",
".",
"SchedPolicyCreate",
"(",
"name",
",",
"sched",
")",
"\n",
"}"
] | // SchedPolicyCreate creates a policy with given name and schedule. | [
"SchedPolicyCreate",
"creates",
"a",
"policy",
"with",
"given",
"name",
"and",
"schedule",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/cluster/manager/manager.go#L1946-L1948 | train |
libopenstorage/openstorage | cluster/manager/manager.go | SchedPolicyUpdate | func (c *ClusterManager) SchedPolicyUpdate(name, sched string) error {
return c.schedManager.SchedPolicyUpdate(name, sched)
} | go | func (c *ClusterManager) SchedPolicyUpdate(name, sched string) error {
return c.schedManager.SchedPolicyUpdate(name, sched)
} | [
"func",
"(",
"c",
"*",
"ClusterManager",
")",
"SchedPolicyUpdate",
"(",
"name",
",",
"sched",
"string",
")",
"error",
"{",
"return",
"c",
".",
"schedManager",
".",
"SchedPolicyUpdate",
"(",
"name",
",",
"sched",
")",
"\n",
"}"
] | // SchedPolicyUpdate updates a policy with given name and schedule. | [
"SchedPolicyUpdate",
"updates",
"a",
"policy",
"with",
"given",
"name",
"and",
"schedule",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/cluster/manager/manager.go#L1951-L1953 | train |
libopenstorage/openstorage | cluster/manager/manager.go | SchedPolicyDelete | func (c *ClusterManager) SchedPolicyDelete(name string) error {
return c.schedManager.SchedPolicyDelete(name)
} | go | func (c *ClusterManager) SchedPolicyDelete(name string) error {
return c.schedManager.SchedPolicyDelete(name)
} | [
"func",
"(",
"c",
"*",
"ClusterManager",
")",
"SchedPolicyDelete",
"(",
"name",
"string",
")",
"error",
"{",
"return",
"c",
".",
"schedManager",
".",
"SchedPolicyDelete",
"(",
"name",
")",
"\n",
"}"
] | // SchedPolicyDelete deletes a policy with given name. | [
"SchedPolicyDelete",
"deletes",
"a",
"policy",
"with",
"given",
"name",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/cluster/manager/manager.go#L1956-L1958 | train |
libopenstorage/openstorage | cluster/manager/manager.go | ObjectStoreInspect | func (c *ClusterManager) ObjectStoreInspect(objectstoreID string) (*api.ObjectstoreInfo, error) {
return c.objstoreManager.ObjectStoreInspect(objectstoreID)
} | go | func (c *ClusterManager) ObjectStoreInspect(objectstoreID string) (*api.ObjectstoreInfo, error) {
return c.objstoreManager.ObjectStoreInspect(objectstoreID)
} | [
"func",
"(",
"c",
"*",
"ClusterManager",
")",
"ObjectStoreInspect",
"(",
"objectstoreID",
"string",
")",
"(",
"*",
"api",
".",
"ObjectstoreInfo",
",",
"error",
")",
"{",
"return",
"c",
".",
"objstoreManager",
".",
"ObjectStoreInspect",
"(",
"objectstoreID",
")",
"\n",
"}"
] | // ObjectStoreInspect returns status of objectstore | [
"ObjectStoreInspect",
"returns",
"status",
"of",
"objectstore"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/cluster/manager/manager.go#L1971-L1973 | train |
libopenstorage/openstorage | cluster/manager/manager.go | ObjectStoreCreate | func (c *ClusterManager) ObjectStoreCreate(volumeID string) (*api.ObjectstoreInfo, error) {
return c.objstoreManager.ObjectStoreCreate(volumeID)
} | go | func (c *ClusterManager) ObjectStoreCreate(volumeID string) (*api.ObjectstoreInfo, error) {
return c.objstoreManager.ObjectStoreCreate(volumeID)
} | [
"func",
"(",
"c",
"*",
"ClusterManager",
")",
"ObjectStoreCreate",
"(",
"volumeID",
"string",
")",
"(",
"*",
"api",
".",
"ObjectstoreInfo",
",",
"error",
")",
"{",
"return",
"c",
".",
"objstoreManager",
".",
"ObjectStoreCreate",
"(",
"volumeID",
")",
"\n",
"}"
] | // ObjectStoreCreate objectstore on specified volume | [
"ObjectStoreCreate",
"objectstore",
"on",
"specified",
"volume"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/cluster/manager/manager.go#L1976-L1978 | train |
libopenstorage/openstorage | cluster/manager/manager.go | ObjectStoreDelete | func (c *ClusterManager) ObjectStoreDelete(objectstoreID string) error {
return c.objstoreManager.ObjectStoreDelete(objectstoreID)
} | go | func (c *ClusterManager) ObjectStoreDelete(objectstoreID string) error {
return c.objstoreManager.ObjectStoreDelete(objectstoreID)
} | [
"func",
"(",
"c",
"*",
"ClusterManager",
")",
"ObjectStoreDelete",
"(",
"objectstoreID",
"string",
")",
"error",
"{",
"return",
"c",
".",
"objstoreManager",
".",
"ObjectStoreDelete",
"(",
"objectstoreID",
")",
"\n",
"}"
] | // ObjectStoreDelete objectstore from cluster | [
"ObjectStoreDelete",
"objectstore",
"from",
"cluster"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/cluster/manager/manager.go#L1986-L1988 | train |
libopenstorage/openstorage | cluster/manager/manager.go | Uuid | func (c *ClusterManager) Uuid() string {
if len(c.config.ClusterUuid) == 0 {
return c.config.ClusterId
}
return c.config.ClusterUuid
} | go | func (c *ClusterManager) Uuid() string {
if len(c.config.ClusterUuid) == 0 {
return c.config.ClusterId
}
return c.config.ClusterUuid
} | [
"func",
"(",
"c",
"*",
"ClusterManager",
")",
"Uuid",
"(",
")",
"string",
"{",
"if",
"len",
"(",
"c",
".",
"config",
".",
"ClusterUuid",
")",
"==",
"0",
"{",
"return",
"c",
".",
"config",
".",
"ClusterId",
"\n",
"}",
"\n",
"return",
"c",
".",
"config",
".",
"ClusterUuid",
"\n",
"}"
] | // Uuid returns the unique id of the cluster | [
"Uuid",
"returns",
"the",
"unique",
"id",
"of",
"the",
"cluster"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/cluster/manager/manager.go#L2021-L2026 | train |
libopenstorage/openstorage | api/server/sdk/alerts.go | NewAlertsServer | func NewAlertsServer(filterDeleter alerts.FilterDeleter) api.OpenStorageAlertsServer {
return &alertsServer{
server: &sdkGrpcServer{alertHandler: filterDeleter},
}
} | go | func NewAlertsServer(filterDeleter alerts.FilterDeleter) api.OpenStorageAlertsServer {
return &alertsServer{
server: &sdkGrpcServer{alertHandler: filterDeleter},
}
} | [
"func",
"NewAlertsServer",
"(",
"filterDeleter",
"alerts",
".",
"FilterDeleter",
")",
"api",
".",
"OpenStorageAlertsServer",
"{",
"return",
"&",
"alertsServer",
"{",
"server",
":",
"&",
"sdkGrpcServer",
"{",
"alertHandler",
":",
"filterDeleter",
"}",
",",
"}",
"\n",
"}"
] | // NewAlertsServer provides an instance of alerts server interface. | [
"NewAlertsServer",
"provides",
"an",
"instance",
"of",
"alerts",
"server",
"interface",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/alerts.go#L49-L53 | train |
libopenstorage/openstorage | api/server/sdk/alerts.go | EnumerateWithFilters | func (g *alertsServer) EnumerateWithFilters(request *api.SdkAlertsEnumerateWithFiltersRequest, stream api.OpenStorageAlerts_EnumerateWithFiltersServer) error {
ctx := stream.Context()
if g.alert() == nil {
return status.Error(codes.Unavailable, "Resource has not been initialized")
}
queries := request.GetQueries()
if queries == nil {
return status.Error(codes.InvalidArgument, "Must provide at least one query")
}
// if input has deadline, ensure graceful exit within that deadline.
deadline, ok := ctx.Deadline()
var cancel context.CancelFunc
if ok {
// create a new context that will get done on deadline
ctx, cancel = context.WithTimeout(ctx, deadline.Sub(time.Now()))
defer cancel()
}
group, _ := errgroup.WithContext(ctx)
errChan := make(chan error)
filters := getFilters(queries)
// spawn err-group process.
group.Go(func() error {
if out, err := g.alert().Enumerate(filters...); err != nil {
return err
} else {
for i := 0; ; i++ {
start := i * alertChunkSize
stop := (i + 1) * alertChunkSize
if start >= len(out) {
break
}
if stop > len(out) {
stop = len(out)
}
resp := new(api.SdkAlertsEnumerateWithFiltersResponse)
resp.Alerts = append(resp.Alerts, out[start:stop]...)
if err := stream.Send(resp); err != nil {
return err
}
if stop == len(out) {
break
}
}
return nil
}
})
// wait for err-group processes to be done
go func() {
errChan <- group.Wait()
}()
// wait only as long as context deadline allows
select {
case err := <-errChan:
if err != nil {
return status.Errorf(codes.Internal, "error enumerating alerts: %v", err)
} else {
return nil
}
case <-ctx.Done():
return status.Error(codes.DeadlineExceeded,
"Deadline is reached, server side func exiting")
}
} | go | func (g *alertsServer) EnumerateWithFilters(request *api.SdkAlertsEnumerateWithFiltersRequest, stream api.OpenStorageAlerts_EnumerateWithFiltersServer) error {
ctx := stream.Context()
if g.alert() == nil {
return status.Error(codes.Unavailable, "Resource has not been initialized")
}
queries := request.GetQueries()
if queries == nil {
return status.Error(codes.InvalidArgument, "Must provide at least one query")
}
// if input has deadline, ensure graceful exit within that deadline.
deadline, ok := ctx.Deadline()
var cancel context.CancelFunc
if ok {
// create a new context that will get done on deadline
ctx, cancel = context.WithTimeout(ctx, deadline.Sub(time.Now()))
defer cancel()
}
group, _ := errgroup.WithContext(ctx)
errChan := make(chan error)
filters := getFilters(queries)
// spawn err-group process.
group.Go(func() error {
if out, err := g.alert().Enumerate(filters...); err != nil {
return err
} else {
for i := 0; ; i++ {
start := i * alertChunkSize
stop := (i + 1) * alertChunkSize
if start >= len(out) {
break
}
if stop > len(out) {
stop = len(out)
}
resp := new(api.SdkAlertsEnumerateWithFiltersResponse)
resp.Alerts = append(resp.Alerts, out[start:stop]...)
if err := stream.Send(resp); err != nil {
return err
}
if stop == len(out) {
break
}
}
return nil
}
})
// wait for err-group processes to be done
go func() {
errChan <- group.Wait()
}()
// wait only as long as context deadline allows
select {
case err := <-errChan:
if err != nil {
return status.Errorf(codes.Internal, "error enumerating alerts: %v", err)
} else {
return nil
}
case <-ctx.Done():
return status.Error(codes.DeadlineExceeded,
"Deadline is reached, server side func exiting")
}
} | [
"func",
"(",
"g",
"*",
"alertsServer",
")",
"EnumerateWithFilters",
"(",
"request",
"*",
"api",
".",
"SdkAlertsEnumerateWithFiltersRequest",
",",
"stream",
"api",
".",
"OpenStorageAlerts_EnumerateWithFiltersServer",
")",
"error",
"{",
"ctx",
":=",
"stream",
".",
"Context",
"(",
")",
"\n\n",
"if",
"g",
".",
"alert",
"(",
")",
"==",
"nil",
"{",
"return",
"status",
".",
"Error",
"(",
"codes",
".",
"Unavailable",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"queries",
":=",
"request",
".",
"GetQueries",
"(",
")",
"\n",
"if",
"queries",
"==",
"nil",
"{",
"return",
"status",
".",
"Error",
"(",
"codes",
".",
"InvalidArgument",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// if input has deadline, ensure graceful exit within that deadline.",
"deadline",
",",
"ok",
":=",
"ctx",
".",
"Deadline",
"(",
")",
"\n",
"var",
"cancel",
"context",
".",
"CancelFunc",
"\n",
"if",
"ok",
"{",
"// create a new context that will get done on deadline",
"ctx",
",",
"cancel",
"=",
"context",
".",
"WithTimeout",
"(",
"ctx",
",",
"deadline",
".",
"Sub",
"(",
"time",
".",
"Now",
"(",
")",
")",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"}",
"\n\n",
"group",
",",
"_",
":=",
"errgroup",
".",
"WithContext",
"(",
"ctx",
")",
"\n",
"errChan",
":=",
"make",
"(",
"chan",
"error",
")",
"\n\n",
"filters",
":=",
"getFilters",
"(",
"queries",
")",
"\n\n",
"// spawn err-group process.",
"group",
".",
"Go",
"(",
"func",
"(",
")",
"error",
"{",
"if",
"out",
",",
"err",
":=",
"g",
".",
"alert",
"(",
")",
".",
"Enumerate",
"(",
"filters",
"...",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"else",
"{",
"for",
"i",
":=",
"0",
";",
";",
"i",
"++",
"{",
"start",
":=",
"i",
"*",
"alertChunkSize",
"\n",
"stop",
":=",
"(",
"i",
"+",
"1",
")",
"*",
"alertChunkSize",
"\n\n",
"if",
"start",
">=",
"len",
"(",
"out",
")",
"{",
"break",
"\n",
"}",
"\n\n",
"if",
"stop",
">",
"len",
"(",
"out",
")",
"{",
"stop",
"=",
"len",
"(",
"out",
")",
"\n",
"}",
"\n\n",
"resp",
":=",
"new",
"(",
"api",
".",
"SdkAlertsEnumerateWithFiltersResponse",
")",
"\n",
"resp",
".",
"Alerts",
"=",
"append",
"(",
"resp",
".",
"Alerts",
",",
"out",
"[",
"start",
":",
"stop",
"]",
"...",
")",
"\n",
"if",
"err",
":=",
"stream",
".",
"Send",
"(",
"resp",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"stop",
"==",
"len",
"(",
"out",
")",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}",
")",
"\n\n",
"// wait for err-group processes to be done",
"go",
"func",
"(",
")",
"{",
"errChan",
"<-",
"group",
".",
"Wait",
"(",
")",
"\n",
"}",
"(",
")",
"\n\n",
"// wait only as long as context deadline allows",
"select",
"{",
"case",
"err",
":=",
"<-",
"errChan",
":",
"if",
"err",
"!=",
"nil",
"{",
"return",
"status",
".",
"Errorf",
"(",
"codes",
".",
"Internal",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"else",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"case",
"<-",
"ctx",
".",
"Done",
"(",
")",
":",
"return",
"status",
".",
"Error",
"(",
"codes",
".",
"DeadlineExceeded",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
] | // EnumerateWithFilters implements api.OpenStorageAlertsServer for alertsServer.
// Input context should ideally have a deadline, in which case, a
// graceful exit is ensured within that deadline. | [
"EnumerateWithFilters",
"implements",
"api",
".",
"OpenStorageAlertsServer",
"for",
"alertsServer",
".",
"Input",
"context",
"should",
"ideally",
"have",
"a",
"deadline",
"in",
"which",
"case",
"a",
"graceful",
"exit",
"is",
"ensured",
"within",
"that",
"deadline",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/alerts.go#L118-L192 | train |
libopenstorage/openstorage | api/server/sdk/alerts.go | Delete | func (g *alertsServer) Delete(ctx context.Context,
request *api.SdkAlertsDeleteRequest) (*api.SdkAlertsDeleteResponse, error) {
if g.alert() == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
queries := request.GetQueries()
if queries == nil {
return nil, status.Error(codes.InvalidArgument, "Must provide at least one query")
}
// if input has deadline, ensure graceful exit within that deadline.
deadline, ok := ctx.Deadline()
var cancel context.CancelFunc
if ok {
// create a new context that will get done on deadline
ctx, cancel = context.WithTimeout(ctx, deadline.Sub(time.Now()))
defer cancel()
}
group, _ := errgroup.WithContext(ctx)
errChan := make(chan error)
resp := new(api.SdkAlertsDeleteResponse)
filters := getFilters(queries)
// spawn err-group process.
group.Go(func() error {
return g.alert().Delete(filters...)
})
// wait for err-group processes to be done
go func() {
errChan <- group.Wait()
}()
// wait only as long as context deadline allows
select {
case err := <-errChan:
if err != nil {
return nil, status.Errorf(codes.Internal, "error deleting alerts: %v", err)
} else {
return resp, nil
}
case <-ctx.Done():
return nil, status.Error(codes.DeadlineExceeded,
"Deadline is reached, server side func exiting")
}
} | go | func (g *alertsServer) Delete(ctx context.Context,
request *api.SdkAlertsDeleteRequest) (*api.SdkAlertsDeleteResponse, error) {
if g.alert() == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
queries := request.GetQueries()
if queries == nil {
return nil, status.Error(codes.InvalidArgument, "Must provide at least one query")
}
// if input has deadline, ensure graceful exit within that deadline.
deadline, ok := ctx.Deadline()
var cancel context.CancelFunc
if ok {
// create a new context that will get done on deadline
ctx, cancel = context.WithTimeout(ctx, deadline.Sub(time.Now()))
defer cancel()
}
group, _ := errgroup.WithContext(ctx)
errChan := make(chan error)
resp := new(api.SdkAlertsDeleteResponse)
filters := getFilters(queries)
// spawn err-group process.
group.Go(func() error {
return g.alert().Delete(filters...)
})
// wait for err-group processes to be done
go func() {
errChan <- group.Wait()
}()
// wait only as long as context deadline allows
select {
case err := <-errChan:
if err != nil {
return nil, status.Errorf(codes.Internal, "error deleting alerts: %v", err)
} else {
return resp, nil
}
case <-ctx.Done():
return nil, status.Error(codes.DeadlineExceeded,
"Deadline is reached, server side func exiting")
}
} | [
"func",
"(",
"g",
"*",
"alertsServer",
")",
"Delete",
"(",
"ctx",
"context",
".",
"Context",
",",
"request",
"*",
"api",
".",
"SdkAlertsDeleteRequest",
")",
"(",
"*",
"api",
".",
"SdkAlertsDeleteResponse",
",",
"error",
")",
"{",
"if",
"g",
".",
"alert",
"(",
")",
"==",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"Unavailable",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"queries",
":=",
"request",
".",
"GetQueries",
"(",
")",
"\n",
"if",
"queries",
"==",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"InvalidArgument",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// if input has deadline, ensure graceful exit within that deadline.",
"deadline",
",",
"ok",
":=",
"ctx",
".",
"Deadline",
"(",
")",
"\n",
"var",
"cancel",
"context",
".",
"CancelFunc",
"\n",
"if",
"ok",
"{",
"// create a new context that will get done on deadline",
"ctx",
",",
"cancel",
"=",
"context",
".",
"WithTimeout",
"(",
"ctx",
",",
"deadline",
".",
"Sub",
"(",
"time",
".",
"Now",
"(",
")",
")",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"}",
"\n\n",
"group",
",",
"_",
":=",
"errgroup",
".",
"WithContext",
"(",
"ctx",
")",
"\n",
"errChan",
":=",
"make",
"(",
"chan",
"error",
")",
"\n\n",
"resp",
":=",
"new",
"(",
"api",
".",
"SdkAlertsDeleteResponse",
")",
"\n\n",
"filters",
":=",
"getFilters",
"(",
"queries",
")",
"\n\n",
"// spawn err-group process.",
"group",
".",
"Go",
"(",
"func",
"(",
")",
"error",
"{",
"return",
"g",
".",
"alert",
"(",
")",
".",
"Delete",
"(",
"filters",
"...",
")",
"\n",
"}",
")",
"\n\n",
"// wait for err-group processes to be done",
"go",
"func",
"(",
")",
"{",
"errChan",
"<-",
"group",
".",
"Wait",
"(",
")",
"\n",
"}",
"(",
")",
"\n\n",
"// wait only as long as context deadline allows",
"select",
"{",
"case",
"err",
":=",
"<-",
"errChan",
":",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"Internal",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"else",
"{",
"return",
"resp",
",",
"nil",
"\n",
"}",
"\n",
"case",
"<-",
"ctx",
".",
"Done",
"(",
")",
":",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"DeadlineExceeded",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
] | // Delete implements api.OpenStorageAlertsServer for alertsServer.
// Input context should ideally have a deadline, in which case, a
// graceful exit is ensured within that deadline. | [
"Delete",
"implements",
"api",
".",
"OpenStorageAlertsServer",
"for",
"alertsServer",
".",
"Input",
"context",
"should",
"ideally",
"have",
"a",
"deadline",
"in",
"which",
"case",
"a",
"graceful",
"exit",
"is",
"ensured",
"within",
"that",
"deadline",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/alerts.go#L197-L246 | train |
libopenstorage/openstorage | osdconfig/helper.go | newInMemKvdb | func newInMemKvdb() (kvdb.Kvdb, error) {
// create in memory kvdb
if kv, err := kvdb.New(mem.Name, "", []string{}, nil, nil); err != nil {
return nil, err
} else {
return kv, nil
}
} | go | func newInMemKvdb() (kvdb.Kvdb, error) {
// create in memory kvdb
if kv, err := kvdb.New(mem.Name, "", []string{}, nil, nil); err != nil {
return nil, err
} else {
return kv, nil
}
} | [
"func",
"newInMemKvdb",
"(",
")",
"(",
"kvdb",
".",
"Kvdb",
",",
"error",
")",
"{",
"// create in memory kvdb",
"if",
"kv",
",",
"err",
":=",
"kvdb",
".",
"New",
"(",
"mem",
".",
"Name",
",",
"\"",
"\"",
",",
"[",
"]",
"string",
"{",
"}",
",",
"nil",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"else",
"{",
"return",
"kv",
",",
"nil",
"\n",
"}",
"\n",
"}"
] | // helper function go get a new kvdb instance | [
"helper",
"function",
"go",
"get",
"a",
"new",
"kvdb",
"instance"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/osdconfig/helper.go#L12-L19 | train |
libopenstorage/openstorage | osdconfig/helper.go | getNodeKeyFromNodeID | func getNodeKeyFromNodeID(nodeID string) string {
dbg.Assert(len(nodeID) > 0, "%s", "nodeID string can not be empty")
return filepath.Join(baseKey, nodeKey, nodeID)
} | go | func getNodeKeyFromNodeID(nodeID string) string {
dbg.Assert(len(nodeID) > 0, "%s", "nodeID string can not be empty")
return filepath.Join(baseKey, nodeKey, nodeID)
} | [
"func",
"getNodeKeyFromNodeID",
"(",
"nodeID",
"string",
")",
"string",
"{",
"dbg",
".",
"Assert",
"(",
"len",
"(",
"nodeID",
")",
">",
"0",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"return",
"filepath",
".",
"Join",
"(",
"baseKey",
",",
"nodeKey",
",",
"nodeID",
")",
"\n",
"}"
] | // helper function to obtain kvdb key for node based on nodeID
// the check for empty nodeID needs to be done elsewhere | [
"helper",
"function",
"to",
"obtain",
"kvdb",
"key",
"for",
"node",
"based",
"on",
"nodeID",
"the",
"check",
"for",
"empty",
"nodeID",
"needs",
"to",
"be",
"done",
"elsewhere"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/osdconfig/helper.go#L23-L26 | train |
libopenstorage/openstorage | osdconfig/helper.go | copyData | func copyData(wd *data) *data {
wd2 := new(data)
wd2.Key = wd.Key
wd2.Value = make([]byte, len(wd.Value))
copy(wd2.Value, wd.Value)
return wd2
} | go | func copyData(wd *data) *data {
wd2 := new(data)
wd2.Key = wd.Key
wd2.Value = make([]byte, len(wd.Value))
copy(wd2.Value, wd.Value)
return wd2
} | [
"func",
"copyData",
"(",
"wd",
"*",
"data",
")",
"*",
"data",
"{",
"wd2",
":=",
"new",
"(",
"data",
")",
"\n",
"wd2",
".",
"Key",
"=",
"wd",
".",
"Key",
"\n",
"wd2",
".",
"Value",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"len",
"(",
"wd",
".",
"Value",
")",
")",
"\n",
"copy",
"(",
"wd2",
".",
"Value",
",",
"wd",
".",
"Value",
")",
"\n",
"return",
"wd2",
"\n",
"}"
] | // copyData is a helper function to copy data to be fed to each callback | [
"copyData",
"is",
"a",
"helper",
"function",
"to",
"copy",
"data",
"to",
"be",
"fed",
"to",
"each",
"callback"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/osdconfig/helper.go#L29-L35 | train |
libopenstorage/openstorage | alerts/api.go | NewManager | func NewManager(kv kvdb.Kvdb, options ...Option) (Manager, error) {
return newManager(kv, options...)
} | go | func NewManager(kv kvdb.Kvdb, options ...Option) (Manager, error) {
return newManager(kv, options...)
} | [
"func",
"NewManager",
"(",
"kv",
"kvdb",
".",
"Kvdb",
",",
"options",
"...",
"Option",
")",
"(",
"Manager",
",",
"error",
")",
"{",
"return",
"newManager",
"(",
"kv",
",",
"options",
"...",
")",
"\n",
"}"
] | // NewManager obtains instance of Manager for alerts management. | [
"NewManager",
"obtains",
"instance",
"of",
"Manager",
"for",
"alerts",
"management",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/alerts/api.go#L11-L13 | train |
libopenstorage/openstorage | alerts/api.go | NewFilterDeleter | func NewFilterDeleter(kv kvdb.Kvdb, options ...Option) (FilterDeleter, error) {
return newManager(kv, options...)
} | go | func NewFilterDeleter(kv kvdb.Kvdb, options ...Option) (FilterDeleter, error) {
return newManager(kv, options...)
} | [
"func",
"NewFilterDeleter",
"(",
"kv",
"kvdb",
".",
"Kvdb",
",",
"options",
"...",
"Option",
")",
"(",
"FilterDeleter",
",",
"error",
")",
"{",
"return",
"newManager",
"(",
"kv",
",",
"options",
"...",
")",
"\n",
"}"
] | // NewFilterDeleter obtains instance of FilterDeleter for alerts enumeration and deletion. | [
"NewFilterDeleter",
"obtains",
"instance",
"of",
"FilterDeleter",
"for",
"alerts",
"enumeration",
"and",
"deletion",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/alerts/api.go#L16-L18 | train |
libopenstorage/openstorage | alerts/api.go | NewTimeSpanOption | func NewTimeSpanOption(start, stop time.Time) Option {
return &option{optionType: timeSpanOption, value: NewTimeSpanFilter(start, stop)}
} | go | func NewTimeSpanOption(start, stop time.Time) Option {
return &option{optionType: timeSpanOption, value: NewTimeSpanFilter(start, stop)}
} | [
"func",
"NewTimeSpanOption",
"(",
"start",
",",
"stop",
"time",
".",
"Time",
")",
"Option",
"{",
"return",
"&",
"option",
"{",
"optionType",
":",
"timeSpanOption",
",",
"value",
":",
"NewTimeSpanFilter",
"(",
"start",
",",
"stop",
")",
"}",
"\n",
"}"
] | // NewTimeSpanOption provides an option to be used in filter definition.
// Filters that take options, apply options only during matching alerts. | [
"NewTimeSpanOption",
"provides",
"an",
"option",
"to",
"be",
"used",
"in",
"filter",
"definition",
".",
"Filters",
"that",
"take",
"options",
"apply",
"options",
"only",
"during",
"matching",
"alerts",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/alerts/api.go#L29-L31 | train |
libopenstorage/openstorage | alerts/api.go | NewCountSpanOption | func NewCountSpanOption(minCount, maxCount int64) Option {
return &option{optionType: countSpanOption, value: NewCountSpanFilter(minCount, maxCount)}
} | go | func NewCountSpanOption(minCount, maxCount int64) Option {
return &option{optionType: countSpanOption, value: NewCountSpanFilter(minCount, maxCount)}
} | [
"func",
"NewCountSpanOption",
"(",
"minCount",
",",
"maxCount",
"int64",
")",
"Option",
"{",
"return",
"&",
"option",
"{",
"optionType",
":",
"countSpanOption",
",",
"value",
":",
"NewCountSpanFilter",
"(",
"minCount",
",",
"maxCount",
")",
"}",
"\n",
"}"
] | // NewCountSpanOption provides an option to be used in filter definition that
// accept options. Only filters that are efficient in querying kvdb accept options
// and apply these options during matching alerts. | [
"NewCountSpanOption",
"provides",
"an",
"option",
"to",
"be",
"used",
"in",
"filter",
"definition",
"that",
"accept",
"options",
".",
"Only",
"filters",
"that",
"are",
"efficient",
"in",
"querying",
"kvdb",
"accept",
"options",
"and",
"apply",
"these",
"options",
"during",
"matching",
"alerts",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/alerts/api.go#L36-L38 | train |
libopenstorage/openstorage | alerts/api.go | NewMinSeverityOption | func NewMinSeverityOption(minSev api.SeverityType) Option {
return &option{optionType: minSeverityOption, value: NewMinSeverityFilter(minSev)}
} | go | func NewMinSeverityOption(minSev api.SeverityType) Option {
return &option{optionType: minSeverityOption, value: NewMinSeverityFilter(minSev)}
} | [
"func",
"NewMinSeverityOption",
"(",
"minSev",
"api",
".",
"SeverityType",
")",
"Option",
"{",
"return",
"&",
"option",
"{",
"optionType",
":",
"minSeverityOption",
",",
"value",
":",
"NewMinSeverityFilter",
"(",
"minSev",
")",
"}",
"\n",
"}"
] | // NewMinSeverityOption provides an option to be used during filter creation that
// accept such options. Only filters that are efficient in querying kvdb accept options
// and apply these options during matching alerts. | [
"NewMinSeverityOption",
"provides",
"an",
"option",
"to",
"be",
"used",
"during",
"filter",
"creation",
"that",
"accept",
"such",
"options",
".",
"Only",
"filters",
"that",
"are",
"efficient",
"in",
"querying",
"kvdb",
"accept",
"options",
"and",
"apply",
"these",
"options",
"during",
"matching",
"alerts",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/alerts/api.go#L43-L45 | train |
libopenstorage/openstorage | alerts/api.go | NewFlagCheckOption | func NewFlagCheckOption(flag bool) Option {
return &option{optionType: flagCheckOption, value: NewFlagCheckFilter(flag)}
} | go | func NewFlagCheckOption(flag bool) Option {
return &option{optionType: flagCheckOption, value: NewFlagCheckFilter(flag)}
} | [
"func",
"NewFlagCheckOption",
"(",
"flag",
"bool",
")",
"Option",
"{",
"return",
"&",
"option",
"{",
"optionType",
":",
"flagCheckOption",
",",
"value",
":",
"NewFlagCheckFilter",
"(",
"flag",
")",
"}",
"\n",
"}"
] | // NewFlagCheckOptions provides an option to be used during filter creation that
// accept such options. Only filters that are efficient in querying kvdb accept options
// and apply these options during matching alerts. | [
"NewFlagCheckOptions",
"provides",
"an",
"option",
"to",
"be",
"used",
"during",
"filter",
"creation",
"that",
"accept",
"such",
"options",
".",
"Only",
"filters",
"that",
"are",
"efficient",
"in",
"querying",
"kvdb",
"accept",
"options",
"and",
"apply",
"these",
"options",
"during",
"matching",
"alerts",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/alerts/api.go#L50-L52 | train |
libopenstorage/openstorage | alerts/api.go | NewResourceIdOption | func NewResourceIdOption(resourceId string) Option {
return &option{optionType: resourceIdOption, value: NewMatchResourceIDFilter(resourceId)}
} | go | func NewResourceIdOption(resourceId string) Option {
return &option{optionType: resourceIdOption, value: NewMatchResourceIDFilter(resourceId)}
} | [
"func",
"NewResourceIdOption",
"(",
"resourceId",
"string",
")",
"Option",
"{",
"return",
"&",
"option",
"{",
"optionType",
":",
"resourceIdOption",
",",
"value",
":",
"NewMatchResourceIDFilter",
"(",
"resourceId",
")",
"}",
"\n",
"}"
] | // NewResourceIdOption provides an option to be used during filter creation that
// accept such options. Only filters that are efficient in querying kvdb accept options
// and apply these options during matching alerts. | [
"NewResourceIdOption",
"provides",
"an",
"option",
"to",
"be",
"used",
"during",
"filter",
"creation",
"that",
"accept",
"such",
"options",
".",
"Only",
"filters",
"that",
"are",
"efficient",
"in",
"querying",
"kvdb",
"accept",
"options",
"and",
"apply",
"these",
"options",
"during",
"matching",
"alerts",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/alerts/api.go#L57-L59 | train |
libopenstorage/openstorage | alerts/api.go | NewTimeSpanFilter | func NewTimeSpanFilter(start, stop time.Time) Filter {
return &filter{filterType: timeSpanFilter, value: timeZone{start: start, stop: stop}}
} | go | func NewTimeSpanFilter(start, stop time.Time) Filter {
return &filter{filterType: timeSpanFilter, value: timeZone{start: start, stop: stop}}
} | [
"func",
"NewTimeSpanFilter",
"(",
"start",
",",
"stop",
"time",
".",
"Time",
")",
"Filter",
"{",
"return",
"&",
"filter",
"{",
"filterType",
":",
"timeSpanFilter",
",",
"value",
":",
"timeZone",
"{",
"start",
":",
"start",
",",
"stop",
":",
"stop",
"}",
"}",
"\n",
"}"
] | // NewTimeSpanFilter creates a filter that matches on alert raised in a given time window. | [
"NewTimeSpanFilter",
"creates",
"a",
"filter",
"that",
"matches",
"on",
"alert",
"raised",
"in",
"a",
"given",
"time",
"window",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/alerts/api.go#L83-L85 | train |
libopenstorage/openstorage | alerts/api.go | NewCountSpanFilter | func NewCountSpanFilter(minCount, maxCount int64) Filter {
return &filter{filterType: countSpanFilter, value: []int64{minCount, maxCount}}
} | go | func NewCountSpanFilter(minCount, maxCount int64) Filter {
return &filter{filterType: countSpanFilter, value: []int64{minCount, maxCount}}
} | [
"func",
"NewCountSpanFilter",
"(",
"minCount",
",",
"maxCount",
"int64",
")",
"Filter",
"{",
"return",
"&",
"filter",
"{",
"filterType",
":",
"countSpanFilter",
",",
"value",
":",
"[",
"]",
"int64",
"{",
"minCount",
",",
"maxCount",
"}",
"}",
"\n",
"}"
] | // NewCountSpanFilter provides a filter that matches on alert count. | [
"NewCountSpanFilter",
"provides",
"a",
"filter",
"that",
"matches",
"on",
"alert",
"count",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/alerts/api.go#L100-L102 | train |
libopenstorage/openstorage | alerts/api.go | NewMinSeverityFilter | func NewMinSeverityFilter(minSev api.SeverityType) Filter {
return &filter{filterType: minSeverityFilter, value: minSev}
} | go | func NewMinSeverityFilter(minSev api.SeverityType) Filter {
return &filter{filterType: minSeverityFilter, value: minSev}
} | [
"func",
"NewMinSeverityFilter",
"(",
"minSev",
"api",
".",
"SeverityType",
")",
"Filter",
"{",
"return",
"&",
"filter",
"{",
"filterType",
":",
"minSeverityFilter",
",",
"value",
":",
"minSev",
"}",
"\n",
"}"
] | // NewMinSeverityFilter provides a filter that matches on alert when severity is greater than
// or equal to the minSev value. | [
"NewMinSeverityFilter",
"provides",
"a",
"filter",
"that",
"matches",
"on",
"alert",
"when",
"severity",
"is",
"greater",
"than",
"or",
"equal",
"to",
"the",
"minSev",
"value",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/alerts/api.go#L106-L108 | train |
libopenstorage/openstorage | alerts/api.go | NewDeleteAction | func NewDeleteAction(filters ...Filter) Action {
return &action{action: deleteAction, filters: filters, f: deleteActionFunc}
} | go | func NewDeleteAction(filters ...Filter) Action {
return &action{action: deleteAction, filters: filters, f: deleteActionFunc}
} | [
"func",
"NewDeleteAction",
"(",
"filters",
"...",
"Filter",
")",
"Action",
"{",
"return",
"&",
"action",
"{",
"action",
":",
"deleteAction",
",",
"filters",
":",
"filters",
",",
"f",
":",
"deleteActionFunc",
"}",
"\n",
"}"
] | // Action API
// NewDeleteAction deletes alert entries based on filters. | [
"Action",
"API",
"NewDeleteAction",
"deletes",
"alert",
"entries",
"based",
"on",
"filters",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/alerts/api.go#L123-L125 | train |
libopenstorage/openstorage | alerts/api.go | NewClearAction | func NewClearAction(filters ...Filter) Action {
return &action{action: clearAction, filters: filters, f: clearActionFunc}
} | go | func NewClearAction(filters ...Filter) Action {
return &action{action: clearAction, filters: filters, f: clearActionFunc}
} | [
"func",
"NewClearAction",
"(",
"filters",
"...",
"Filter",
")",
"Action",
"{",
"return",
"&",
"action",
"{",
"action",
":",
"clearAction",
",",
"filters",
":",
"filters",
",",
"f",
":",
"clearActionFunc",
"}",
"\n",
"}"
] | // NewClearAction marks alert entries as cleared that get deleted after half a day of life in kvdb. | [
"NewClearAction",
"marks",
"alert",
"entries",
"as",
"cleared",
"that",
"get",
"deleted",
"after",
"half",
"a",
"day",
"of",
"life",
"in",
"kvdb",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/alerts/api.go#L128-L130 | train |
libopenstorage/openstorage | alerts/api.go | NewCustomAction | func NewCustomAction(f func(manager Manager, filters ...Filter) error, filters ...Filter) Action {
return &action{action: CustomAction, filters: filters, f: f}
} | go | func NewCustomAction(f func(manager Manager, filters ...Filter) error, filters ...Filter) Action {
return &action{action: CustomAction, filters: filters, f: f}
} | [
"func",
"NewCustomAction",
"(",
"f",
"func",
"(",
"manager",
"Manager",
",",
"filters",
"...",
"Filter",
")",
"error",
",",
"filters",
"...",
"Filter",
")",
"Action",
"{",
"return",
"&",
"action",
"{",
"action",
":",
"CustomAction",
",",
"filters",
":",
"filters",
",",
"f",
":",
"f",
"}",
"\n",
"}"
] | // NewCustomAction takes custom action using user defined function. | [
"NewCustomAction",
"takes",
"custom",
"action",
"using",
"user",
"defined",
"function",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/alerts/api.go#L133-L135 | train |
libopenstorage/openstorage | alerts/api.go | NewRaiseRule | func NewRaiseRule(name string, filter Filter, action Action) Rule {
return &rule{name: name, event: raiseEvent, filter: filter, action: action}
} | go | func NewRaiseRule(name string, filter Filter, action Action) Rule {
return &rule{name: name, event: raiseEvent, filter: filter, action: action}
} | [
"func",
"NewRaiseRule",
"(",
"name",
"string",
",",
"filter",
"Filter",
",",
"action",
"Action",
")",
"Rule",
"{",
"return",
"&",
"rule",
"{",
"name",
":",
"name",
",",
"event",
":",
"raiseEvent",
",",
"filter",
":",
"filter",
",",
"action",
":",
"action",
"}",
"\n",
"}"
] | // Rule API
// NewRaiseRule creates a rule that runs action when a raised alerts matche filter.
// Action happens before incoming alert is raised. | [
"Rule",
"API",
"NewRaiseRule",
"creates",
"a",
"rule",
"that",
"runs",
"action",
"when",
"a",
"raised",
"alerts",
"matche",
"filter",
".",
"Action",
"happens",
"before",
"incoming",
"alert",
"is",
"raised",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/alerts/api.go#L141-L143 | train |
libopenstorage/openstorage | alerts/api.go | NewDeleteRule | func NewDeleteRule(name string, filter Filter, action Action) Rule {
return &rule{name: name, event: deleteEvent, filter: filter, action: action}
} | go | func NewDeleteRule(name string, filter Filter, action Action) Rule {
return &rule{name: name, event: deleteEvent, filter: filter, action: action}
} | [
"func",
"NewDeleteRule",
"(",
"name",
"string",
",",
"filter",
"Filter",
",",
"action",
"Action",
")",
"Rule",
"{",
"return",
"&",
"rule",
"{",
"name",
":",
"name",
",",
"event",
":",
"deleteEvent",
",",
"filter",
":",
"filter",
",",
"action",
":",
"action",
"}",
"\n",
"}"
] | // NewDeleteRule creates a rule that runs action when deleted alerts matche filter.
// Action happens after matching alerts are deleted. | [
"NewDeleteRule",
"creates",
"a",
"rule",
"that",
"runs",
"action",
"when",
"deleted",
"alerts",
"matche",
"filter",
".",
"Action",
"happens",
"after",
"matching",
"alerts",
"are",
"deleted",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/alerts/api.go#L147-L149 | train |
libopenstorage/openstorage | volume/volume.go | NewVolumeDriverRegistry | func NewVolumeDriverRegistry(nameToInitFunc map[string]func(map[string]string) (VolumeDriver, error)) VolumeDriverRegistry {
return newVolumeDriverRegistry(nameToInitFunc)
} | go | func NewVolumeDriverRegistry(nameToInitFunc map[string]func(map[string]string) (VolumeDriver, error)) VolumeDriverRegistry {
return newVolumeDriverRegistry(nameToInitFunc)
} | [
"func",
"NewVolumeDriverRegistry",
"(",
"nameToInitFunc",
"map",
"[",
"string",
"]",
"func",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"VolumeDriver",
",",
"error",
")",
")",
"VolumeDriverRegistry",
"{",
"return",
"newVolumeDriverRegistry",
"(",
"nameToInitFunc",
")",
"\n",
"}"
] | // NewVolumeDriverRegistry constructs a new VolumeDriverRegistry. | [
"NewVolumeDriverRegistry",
"constructs",
"a",
"new",
"VolumeDriverRegistry",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/volume/volume.go#L294-L296 | train |
libopenstorage/openstorage | volume/drivers/btrfs/btrfs.go | Create | func (d *driver) Create(
locator *api.VolumeLocator,
source *api.Source,
spec *api.VolumeSpec,
) (string, error) {
if spec.Format != api.FSType_FS_TYPE_BTRFS && spec.Format != api.FSType_FS_TYPE_NONE {
return "", fmt.Errorf("Filesystem format (%v) must be %v", spec.Format.SimpleString(), api.FSType_FS_TYPE_BTRFS.SimpleString())
}
volume := common.NewVolume(
uuid.New(),
api.FSType_FS_TYPE_BTRFS,
locator,
source,
spec,
)
if err := d.CreateVol(volume); err != nil {
return "", err
}
if err := d.btrfs.Create(volume.Id, "", "", nil); err != nil {
return "", err
}
devicePath, err := d.btrfs.Get(volume.Id, "")
if err != nil {
return volume.Id, err
}
volume.DevicePath = devicePath
return volume.Id, d.UpdateVol(volume)
} | go | func (d *driver) Create(
locator *api.VolumeLocator,
source *api.Source,
spec *api.VolumeSpec,
) (string, error) {
if spec.Format != api.FSType_FS_TYPE_BTRFS && spec.Format != api.FSType_FS_TYPE_NONE {
return "", fmt.Errorf("Filesystem format (%v) must be %v", spec.Format.SimpleString(), api.FSType_FS_TYPE_BTRFS.SimpleString())
}
volume := common.NewVolume(
uuid.New(),
api.FSType_FS_TYPE_BTRFS,
locator,
source,
spec,
)
if err := d.CreateVol(volume); err != nil {
return "", err
}
if err := d.btrfs.Create(volume.Id, "", "", nil); err != nil {
return "", err
}
devicePath, err := d.btrfs.Get(volume.Id, "")
if err != nil {
return volume.Id, err
}
volume.DevicePath = devicePath
return volume.Id, d.UpdateVol(volume)
} | [
"func",
"(",
"d",
"*",
"driver",
")",
"Create",
"(",
"locator",
"*",
"api",
".",
"VolumeLocator",
",",
"source",
"*",
"api",
".",
"Source",
",",
"spec",
"*",
"api",
".",
"VolumeSpec",
",",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"spec",
".",
"Format",
"!=",
"api",
".",
"FSType_FS_TYPE_BTRFS",
"&&",
"spec",
".",
"Format",
"!=",
"api",
".",
"FSType_FS_TYPE_NONE",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"spec",
".",
"Format",
".",
"SimpleString",
"(",
")",
",",
"api",
".",
"FSType_FS_TYPE_BTRFS",
".",
"SimpleString",
"(",
")",
")",
"\n",
"}",
"\n",
"volume",
":=",
"common",
".",
"NewVolume",
"(",
"uuid",
".",
"New",
"(",
")",
",",
"api",
".",
"FSType_FS_TYPE_BTRFS",
",",
"locator",
",",
"source",
",",
"spec",
",",
")",
"\n",
"if",
"err",
":=",
"d",
".",
"CreateVol",
"(",
"volume",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"d",
".",
"btrfs",
".",
"Create",
"(",
"volume",
".",
"Id",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"devicePath",
",",
"err",
":=",
"d",
".",
"btrfs",
".",
"Get",
"(",
"volume",
".",
"Id",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"volume",
".",
"Id",
",",
"err",
"\n",
"}",
"\n",
"volume",
".",
"DevicePath",
"=",
"devicePath",
"\n",
"return",
"volume",
".",
"Id",
",",
"d",
".",
"UpdateVol",
"(",
"volume",
")",
"\n",
"}"
] | // Create a new subvolume. The volume spec is not taken into account. | [
"Create",
"a",
"new",
"subvolume",
".",
"The",
"volume",
"spec",
"is",
"not",
"taken",
"into",
"account",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/volume/drivers/btrfs/btrfs.go#L81-L108 | train |
libopenstorage/openstorage | volume/drivers/btrfs/btrfs.go | Snapshot | func (d *driver) Snapshot(volumeID string, readonly bool, locator *api.VolumeLocator, noRetry bool) (string, error) {
vols, err := d.Inspect([]string{volumeID})
if err != nil {
return "", err
}
if len(vols) != 1 {
return "", fmt.Errorf("Failed to inspect %v len %v", volumeID, len(vols))
}
snapID := uuid.New()
vols[0].Id = snapID
vols[0].Source = &api.Source{Parent: volumeID}
vols[0].Locator = locator
vols[0].Ctime = prototime.Now()
if err := d.CreateVol(vols[0]); err != nil {
return "", err
}
chaos.Now(koStrayCreate)
err = d.btrfs.Create(snapID, volumeID, "", nil)
if err != nil {
return "", err
}
return vols[0].Id, nil
} | go | func (d *driver) Snapshot(volumeID string, readonly bool, locator *api.VolumeLocator, noRetry bool) (string, error) {
vols, err := d.Inspect([]string{volumeID})
if err != nil {
return "", err
}
if len(vols) != 1 {
return "", fmt.Errorf("Failed to inspect %v len %v", volumeID, len(vols))
}
snapID := uuid.New()
vols[0].Id = snapID
vols[0].Source = &api.Source{Parent: volumeID}
vols[0].Locator = locator
vols[0].Ctime = prototime.Now()
if err := d.CreateVol(vols[0]); err != nil {
return "", err
}
chaos.Now(koStrayCreate)
err = d.btrfs.Create(snapID, volumeID, "", nil)
if err != nil {
return "", err
}
return vols[0].Id, nil
} | [
"func",
"(",
"d",
"*",
"driver",
")",
"Snapshot",
"(",
"volumeID",
"string",
",",
"readonly",
"bool",
",",
"locator",
"*",
"api",
".",
"VolumeLocator",
",",
"noRetry",
"bool",
")",
"(",
"string",
",",
"error",
")",
"{",
"vols",
",",
"err",
":=",
"d",
".",
"Inspect",
"(",
"[",
"]",
"string",
"{",
"volumeID",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"vols",
")",
"!=",
"1",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"volumeID",
",",
"len",
"(",
"vols",
")",
")",
"\n",
"}",
"\n",
"snapID",
":=",
"uuid",
".",
"New",
"(",
")",
"\n",
"vols",
"[",
"0",
"]",
".",
"Id",
"=",
"snapID",
"\n",
"vols",
"[",
"0",
"]",
".",
"Source",
"=",
"&",
"api",
".",
"Source",
"{",
"Parent",
":",
"volumeID",
"}",
"\n",
"vols",
"[",
"0",
"]",
".",
"Locator",
"=",
"locator",
"\n",
"vols",
"[",
"0",
"]",
".",
"Ctime",
"=",
"prototime",
".",
"Now",
"(",
")",
"\n\n",
"if",
"err",
":=",
"d",
".",
"CreateVol",
"(",
"vols",
"[",
"0",
"]",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"chaos",
".",
"Now",
"(",
"koStrayCreate",
")",
"\n",
"err",
"=",
"d",
".",
"btrfs",
".",
"Create",
"(",
"snapID",
",",
"volumeID",
",",
"\"",
"\"",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"vols",
"[",
"0",
"]",
".",
"Id",
",",
"nil",
"\n",
"}"
] | // Snapshot create new subvolume from volume | [
"Snapshot",
"create",
"new",
"subvolume",
"from",
"volume"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/volume/drivers/btrfs/btrfs.go#L160-L183 | train |
libopenstorage/openstorage | osdconfig/new.go | newCaller | func newCaller(kv kvdb.Kvdb) (*configManager, error) {
manager := new(configManager)
manager.cbCluster = make(map[string]CallbackClusterConfigFunc)
manager.cbNode = make(map[string]CallbackNodeConfigFunc)
// kvdb pointer
manager.kv = kv
return manager, nil
} | go | func newCaller(kv kvdb.Kvdb) (*configManager, error) {
manager := new(configManager)
manager.cbCluster = make(map[string]CallbackClusterConfigFunc)
manager.cbNode = make(map[string]CallbackNodeConfigFunc)
// kvdb pointer
manager.kv = kv
return manager, nil
} | [
"func",
"newCaller",
"(",
"kv",
"kvdb",
".",
"Kvdb",
")",
"(",
"*",
"configManager",
",",
"error",
")",
"{",
"manager",
":=",
"new",
"(",
"configManager",
")",
"\n\n",
"manager",
".",
"cbCluster",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"CallbackClusterConfigFunc",
")",
"\n",
"manager",
".",
"cbNode",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"CallbackNodeConfigFunc",
")",
"\n\n",
"// kvdb pointer",
"manager",
".",
"kv",
"=",
"kv",
"\n\n",
"return",
"manager",
",",
"nil",
"\n",
"}"
] | // newCaller can be used to instantiate configManager,
// however, it is exported as ConfigCaller and avoids
// starting kvdb watches.
// Those not needing kvdb wtches should use this instead of
// config manager. | [
"newCaller",
"can",
"be",
"used",
"to",
"instantiate",
"configManager",
"however",
"it",
"is",
"exported",
"as",
"ConfigCaller",
"and",
"avoids",
"starting",
"kvdb",
"watches",
".",
"Those",
"not",
"needing",
"kvdb",
"wtches",
"should",
"use",
"this",
"instead",
"of",
"config",
"manager",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/osdconfig/new.go#L56-L66 | train |
libopenstorage/openstorage | pkg/storageops/vsphere/vsphere_util.go | IsDevMode | func IsDevMode() bool {
_, err := storageops.GetEnvValueStrict("VSPHERE_VM_UUID")
if err != nil {
return false
}
_, err = storageops.GetEnvValueStrict("VSPHERE_TEST_DATASTORE")
return err == nil
} | go | func IsDevMode() bool {
_, err := storageops.GetEnvValueStrict("VSPHERE_VM_UUID")
if err != nil {
return false
}
_, err = storageops.GetEnvValueStrict("VSPHERE_TEST_DATASTORE")
return err == nil
} | [
"func",
"IsDevMode",
"(",
")",
"bool",
"{",
"_",
",",
"err",
":=",
"storageops",
".",
"GetEnvValueStrict",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"_",
",",
"err",
"=",
"storageops",
".",
"GetEnvValueStrict",
"(",
"\"",
"\"",
")",
"\n",
"return",
"err",
"==",
"nil",
"\n",
"}"
] | // IsDevMode checks if requirement env variables are set to run the pkg outside vsphere in dev mode | [
"IsDevMode",
"checks",
"if",
"requirement",
"env",
"variables",
"are",
"set",
"to",
"run",
"the",
"pkg",
"outside",
"vsphere",
"in",
"dev",
"mode"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/storageops/vsphere/vsphere_util.go#L94-L102 | train |
libopenstorage/openstorage | pkg/storageops/vsphere/vsphere_util.go | GetStoragePodMoList | func GetStoragePodMoList(
ctx context.Context,
client *vim25.Client,
storagePodRefs []types.ManagedObjectReference,
properties []string) ([]mo.StoragePod, error) {
var storagePodMoList []mo.StoragePod
pc := property.DefaultCollector(client)
err := pc.Retrieve(ctx, storagePodRefs, properties, &storagePodMoList)
if err != nil {
logrus.Errorf("Failed to get Storagepod managed objects from storage pod refs: %+v, properties: %+v, err: %v",
storagePodRefs, properties, err)
return nil, err
}
return storagePodMoList, nil
} | go | func GetStoragePodMoList(
ctx context.Context,
client *vim25.Client,
storagePodRefs []types.ManagedObjectReference,
properties []string) ([]mo.StoragePod, error) {
var storagePodMoList []mo.StoragePod
pc := property.DefaultCollector(client)
err := pc.Retrieve(ctx, storagePodRefs, properties, &storagePodMoList)
if err != nil {
logrus.Errorf("Failed to get Storagepod managed objects from storage pod refs: %+v, properties: %+v, err: %v",
storagePodRefs, properties, err)
return nil, err
}
return storagePodMoList, nil
} | [
"func",
"GetStoragePodMoList",
"(",
"ctx",
"context",
".",
"Context",
",",
"client",
"*",
"vim25",
".",
"Client",
",",
"storagePodRefs",
"[",
"]",
"types",
".",
"ManagedObjectReference",
",",
"properties",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"mo",
".",
"StoragePod",
",",
"error",
")",
"{",
"var",
"storagePodMoList",
"[",
"]",
"mo",
".",
"StoragePod",
"\n",
"pc",
":=",
"property",
".",
"DefaultCollector",
"(",
"client",
")",
"\n",
"err",
":=",
"pc",
".",
"Retrieve",
"(",
"ctx",
",",
"storagePodRefs",
",",
"properties",
",",
"&",
"storagePodMoList",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"storagePodRefs",
",",
"properties",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"storagePodMoList",
",",
"nil",
"\n",
"}"
] | // GetStoragePodMoList fetches the managed storage pod objects for the given references
// Only the properties is the given property list will be populated in the response | [
"GetStoragePodMoList",
"fetches",
"the",
"managed",
"storage",
"pod",
"objects",
"for",
"the",
"given",
"references",
"Only",
"the",
"properties",
"is",
"the",
"given",
"property",
"list",
"will",
"be",
"populated",
"in",
"the",
"response"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/storageops/vsphere/vsphere_util.go#L171-L185 | train |
libopenstorage/openstorage | api/server/sdk/volume_migrate.go | Start | func (s *VolumeServer) Start(
ctx context.Context,
req *api.SdkCloudMigrateStartRequest,
) (*api.SdkCloudMigrateStartResponse, error) {
if s.cluster() == nil || s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
if volume := req.GetVolume(); volume != nil {
// Check ownership
if err := checkAccessFromDriverForVolumeId(ctx, s.driver(ctx), volume.GetVolumeId(), api.Ownership_Read); err != nil {
return nil, err
}
//migrate volume
return s.volumeMigrate(ctx, req, volume)
} else if volumeGroup := req.GetVolumeGroup(); volumeGroup != nil {
if !s.haveOwnership(ctx, nil, &api.VolumeLocator{
Group: &api.Group{
Id: volumeGroup.GetGroupId(),
},
}) {
return nil, status.Error(codes.PermissionDenied, "Volume Operation not Permitted.")
}
//migrate volume groups
return s.volumeGroupMigrate(ctx, req, volumeGroup)
} else if allVolumes := req.GetAllVolumes(); allVolumes != nil {
// migrate all volumes
if !s.haveOwnership(ctx, nil, nil) {
return nil, status.Error(codes.PermissionDenied, "Volume Operation not Permitted.")
}
return s.allVolumesMigrate(ctx, req, allVolumes)
}
return nil, status.Error(codes.InvalidArgument, "Unknown operation request")
} | go | func (s *VolumeServer) Start(
ctx context.Context,
req *api.SdkCloudMigrateStartRequest,
) (*api.SdkCloudMigrateStartResponse, error) {
if s.cluster() == nil || s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
if volume := req.GetVolume(); volume != nil {
// Check ownership
if err := checkAccessFromDriverForVolumeId(ctx, s.driver(ctx), volume.GetVolumeId(), api.Ownership_Read); err != nil {
return nil, err
}
//migrate volume
return s.volumeMigrate(ctx, req, volume)
} else if volumeGroup := req.GetVolumeGroup(); volumeGroup != nil {
if !s.haveOwnership(ctx, nil, &api.VolumeLocator{
Group: &api.Group{
Id: volumeGroup.GetGroupId(),
},
}) {
return nil, status.Error(codes.PermissionDenied, "Volume Operation not Permitted.")
}
//migrate volume groups
return s.volumeGroupMigrate(ctx, req, volumeGroup)
} else if allVolumes := req.GetAllVolumes(); allVolumes != nil {
// migrate all volumes
if !s.haveOwnership(ctx, nil, nil) {
return nil, status.Error(codes.PermissionDenied, "Volume Operation not Permitted.")
}
return s.allVolumesMigrate(ctx, req, allVolumes)
}
return nil, status.Error(codes.InvalidArgument, "Unknown operation request")
} | [
"func",
"(",
"s",
"*",
"VolumeServer",
")",
"Start",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"api",
".",
"SdkCloudMigrateStartRequest",
",",
")",
"(",
"*",
"api",
".",
"SdkCloudMigrateStartResponse",
",",
"error",
")",
"{",
"if",
"s",
".",
"cluster",
"(",
")",
"==",
"nil",
"||",
"s",
".",
"driver",
"(",
"ctx",
")",
"==",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"Unavailable",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"volume",
":=",
"req",
".",
"GetVolume",
"(",
")",
";",
"volume",
"!=",
"nil",
"{",
"// Check ownership",
"if",
"err",
":=",
"checkAccessFromDriverForVolumeId",
"(",
"ctx",
",",
"s",
".",
"driver",
"(",
"ctx",
")",
",",
"volume",
".",
"GetVolumeId",
"(",
")",
",",
"api",
".",
"Ownership_Read",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"//migrate volume",
"return",
"s",
".",
"volumeMigrate",
"(",
"ctx",
",",
"req",
",",
"volume",
")",
"\n",
"}",
"else",
"if",
"volumeGroup",
":=",
"req",
".",
"GetVolumeGroup",
"(",
")",
";",
"volumeGroup",
"!=",
"nil",
"{",
"if",
"!",
"s",
".",
"haveOwnership",
"(",
"ctx",
",",
"nil",
",",
"&",
"api",
".",
"VolumeLocator",
"{",
"Group",
":",
"&",
"api",
".",
"Group",
"{",
"Id",
":",
"volumeGroup",
".",
"GetGroupId",
"(",
")",
",",
"}",
",",
"}",
")",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"PermissionDenied",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"//migrate volume groups",
"return",
"s",
".",
"volumeGroupMigrate",
"(",
"ctx",
",",
"req",
",",
"volumeGroup",
")",
"\n",
"}",
"else",
"if",
"allVolumes",
":=",
"req",
".",
"GetAllVolumes",
"(",
")",
";",
"allVolumes",
"!=",
"nil",
"{",
"// migrate all volumes",
"if",
"!",
"s",
".",
"haveOwnership",
"(",
"ctx",
",",
"nil",
",",
"nil",
")",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"PermissionDenied",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"s",
".",
"allVolumesMigrate",
"(",
"ctx",
",",
"req",
",",
"allVolumes",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"InvalidArgument",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // Start a volume migration | [
"Start",
"a",
"volume",
"migration"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/volume_migrate.go#L29-L63 | train |
libopenstorage/openstorage | api/server/sdk/volume_migrate.go | Cancel | func (s *VolumeServer) Cancel(
ctx context.Context,
req *api.SdkCloudMigrateCancelRequest,
) (*api.SdkCloudMigrateCancelResponse, error) {
if s.cluster() == nil || s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
if req.GetRequest() == nil {
return nil, status.Errorf(codes.InvalidArgument, "Must supply valid request")
} else if len(req.GetRequest().GetTaskId()) == 0 {
return nil, status.Errorf(codes.InvalidArgument, "Must supply valid Task ID")
}
err := s.driver(ctx).CloudMigrateCancel(req.GetRequest())
if err != nil {
return nil, status.Errorf(codes.Internal, "Cannot stop migration for %s : %v",
req.GetRequest().GetTaskId(), err)
}
return &api.SdkCloudMigrateCancelResponse{}, nil
} | go | func (s *VolumeServer) Cancel(
ctx context.Context,
req *api.SdkCloudMigrateCancelRequest,
) (*api.SdkCloudMigrateCancelResponse, error) {
if s.cluster() == nil || s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
if req.GetRequest() == nil {
return nil, status.Errorf(codes.InvalidArgument, "Must supply valid request")
} else if len(req.GetRequest().GetTaskId()) == 0 {
return nil, status.Errorf(codes.InvalidArgument, "Must supply valid Task ID")
}
err := s.driver(ctx).CloudMigrateCancel(req.GetRequest())
if err != nil {
return nil, status.Errorf(codes.Internal, "Cannot stop migration for %s : %v",
req.GetRequest().GetTaskId(), err)
}
return &api.SdkCloudMigrateCancelResponse{}, nil
} | [
"func",
"(",
"s",
"*",
"VolumeServer",
")",
"Cancel",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"api",
".",
"SdkCloudMigrateCancelRequest",
",",
")",
"(",
"*",
"api",
".",
"SdkCloudMigrateCancelResponse",
",",
"error",
")",
"{",
"if",
"s",
".",
"cluster",
"(",
")",
"==",
"nil",
"||",
"s",
".",
"driver",
"(",
"ctx",
")",
"==",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"Unavailable",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"req",
".",
"GetRequest",
"(",
")",
"==",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"InvalidArgument",
",",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"len",
"(",
"req",
".",
"GetRequest",
"(",
")",
".",
"GetTaskId",
"(",
")",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"InvalidArgument",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"err",
":=",
"s",
".",
"driver",
"(",
"ctx",
")",
".",
"CloudMigrateCancel",
"(",
"req",
".",
"GetRequest",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"Internal",
",",
"\"",
"\"",
",",
"req",
".",
"GetRequest",
"(",
")",
".",
"GetTaskId",
"(",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"&",
"api",
".",
"SdkCloudMigrateCancelResponse",
"{",
"}",
",",
"nil",
"\n",
"}"
] | // Cancel or stop a ongoing migration | [
"Cancel",
"or",
"stop",
"a",
"ongoing",
"migration"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/volume_migrate.go#L166-L185 | train |
libopenstorage/openstorage | api/server/sdk/volume_migrate.go | Status | func (s *VolumeServer) Status(
ctx context.Context,
req *api.SdkCloudMigrateStatusRequest,
) (*api.SdkCloudMigrateStatusResponse, error) {
if s.cluster() == nil || s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
resp, err := s.driver(ctx).CloudMigrateStatus(req.GetRequest())
if err != nil {
return nil, status.Errorf(codes.Internal, "Cannot get status of migration : %v", err)
}
return &api.SdkCloudMigrateStatusResponse{
Result: resp,
}, nil
} | go | func (s *VolumeServer) Status(
ctx context.Context,
req *api.SdkCloudMigrateStatusRequest,
) (*api.SdkCloudMigrateStatusResponse, error) {
if s.cluster() == nil || s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
resp, err := s.driver(ctx).CloudMigrateStatus(req.GetRequest())
if err != nil {
return nil, status.Errorf(codes.Internal, "Cannot get status of migration : %v", err)
}
return &api.SdkCloudMigrateStatusResponse{
Result: resp,
}, nil
} | [
"func",
"(",
"s",
"*",
"VolumeServer",
")",
"Status",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"api",
".",
"SdkCloudMigrateStatusRequest",
",",
")",
"(",
"*",
"api",
".",
"SdkCloudMigrateStatusResponse",
",",
"error",
")",
"{",
"if",
"s",
".",
"cluster",
"(",
")",
"==",
"nil",
"||",
"s",
".",
"driver",
"(",
"ctx",
")",
"==",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"Unavailable",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"resp",
",",
"err",
":=",
"s",
".",
"driver",
"(",
"ctx",
")",
".",
"CloudMigrateStatus",
"(",
"req",
".",
"GetRequest",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"Internal",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"&",
"api",
".",
"SdkCloudMigrateStatusResponse",
"{",
"Result",
":",
"resp",
",",
"}",
",",
"nil",
"\n\n",
"}"
] | // Status of ongoing migration | [
"Status",
"of",
"ongoing",
"migration"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/volume_migrate.go#L188-L204 | train |
libopenstorage/openstorage | volume/drivers/pwx/pwx.go | Init | func Init(params map[string]string) (volume.VolumeDriver, error) {
url, ok := params[config.UrlKey]
if !ok {
url = DefaultUrl
}
version, ok := params[config.VersionKey]
if !ok {
version = volume.APIVersion
}
c, err := client.NewClient(url, version, "")
if err != nil {
return nil, err
}
return &driver{VolumeDriver: volumeclient.VolumeDriver(c)}, nil
} | go | func Init(params map[string]string) (volume.VolumeDriver, error) {
url, ok := params[config.UrlKey]
if !ok {
url = DefaultUrl
}
version, ok := params[config.VersionKey]
if !ok {
version = volume.APIVersion
}
c, err := client.NewClient(url, version, "")
if err != nil {
return nil, err
}
return &driver{VolumeDriver: volumeclient.VolumeDriver(c)}, nil
} | [
"func",
"Init",
"(",
"params",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"volume",
".",
"VolumeDriver",
",",
"error",
")",
"{",
"url",
",",
"ok",
":=",
"params",
"[",
"config",
".",
"UrlKey",
"]",
"\n",
"if",
"!",
"ok",
"{",
"url",
"=",
"DefaultUrl",
"\n",
"}",
"\n",
"version",
",",
"ok",
":=",
"params",
"[",
"config",
".",
"VersionKey",
"]",
"\n",
"if",
"!",
"ok",
"{",
"version",
"=",
"volume",
".",
"APIVersion",
"\n",
"}",
"\n",
"c",
",",
"err",
":=",
"client",
".",
"NewClient",
"(",
"url",
",",
"version",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"driver",
"{",
"VolumeDriver",
":",
"volumeclient",
".",
"VolumeDriver",
"(",
"c",
")",
"}",
",",
"nil",
"\n",
"}"
] | // Init initialized the Portworx driver.
// Portworx natively implements the openstorage.org API specification, so
// we can directly point the VolumeDriver to the PWX API server. | [
"Init",
"initialized",
"the",
"Portworx",
"driver",
".",
"Portworx",
"natively",
"implements",
"the",
"openstorage",
".",
"org",
"API",
"specification",
"so",
"we",
"can",
"directly",
"point",
"the",
"VolumeDriver",
"to",
"the",
"PWX",
"API",
"server",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/volume/drivers/pwx/pwx.go#L27-L42 | train |
libopenstorage/openstorage | cluster/manager/pair.go | CreatePair | func (c *ClusterManager) CreatePair(
request *api.ClusterPairCreateRequest,
) (*api.ClusterPairCreateResponse, error) {
remoteIp := request.RemoteClusterIp
// Pair with remote server
logrus.Infof("Attempting to pair with cluster at IP %v", remoteIp)
processRequest := &api.ClusterPairProcessRequest{
SourceClusterId: c.Uuid(),
RemoteClusterToken: request.RemoteClusterToken,
Mode: request.Mode,
}
endpoint := "http://" + remoteIp + ":" + strconv.FormatUint(uint64(request.RemoteClusterPort), 10)
clnt, err := clusterclient.NewClusterClient(endpoint, cluster.APIVersion)
if err != nil {
return nil, err
}
remoteCluster := clusterclient.ClusterManager(clnt)
// Issue a remote pair request
resp, err := remoteCluster.ProcessPairRequest(processRequest)
if err != nil {
logrus.Warnf("Unable to pair with %v: %v", remoteIp, err)
return nil, fmt.Errorf("Error from remote cluster: %v", err)
}
// Alert all listeners that we are pairing with a cluster.
for e := c.listeners.Front(); e != nil; e = e.Next() {
err = e.Value.(cluster.ClusterListener).CreatePair(
request,
resp,
)
if err != nil {
logrus.Errorf("Unable to notify %v on a cluster pair event: %v",
e.Value.(cluster.ClusterListener).String(),
err,
)
return nil, err
}
}
pairInfo := &api.ClusterPairInfo{
Id: resp.RemoteClusterId,
Name: resp.RemoteClusterName,
Endpoint: endpoint,
CurrentEndpoints: resp.RemoteClusterEndpoints,
Token: request.RemoteClusterToken,
Options: resp.Options,
Mode: request.Mode,
}
err = pairCreate(pairInfo, request.SetDefault)
if err != nil {
return nil, err
}
logrus.Infof("Successfully paired with cluster ID %v", resp.RemoteClusterId)
response := &api.ClusterPairCreateResponse{
RemoteClusterId: pairInfo.Id,
RemoteClusterName: pairInfo.Name,
}
return response, nil
} | go | func (c *ClusterManager) CreatePair(
request *api.ClusterPairCreateRequest,
) (*api.ClusterPairCreateResponse, error) {
remoteIp := request.RemoteClusterIp
// Pair with remote server
logrus.Infof("Attempting to pair with cluster at IP %v", remoteIp)
processRequest := &api.ClusterPairProcessRequest{
SourceClusterId: c.Uuid(),
RemoteClusterToken: request.RemoteClusterToken,
Mode: request.Mode,
}
endpoint := "http://" + remoteIp + ":" + strconv.FormatUint(uint64(request.RemoteClusterPort), 10)
clnt, err := clusterclient.NewClusterClient(endpoint, cluster.APIVersion)
if err != nil {
return nil, err
}
remoteCluster := clusterclient.ClusterManager(clnt)
// Issue a remote pair request
resp, err := remoteCluster.ProcessPairRequest(processRequest)
if err != nil {
logrus.Warnf("Unable to pair with %v: %v", remoteIp, err)
return nil, fmt.Errorf("Error from remote cluster: %v", err)
}
// Alert all listeners that we are pairing with a cluster.
for e := c.listeners.Front(); e != nil; e = e.Next() {
err = e.Value.(cluster.ClusterListener).CreatePair(
request,
resp,
)
if err != nil {
logrus.Errorf("Unable to notify %v on a cluster pair event: %v",
e.Value.(cluster.ClusterListener).String(),
err,
)
return nil, err
}
}
pairInfo := &api.ClusterPairInfo{
Id: resp.RemoteClusterId,
Name: resp.RemoteClusterName,
Endpoint: endpoint,
CurrentEndpoints: resp.RemoteClusterEndpoints,
Token: request.RemoteClusterToken,
Options: resp.Options,
Mode: request.Mode,
}
err = pairCreate(pairInfo, request.SetDefault)
if err != nil {
return nil, err
}
logrus.Infof("Successfully paired with cluster ID %v", resp.RemoteClusterId)
response := &api.ClusterPairCreateResponse{
RemoteClusterId: pairInfo.Id,
RemoteClusterName: pairInfo.Name,
}
return response, nil
} | [
"func",
"(",
"c",
"*",
"ClusterManager",
")",
"CreatePair",
"(",
"request",
"*",
"api",
".",
"ClusterPairCreateRequest",
",",
")",
"(",
"*",
"api",
".",
"ClusterPairCreateResponse",
",",
"error",
")",
"{",
"remoteIp",
":=",
"request",
".",
"RemoteClusterIp",
"\n\n",
"// Pair with remote server",
"logrus",
".",
"Infof",
"(",
"\"",
"\"",
",",
"remoteIp",
")",
"\n",
"processRequest",
":=",
"&",
"api",
".",
"ClusterPairProcessRequest",
"{",
"SourceClusterId",
":",
"c",
".",
"Uuid",
"(",
")",
",",
"RemoteClusterToken",
":",
"request",
".",
"RemoteClusterToken",
",",
"Mode",
":",
"request",
".",
"Mode",
",",
"}",
"\n\n",
"endpoint",
":=",
"\"",
"\"",
"+",
"remoteIp",
"+",
"\"",
"\"",
"+",
"strconv",
".",
"FormatUint",
"(",
"uint64",
"(",
"request",
".",
"RemoteClusterPort",
")",
",",
"10",
")",
"\n",
"clnt",
",",
"err",
":=",
"clusterclient",
".",
"NewClusterClient",
"(",
"endpoint",
",",
"cluster",
".",
"APIVersion",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"remoteCluster",
":=",
"clusterclient",
".",
"ClusterManager",
"(",
"clnt",
")",
"\n\n",
"// Issue a remote pair request",
"resp",
",",
"err",
":=",
"remoteCluster",
".",
"ProcessPairRequest",
"(",
"processRequest",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"remoteIp",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// Alert all listeners that we are pairing with a cluster.",
"for",
"e",
":=",
"c",
".",
"listeners",
".",
"Front",
"(",
")",
";",
"e",
"!=",
"nil",
";",
"e",
"=",
"e",
".",
"Next",
"(",
")",
"{",
"err",
"=",
"e",
".",
"Value",
".",
"(",
"cluster",
".",
"ClusterListener",
")",
".",
"CreatePair",
"(",
"request",
",",
"resp",
",",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"e",
".",
"Value",
".",
"(",
"cluster",
".",
"ClusterListener",
")",
".",
"String",
"(",
")",
",",
"err",
",",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"pairInfo",
":=",
"&",
"api",
".",
"ClusterPairInfo",
"{",
"Id",
":",
"resp",
".",
"RemoteClusterId",
",",
"Name",
":",
"resp",
".",
"RemoteClusterName",
",",
"Endpoint",
":",
"endpoint",
",",
"CurrentEndpoints",
":",
"resp",
".",
"RemoteClusterEndpoints",
",",
"Token",
":",
"request",
".",
"RemoteClusterToken",
",",
"Options",
":",
"resp",
".",
"Options",
",",
"Mode",
":",
"request",
".",
"Mode",
",",
"}",
"\n\n",
"err",
"=",
"pairCreate",
"(",
"pairInfo",
",",
"request",
".",
"SetDefault",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"logrus",
".",
"Infof",
"(",
"\"",
"\"",
",",
"resp",
".",
"RemoteClusterId",
")",
"\n\n",
"response",
":=",
"&",
"api",
".",
"ClusterPairCreateResponse",
"{",
"RemoteClusterId",
":",
"pairInfo",
".",
"Id",
",",
"RemoteClusterName",
":",
"pairInfo",
".",
"Name",
",",
"}",
"\n",
"return",
"response",
",",
"nil",
"\n",
"}"
] | // CreatePair remote pairs this cluster with a remote cluster. | [
"CreatePair",
"remote",
"pairs",
"this",
"cluster",
"with",
"a",
"remote",
"cluster",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/cluster/manager/pair.go#L27-L90 | train |
libopenstorage/openstorage | cluster/manager/pair.go | ProcessPairRequest | func (c *ClusterManager) ProcessPairRequest(
request *api.ClusterPairProcessRequest,
) (*api.ClusterPairProcessResponse, error) {
if request.SourceClusterId == c.Uuid() {
return nil, fmt.Errorf("Cannot create cluster pair with self")
}
response := &api.ClusterPairProcessResponse{
RemoteClusterId: c.Uuid(),
RemoteClusterName: c.config.ClusterId,
}
// Get the token without resetting it
tokenResp, err := c.GetPairToken(false)
if err != nil {
return nil, fmt.Errorf("Error getting Cluster Token: %v", err)
}
if tokenResp.Token != request.RemoteClusterToken {
return nil, fmt.Errorf("Token mismatch during pairing")
}
// Alert all listeners that we have received a pair request
for e := c.listeners.Front(); e != nil; e = e.Next() {
err := e.Value.(cluster.ClusterListener).ProcessPairRequest(
request,
response,
)
if err != nil {
logrus.Errorf("Unable to notify %v on a a cluster remote pair request: %v",
e.Value.(cluster.ClusterListener).String(),
err,
)
return nil, err
}
}
logrus.Infof("Successfully paired with remote cluster %v", request.SourceClusterId)
return response, nil
} | go | func (c *ClusterManager) ProcessPairRequest(
request *api.ClusterPairProcessRequest,
) (*api.ClusterPairProcessResponse, error) {
if request.SourceClusterId == c.Uuid() {
return nil, fmt.Errorf("Cannot create cluster pair with self")
}
response := &api.ClusterPairProcessResponse{
RemoteClusterId: c.Uuid(),
RemoteClusterName: c.config.ClusterId,
}
// Get the token without resetting it
tokenResp, err := c.GetPairToken(false)
if err != nil {
return nil, fmt.Errorf("Error getting Cluster Token: %v", err)
}
if tokenResp.Token != request.RemoteClusterToken {
return nil, fmt.Errorf("Token mismatch during pairing")
}
// Alert all listeners that we have received a pair request
for e := c.listeners.Front(); e != nil; e = e.Next() {
err := e.Value.(cluster.ClusterListener).ProcessPairRequest(
request,
response,
)
if err != nil {
logrus.Errorf("Unable to notify %v on a a cluster remote pair request: %v",
e.Value.(cluster.ClusterListener).String(),
err,
)
return nil, err
}
}
logrus.Infof("Successfully paired with remote cluster %v", request.SourceClusterId)
return response, nil
} | [
"func",
"(",
"c",
"*",
"ClusterManager",
")",
"ProcessPairRequest",
"(",
"request",
"*",
"api",
".",
"ClusterPairProcessRequest",
",",
")",
"(",
"*",
"api",
".",
"ClusterPairProcessResponse",
",",
"error",
")",
"{",
"if",
"request",
".",
"SourceClusterId",
"==",
"c",
".",
"Uuid",
"(",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"response",
":=",
"&",
"api",
".",
"ClusterPairProcessResponse",
"{",
"RemoteClusterId",
":",
"c",
".",
"Uuid",
"(",
")",
",",
"RemoteClusterName",
":",
"c",
".",
"config",
".",
"ClusterId",
",",
"}",
"\n\n",
"// Get the token without resetting it",
"tokenResp",
",",
"err",
":=",
"c",
".",
"GetPairToken",
"(",
"false",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"tokenResp",
".",
"Token",
"!=",
"request",
".",
"RemoteClusterToken",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Alert all listeners that we have received a pair request",
"for",
"e",
":=",
"c",
".",
"listeners",
".",
"Front",
"(",
")",
";",
"e",
"!=",
"nil",
";",
"e",
"=",
"e",
".",
"Next",
"(",
")",
"{",
"err",
":=",
"e",
".",
"Value",
".",
"(",
"cluster",
".",
"ClusterListener",
")",
".",
"ProcessPairRequest",
"(",
"request",
",",
"response",
",",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"e",
".",
"Value",
".",
"(",
"cluster",
".",
"ClusterListener",
")",
".",
"String",
"(",
")",
",",
"err",
",",
")",
"\n\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"logrus",
".",
"Infof",
"(",
"\"",
"\"",
",",
"request",
".",
"SourceClusterId",
")",
"\n\n",
"return",
"response",
",",
"nil",
"\n",
"}"
] | // ProcessPairRequest handles a remote cluster's pair request | [
"ProcessPairRequest",
"handles",
"a",
"remote",
"cluster",
"s",
"pair",
"request"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/cluster/manager/pair.go#L93-L133 | train |
libopenstorage/openstorage | cluster/manager/pair.go | getDefaultPairId | func getDefaultPairId() (string, error) {
kv := kvdb.Instance()
kvp, err := kv.Get(clusterPairDefaultKey)
if err != nil {
return "", err
}
return string(kvp.Value), nil
} | go | func getDefaultPairId() (string, error) {
kv := kvdb.Instance()
kvp, err := kv.Get(clusterPairDefaultKey)
if err != nil {
return "", err
}
return string(kvp.Value), nil
} | [
"func",
"getDefaultPairId",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"kv",
":=",
"kvdb",
".",
"Instance",
"(",
")",
"\n",
"kvp",
",",
"err",
":=",
"kv",
".",
"Get",
"(",
"clusterPairDefaultKey",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"string",
"(",
"kvp",
".",
"Value",
")",
",",
"nil",
"\n",
"}"
] | // Return the default pair id if set, error if none set | [
"Return",
"the",
"default",
"pair",
"id",
"if",
"set",
"error",
"if",
"none",
"set"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/cluster/manager/pair.go#L424-L431 | train |
libopenstorage/openstorage | pkg/flexvolume/flexvolume.pb.gw.go | RegisterAPIHandler | func RegisterAPIHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return RegisterAPIHandlerClient(ctx, mux, NewAPIClient(conn))
} | go | func RegisterAPIHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return RegisterAPIHandlerClient(ctx, mux, NewAPIClient(conn))
} | [
"func",
"RegisterAPIHandler",
"(",
"ctx",
"context",
".",
"Context",
",",
"mux",
"*",
"runtime",
".",
"ServeMux",
",",
"conn",
"*",
"grpc",
".",
"ClientConn",
")",
"error",
"{",
"return",
"RegisterAPIHandlerClient",
"(",
"ctx",
",",
"mux",
",",
"NewAPIClient",
"(",
"conn",
")",
")",
"\n",
"}"
] | // RegisterAPIHandler registers the http handlers for service API to "mux".
// The handlers forward requests to the grpc endpoint over "conn". | [
"RegisterAPIHandler",
"registers",
"the",
"http",
"handlers",
"for",
"service",
"API",
"to",
"mux",
".",
"The",
"handlers",
"forward",
"requests",
"to",
"the",
"grpc",
"endpoint",
"over",
"conn",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/flexvolume/flexvolume.pb.gw.go#L124-L126 | train |
libopenstorage/openstorage | pkg/sanity/sanity.go | CloudProviderConfigParse | func CloudProviderConfigParse(filePath string) (*CloudBackupConfig, error) {
config := &CloudBackupConfig{}
data, err := ioutil.ReadFile(filePath)
if err != nil {
return nil, fmt.Errorf("Unable to read the Cloud backup configuration file (%s): %s", filePath, err.Error())
}
if err := yaml.Unmarshal(data, config); err != nil {
return nil, fmt.Errorf("Unable to parse Cloud backup configuration: %s", err.Error())
}
return config, nil
} | go | func CloudProviderConfigParse(filePath string) (*CloudBackupConfig, error) {
config := &CloudBackupConfig{}
data, err := ioutil.ReadFile(filePath)
if err != nil {
return nil, fmt.Errorf("Unable to read the Cloud backup configuration file (%s): %s", filePath, err.Error())
}
if err := yaml.Unmarshal(data, config); err != nil {
return nil, fmt.Errorf("Unable to parse Cloud backup configuration: %s", err.Error())
}
return config, nil
} | [
"func",
"CloudProviderConfigParse",
"(",
"filePath",
"string",
")",
"(",
"*",
"CloudBackupConfig",
",",
"error",
")",
"{",
"config",
":=",
"&",
"CloudBackupConfig",
"{",
"}",
"\n",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"filePath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"filePath",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"yaml",
".",
"Unmarshal",
"(",
"data",
",",
"config",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"config",
",",
"nil",
"\n\n",
"}"
] | // CloudProviderConfigParse parses the config file of cloudBackup | [
"CloudProviderConfigParse",
"parses",
"the",
"config",
"file",
"of",
"cloudBackup"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/sanity/sanity.go#L65-L77 | train |
libopenstorage/openstorage | volume/drivers/drivers.go | Register | func Register(name string, params map[string]string) error {
return volumeDriverRegistry.Register(name, params)
} | go | func Register(name string, params map[string]string) error {
return volumeDriverRegistry.Register(name, params)
} | [
"func",
"Register",
"(",
"name",
"string",
",",
"params",
"map",
"[",
"string",
"]",
"string",
")",
"error",
"{",
"return",
"volumeDriverRegistry",
".",
"Register",
"(",
"name",
",",
"params",
")",
"\n",
"}"
] | // Register registers a new driver. | [
"Register",
"registers",
"a",
"new",
"driver",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/volume/drivers/drivers.go#L62-L64 | train |
libopenstorage/openstorage | volume/drivers/drivers.go | Add | func Add(name string, init func(map[string]string) (volume.VolumeDriver, error)) error {
return volumeDriverRegistry.Add(name, init)
} | go | func Add(name string, init func(map[string]string) (volume.VolumeDriver, error)) error {
return volumeDriverRegistry.Add(name, init)
} | [
"func",
"Add",
"(",
"name",
"string",
",",
"init",
"func",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"volume",
".",
"VolumeDriver",
",",
"error",
")",
")",
"error",
"{",
"return",
"volumeDriverRegistry",
".",
"Add",
"(",
"name",
",",
"init",
")",
"\n",
"}"
] | // Add adds a new driver. | [
"Add",
"adds",
"a",
"new",
"driver",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/volume/drivers/drivers.go#L67-L69 | train |
libopenstorage/openstorage | api/server/sdk/volume_ops.go | Create | func (s *VolumeServer) Create(
ctx context.Context,
req *api.SdkVolumeCreateRequest,
) (*api.SdkVolumeCreateResponse, error) {
if s.cluster() == nil || s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
if len(req.GetName()) == 0 {
return nil, status.Error(
codes.InvalidArgument,
"Must supply a unique name")
} else if req.GetSpec() == nil {
return nil, status.Error(
codes.InvalidArgument,
"Must supply spec object")
}
locator := &api.VolumeLocator{
Name: req.GetName(),
VolumeLabels: req.GetLabels(),
}
source := &api.Source{}
// Validate/Update given spec according to default storage policy set
// In case policy is not set, should fall back to default way
// of creating volume
spec, err := GetDefaultVolSpecs(ctx, req.GetSpec(), false)
if err != nil {
return nil, err
}
// Copy any labels from the spec to the locator
locator = locator.MergeVolumeSpecLabels(spec)
// Convert node IP to ID if necessary for API calls
if err := s.updateReplicaSpecNodeIPstoIds(spec.GetReplicaSet()); err != nil {
return nil, status.Errorf(codes.Internal, "Failed to get replicat set information: %v", err)
}
// Create volume
id, err := s.create(ctx, locator, source, spec)
if err != nil {
return nil, err
}
return &api.SdkVolumeCreateResponse{
VolumeId: id,
}, nil
} | go | func (s *VolumeServer) Create(
ctx context.Context,
req *api.SdkVolumeCreateRequest,
) (*api.SdkVolumeCreateResponse, error) {
if s.cluster() == nil || s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
if len(req.GetName()) == 0 {
return nil, status.Error(
codes.InvalidArgument,
"Must supply a unique name")
} else if req.GetSpec() == nil {
return nil, status.Error(
codes.InvalidArgument,
"Must supply spec object")
}
locator := &api.VolumeLocator{
Name: req.GetName(),
VolumeLabels: req.GetLabels(),
}
source := &api.Source{}
// Validate/Update given spec according to default storage policy set
// In case policy is not set, should fall back to default way
// of creating volume
spec, err := GetDefaultVolSpecs(ctx, req.GetSpec(), false)
if err != nil {
return nil, err
}
// Copy any labels from the spec to the locator
locator = locator.MergeVolumeSpecLabels(spec)
// Convert node IP to ID if necessary for API calls
if err := s.updateReplicaSpecNodeIPstoIds(spec.GetReplicaSet()); err != nil {
return nil, status.Errorf(codes.Internal, "Failed to get replicat set information: %v", err)
}
// Create volume
id, err := s.create(ctx, locator, source, spec)
if err != nil {
return nil, err
}
return &api.SdkVolumeCreateResponse{
VolumeId: id,
}, nil
} | [
"func",
"(",
"s",
"*",
"VolumeServer",
")",
"Create",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"api",
".",
"SdkVolumeCreateRequest",
",",
")",
"(",
"*",
"api",
".",
"SdkVolumeCreateResponse",
",",
"error",
")",
"{",
"if",
"s",
".",
"cluster",
"(",
")",
"==",
"nil",
"||",
"s",
".",
"driver",
"(",
"ctx",
")",
"==",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"Unavailable",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"req",
".",
"GetName",
"(",
")",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"InvalidArgument",
",",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"req",
".",
"GetSpec",
"(",
")",
"==",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"InvalidArgument",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"locator",
":=",
"&",
"api",
".",
"VolumeLocator",
"{",
"Name",
":",
"req",
".",
"GetName",
"(",
")",
",",
"VolumeLabels",
":",
"req",
".",
"GetLabels",
"(",
")",
",",
"}",
"\n",
"source",
":=",
"&",
"api",
".",
"Source",
"{",
"}",
"\n\n",
"// Validate/Update given spec according to default storage policy set",
"// In case policy is not set, should fall back to default way",
"// of creating volume",
"spec",
",",
"err",
":=",
"GetDefaultVolSpecs",
"(",
"ctx",
",",
"req",
".",
"GetSpec",
"(",
")",
",",
"false",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Copy any labels from the spec to the locator",
"locator",
"=",
"locator",
".",
"MergeVolumeSpecLabels",
"(",
"spec",
")",
"\n\n",
"// Convert node IP to ID if necessary for API calls",
"if",
"err",
":=",
"s",
".",
"updateReplicaSpecNodeIPstoIds",
"(",
"spec",
".",
"GetReplicaSet",
"(",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"Internal",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// Create volume",
"id",
",",
"err",
":=",
"s",
".",
"create",
"(",
"ctx",
",",
"locator",
",",
"source",
",",
"spec",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"api",
".",
"SdkVolumeCreateResponse",
"{",
"VolumeId",
":",
"id",
",",
"}",
",",
"nil",
"\n",
"}"
] | // Create creates a new volume | [
"Create",
"creates",
"a",
"new",
"volume"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/volume_ops.go#L144-L193 | train |
libopenstorage/openstorage | api/server/sdk/volume_ops.go | Clone | func (s *VolumeServer) Clone(
ctx context.Context,
req *api.SdkVolumeCloneRequest,
) (*api.SdkVolumeCloneResponse, error) {
if s.cluster() == nil || s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
if len(req.GetName()) == 0 {
return nil, status.Error(
codes.InvalidArgument,
"Must supply a uniqe name")
} else if len(req.GetParentId()) == 0 {
return nil, status.Error(
codes.InvalidArgument,
"Must parent volume id")
}
locator := &api.VolumeLocator{
Name: req.GetName(),
}
source := &api.Source{
Parent: req.GetParentId(),
}
// Get spec. This also checks if the parend id exists.
// This will also check for Ownership_Read access.
parentVol, err := s.Inspect(ctx, &api.SdkVolumeInspectRequest{
VolumeId: req.GetParentId(),
})
if err != nil {
return nil, err
}
// Create the clone
id, err := s.create(ctx, locator, source, parentVol.GetVolume().GetSpec())
if err != nil {
return nil, err
}
return &api.SdkVolumeCloneResponse{
VolumeId: id,
}, nil
} | go | func (s *VolumeServer) Clone(
ctx context.Context,
req *api.SdkVolumeCloneRequest,
) (*api.SdkVolumeCloneResponse, error) {
if s.cluster() == nil || s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
if len(req.GetName()) == 0 {
return nil, status.Error(
codes.InvalidArgument,
"Must supply a uniqe name")
} else if len(req.GetParentId()) == 0 {
return nil, status.Error(
codes.InvalidArgument,
"Must parent volume id")
}
locator := &api.VolumeLocator{
Name: req.GetName(),
}
source := &api.Source{
Parent: req.GetParentId(),
}
// Get spec. This also checks if the parend id exists.
// This will also check for Ownership_Read access.
parentVol, err := s.Inspect(ctx, &api.SdkVolumeInspectRequest{
VolumeId: req.GetParentId(),
})
if err != nil {
return nil, err
}
// Create the clone
id, err := s.create(ctx, locator, source, parentVol.GetVolume().GetSpec())
if err != nil {
return nil, err
}
return &api.SdkVolumeCloneResponse{
VolumeId: id,
}, nil
} | [
"func",
"(",
"s",
"*",
"VolumeServer",
")",
"Clone",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"api",
".",
"SdkVolumeCloneRequest",
",",
")",
"(",
"*",
"api",
".",
"SdkVolumeCloneResponse",
",",
"error",
")",
"{",
"if",
"s",
".",
"cluster",
"(",
")",
"==",
"nil",
"||",
"s",
".",
"driver",
"(",
"ctx",
")",
"==",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"Unavailable",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"req",
".",
"GetName",
"(",
")",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"InvalidArgument",
",",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"len",
"(",
"req",
".",
"GetParentId",
"(",
")",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"InvalidArgument",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"locator",
":=",
"&",
"api",
".",
"VolumeLocator",
"{",
"Name",
":",
"req",
".",
"GetName",
"(",
")",
",",
"}",
"\n",
"source",
":=",
"&",
"api",
".",
"Source",
"{",
"Parent",
":",
"req",
".",
"GetParentId",
"(",
")",
",",
"}",
"\n\n",
"// Get spec. This also checks if the parend id exists.",
"// This will also check for Ownership_Read access.",
"parentVol",
",",
"err",
":=",
"s",
".",
"Inspect",
"(",
"ctx",
",",
"&",
"api",
".",
"SdkVolumeInspectRequest",
"{",
"VolumeId",
":",
"req",
".",
"GetParentId",
"(",
")",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Create the clone",
"id",
",",
"err",
":=",
"s",
".",
"create",
"(",
"ctx",
",",
"locator",
",",
"source",
",",
"parentVol",
".",
"GetVolume",
"(",
")",
".",
"GetSpec",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"api",
".",
"SdkVolumeCloneResponse",
"{",
"VolumeId",
":",
"id",
",",
"}",
",",
"nil",
"\n",
"}"
] | // Clone creates a new volume from an existing volume | [
"Clone",
"creates",
"a",
"new",
"volume",
"from",
"an",
"existing",
"volume"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/volume_ops.go#L196-L239 | train |
libopenstorage/openstorage | api/server/sdk/volume_ops.go | Delete | func (s *VolumeServer) Delete(
ctx context.Context,
req *api.SdkVolumeDeleteRequest,
) (*api.SdkVolumeDeleteResponse, error) {
if s.cluster() == nil || s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
if len(req.GetVolumeId()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Must supply volume id")
}
// If the volume is not found, return OK to be idempotent
// This checks access rights also
resp, err := s.Inspect(ctx, &api.SdkVolumeInspectRequest{
VolumeId: req.GetVolumeId(),
})
if err != nil {
if IsErrorNotFound(err) {
return &api.SdkVolumeDeleteResponse{}, nil
}
return nil, err
}
vol := resp.GetVolume()
// Only the owner or the admin can delete
if !vol.IsPermitted(ctx, api.Ownership_Admin) {
return nil, status.Errorf(codes.PermissionDenied, "Cannot delete volume %v", vol.GetId())
}
// Delete the volume
err = s.driver(ctx).Delete(req.GetVolumeId())
if err != nil {
return nil, status.Errorf(
codes.Internal,
"Failed to delete volume %s: %v",
req.GetVolumeId(),
err.Error())
}
return &api.SdkVolumeDeleteResponse{}, nil
} | go | func (s *VolumeServer) Delete(
ctx context.Context,
req *api.SdkVolumeDeleteRequest,
) (*api.SdkVolumeDeleteResponse, error) {
if s.cluster() == nil || s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
if len(req.GetVolumeId()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Must supply volume id")
}
// If the volume is not found, return OK to be idempotent
// This checks access rights also
resp, err := s.Inspect(ctx, &api.SdkVolumeInspectRequest{
VolumeId: req.GetVolumeId(),
})
if err != nil {
if IsErrorNotFound(err) {
return &api.SdkVolumeDeleteResponse{}, nil
}
return nil, err
}
vol := resp.GetVolume()
// Only the owner or the admin can delete
if !vol.IsPermitted(ctx, api.Ownership_Admin) {
return nil, status.Errorf(codes.PermissionDenied, "Cannot delete volume %v", vol.GetId())
}
// Delete the volume
err = s.driver(ctx).Delete(req.GetVolumeId())
if err != nil {
return nil, status.Errorf(
codes.Internal,
"Failed to delete volume %s: %v",
req.GetVolumeId(),
err.Error())
}
return &api.SdkVolumeDeleteResponse{}, nil
} | [
"func",
"(",
"s",
"*",
"VolumeServer",
")",
"Delete",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"api",
".",
"SdkVolumeDeleteRequest",
",",
")",
"(",
"*",
"api",
".",
"SdkVolumeDeleteResponse",
",",
"error",
")",
"{",
"if",
"s",
".",
"cluster",
"(",
")",
"==",
"nil",
"||",
"s",
".",
"driver",
"(",
"ctx",
")",
"==",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"Unavailable",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"req",
".",
"GetVolumeId",
"(",
")",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"InvalidArgument",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// If the volume is not found, return OK to be idempotent",
"// This checks access rights also",
"resp",
",",
"err",
":=",
"s",
".",
"Inspect",
"(",
"ctx",
",",
"&",
"api",
".",
"SdkVolumeInspectRequest",
"{",
"VolumeId",
":",
"req",
".",
"GetVolumeId",
"(",
")",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"IsErrorNotFound",
"(",
"err",
")",
"{",
"return",
"&",
"api",
".",
"SdkVolumeDeleteResponse",
"{",
"}",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"vol",
":=",
"resp",
".",
"GetVolume",
"(",
")",
"\n\n",
"// Only the owner or the admin can delete",
"if",
"!",
"vol",
".",
"IsPermitted",
"(",
"ctx",
",",
"api",
".",
"Ownership_Admin",
")",
"{",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"PermissionDenied",
",",
"\"",
"\"",
",",
"vol",
".",
"GetId",
"(",
")",
")",
"\n",
"}",
"\n\n",
"// Delete the volume",
"err",
"=",
"s",
".",
"driver",
"(",
"ctx",
")",
".",
"Delete",
"(",
"req",
".",
"GetVolumeId",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"Internal",
",",
"\"",
"\"",
",",
"req",
".",
"GetVolumeId",
"(",
")",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"api",
".",
"SdkVolumeDeleteResponse",
"{",
"}",
",",
"nil",
"\n",
"}"
] | // Delete deletes a volume | [
"Delete",
"deletes",
"a",
"volume"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/volume_ops.go#L242-L283 | train |
libopenstorage/openstorage | api/server/sdk/volume_ops.go | InspectWithFilters | func (s *VolumeServer) InspectWithFilters(
ctx context.Context,
req *api.SdkVolumeInspectWithFiltersRequest,
) (*api.SdkVolumeInspectWithFiltersResponse, error) {
if s.cluster() == nil || s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
var locator *api.VolumeLocator
if len(req.GetName()) != 0 ||
len(req.GetLabels()) != 0 ||
req.GetOwnership() != nil {
locator = &api.VolumeLocator{
Name: req.GetName(),
VolumeLabels: req.GetLabels(),
Ownership: req.GetOwnership(),
}
}
enumVols, err := s.driver(ctx).Enumerate(locator, nil)
if err != nil {
return nil, status.Errorf(
codes.Internal,
"Failed to enumerate volumes: %v",
err.Error())
}
vols := make([]*api.SdkVolumeInspectResponse, 0, len(enumVols))
for _, vol := range enumVols {
// Check access
if vol.IsPermitted(ctx, api.Ownership_Read) {
// Check if the caller wants more information
if req.GetOptions().GetDeep() {
resp, err := s.Inspect(ctx, &api.SdkVolumeInspectRequest{
VolumeId: vol.GetId(),
Options: req.GetOptions(),
})
if IsErrorNotFound(err) {
continue
} else if err != nil {
return nil, err
}
vols = append(vols, resp)
} else {
// Caller does not require a deep inspect
// Add the object now
vols = append(vols, &api.SdkVolumeInspectResponse{
Volume: vol,
Name: vol.GetLocator().GetName(),
Labels: vol.GetLocator().GetVolumeLabels(),
})
}
}
}
return &api.SdkVolumeInspectWithFiltersResponse{
Volumes: vols,
}, nil
} | go | func (s *VolumeServer) InspectWithFilters(
ctx context.Context,
req *api.SdkVolumeInspectWithFiltersRequest,
) (*api.SdkVolumeInspectWithFiltersResponse, error) {
if s.cluster() == nil || s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
var locator *api.VolumeLocator
if len(req.GetName()) != 0 ||
len(req.GetLabels()) != 0 ||
req.GetOwnership() != nil {
locator = &api.VolumeLocator{
Name: req.GetName(),
VolumeLabels: req.GetLabels(),
Ownership: req.GetOwnership(),
}
}
enumVols, err := s.driver(ctx).Enumerate(locator, nil)
if err != nil {
return nil, status.Errorf(
codes.Internal,
"Failed to enumerate volumes: %v",
err.Error())
}
vols := make([]*api.SdkVolumeInspectResponse, 0, len(enumVols))
for _, vol := range enumVols {
// Check access
if vol.IsPermitted(ctx, api.Ownership_Read) {
// Check if the caller wants more information
if req.GetOptions().GetDeep() {
resp, err := s.Inspect(ctx, &api.SdkVolumeInspectRequest{
VolumeId: vol.GetId(),
Options: req.GetOptions(),
})
if IsErrorNotFound(err) {
continue
} else if err != nil {
return nil, err
}
vols = append(vols, resp)
} else {
// Caller does not require a deep inspect
// Add the object now
vols = append(vols, &api.SdkVolumeInspectResponse{
Volume: vol,
Name: vol.GetLocator().GetName(),
Labels: vol.GetLocator().GetVolumeLabels(),
})
}
}
}
return &api.SdkVolumeInspectWithFiltersResponse{
Volumes: vols,
}, nil
} | [
"func",
"(",
"s",
"*",
"VolumeServer",
")",
"InspectWithFilters",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"api",
".",
"SdkVolumeInspectWithFiltersRequest",
",",
")",
"(",
"*",
"api",
".",
"SdkVolumeInspectWithFiltersResponse",
",",
"error",
")",
"{",
"if",
"s",
".",
"cluster",
"(",
")",
"==",
"nil",
"||",
"s",
".",
"driver",
"(",
"ctx",
")",
"==",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"Unavailable",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"var",
"locator",
"*",
"api",
".",
"VolumeLocator",
"\n",
"if",
"len",
"(",
"req",
".",
"GetName",
"(",
")",
")",
"!=",
"0",
"||",
"len",
"(",
"req",
".",
"GetLabels",
"(",
")",
")",
"!=",
"0",
"||",
"req",
".",
"GetOwnership",
"(",
")",
"!=",
"nil",
"{",
"locator",
"=",
"&",
"api",
".",
"VolumeLocator",
"{",
"Name",
":",
"req",
".",
"GetName",
"(",
")",
",",
"VolumeLabels",
":",
"req",
".",
"GetLabels",
"(",
")",
",",
"Ownership",
":",
"req",
".",
"GetOwnership",
"(",
")",
",",
"}",
"\n",
"}",
"\n\n",
"enumVols",
",",
"err",
":=",
"s",
".",
"driver",
"(",
"ctx",
")",
".",
"Enumerate",
"(",
"locator",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"Internal",
",",
"\"",
"\"",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n\n",
"vols",
":=",
"make",
"(",
"[",
"]",
"*",
"api",
".",
"SdkVolumeInspectResponse",
",",
"0",
",",
"len",
"(",
"enumVols",
")",
")",
"\n",
"for",
"_",
",",
"vol",
":=",
"range",
"enumVols",
"{",
"// Check access",
"if",
"vol",
".",
"IsPermitted",
"(",
"ctx",
",",
"api",
".",
"Ownership_Read",
")",
"{",
"// Check if the caller wants more information",
"if",
"req",
".",
"GetOptions",
"(",
")",
".",
"GetDeep",
"(",
")",
"{",
"resp",
",",
"err",
":=",
"s",
".",
"Inspect",
"(",
"ctx",
",",
"&",
"api",
".",
"SdkVolumeInspectRequest",
"{",
"VolumeId",
":",
"vol",
".",
"GetId",
"(",
")",
",",
"Options",
":",
"req",
".",
"GetOptions",
"(",
")",
",",
"}",
")",
"\n",
"if",
"IsErrorNotFound",
"(",
"err",
")",
"{",
"continue",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"vols",
"=",
"append",
"(",
"vols",
",",
"resp",
")",
"\n",
"}",
"else",
"{",
"// Caller does not require a deep inspect",
"// Add the object now",
"vols",
"=",
"append",
"(",
"vols",
",",
"&",
"api",
".",
"SdkVolumeInspectResponse",
"{",
"Volume",
":",
"vol",
",",
"Name",
":",
"vol",
".",
"GetLocator",
"(",
")",
".",
"GetName",
"(",
")",
",",
"Labels",
":",
"vol",
".",
"GetLocator",
"(",
")",
".",
"GetVolumeLabels",
"(",
")",
",",
"}",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"&",
"api",
".",
"SdkVolumeInspectWithFiltersResponse",
"{",
"Volumes",
":",
"vols",
",",
"}",
",",
"nil",
"\n",
"}"
] | // InspectWithFilters is a helper function returning information about volumes which match a filter | [
"InspectWithFilters",
"is",
"a",
"helper",
"function",
"returning",
"information",
"about",
"volumes",
"which",
"match",
"a",
"filter"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/volume_ops.go#L286-L346 | train |
libopenstorage/openstorage | api/server/sdk/volume_ops.go | Inspect | func (s *VolumeServer) Inspect(
ctx context.Context,
req *api.SdkVolumeInspectRequest,
) (*api.SdkVolumeInspectResponse, error) {
if s.cluster() == nil || s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
if len(req.GetVolumeId()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Must supply volume id")
}
var v *api.Volume
if !req.GetOptions().GetDeep() {
vols, err := s.driver(ctx).Enumerate(&api.VolumeLocator{
VolumeIds: []string{req.GetVolumeId()},
}, nil)
if err != nil {
return nil, status.Errorf(
codes.Internal,
"Failed to inspect volume %s: %v",
req.GetVolumeId(), err)
}
if len(vols) == 0 {
return nil, status.Errorf(
codes.NotFound,
"Volume id %s not found",
req.GetVolumeId())
}
v = vols[0]
} else {
vols, err := s.driver(ctx).Inspect([]string{req.GetVolumeId()})
if err == kvdb.ErrNotFound || (err == nil && len(vols) == 0) {
return nil, status.Errorf(
codes.NotFound,
"Volume id %s not found",
req.GetVolumeId())
} else if err != nil {
return nil, status.Errorf(
codes.Internal,
"Failed to inspect volume %s: %v",
req.GetVolumeId(), err)
}
v = vols[0]
}
// Check ownership
if !v.IsPermitted(ctx, api.Ownership_Read) {
return nil, status.Errorf(codes.PermissionDenied, "Access denied to volume %s", v.GetId())
}
return &api.SdkVolumeInspectResponse{
Volume: v,
Name: v.GetLocator().GetName(),
Labels: v.GetLocator().GetVolumeLabels(),
}, nil
} | go | func (s *VolumeServer) Inspect(
ctx context.Context,
req *api.SdkVolumeInspectRequest,
) (*api.SdkVolumeInspectResponse, error) {
if s.cluster() == nil || s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
if len(req.GetVolumeId()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Must supply volume id")
}
var v *api.Volume
if !req.GetOptions().GetDeep() {
vols, err := s.driver(ctx).Enumerate(&api.VolumeLocator{
VolumeIds: []string{req.GetVolumeId()},
}, nil)
if err != nil {
return nil, status.Errorf(
codes.Internal,
"Failed to inspect volume %s: %v",
req.GetVolumeId(), err)
}
if len(vols) == 0 {
return nil, status.Errorf(
codes.NotFound,
"Volume id %s not found",
req.GetVolumeId())
}
v = vols[0]
} else {
vols, err := s.driver(ctx).Inspect([]string{req.GetVolumeId()})
if err == kvdb.ErrNotFound || (err == nil && len(vols) == 0) {
return nil, status.Errorf(
codes.NotFound,
"Volume id %s not found",
req.GetVolumeId())
} else if err != nil {
return nil, status.Errorf(
codes.Internal,
"Failed to inspect volume %s: %v",
req.GetVolumeId(), err)
}
v = vols[0]
}
// Check ownership
if !v.IsPermitted(ctx, api.Ownership_Read) {
return nil, status.Errorf(codes.PermissionDenied, "Access denied to volume %s", v.GetId())
}
return &api.SdkVolumeInspectResponse{
Volume: v,
Name: v.GetLocator().GetName(),
Labels: v.GetLocator().GetVolumeLabels(),
}, nil
} | [
"func",
"(",
"s",
"*",
"VolumeServer",
")",
"Inspect",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"api",
".",
"SdkVolumeInspectRequest",
",",
")",
"(",
"*",
"api",
".",
"SdkVolumeInspectResponse",
",",
"error",
")",
"{",
"if",
"s",
".",
"cluster",
"(",
")",
"==",
"nil",
"||",
"s",
".",
"driver",
"(",
"ctx",
")",
"==",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"Unavailable",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"req",
".",
"GetVolumeId",
"(",
")",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"InvalidArgument",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"var",
"v",
"*",
"api",
".",
"Volume",
"\n",
"if",
"!",
"req",
".",
"GetOptions",
"(",
")",
".",
"GetDeep",
"(",
")",
"{",
"vols",
",",
"err",
":=",
"s",
".",
"driver",
"(",
"ctx",
")",
".",
"Enumerate",
"(",
"&",
"api",
".",
"VolumeLocator",
"{",
"VolumeIds",
":",
"[",
"]",
"string",
"{",
"req",
".",
"GetVolumeId",
"(",
")",
"}",
",",
"}",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"Internal",
",",
"\"",
"\"",
",",
"req",
".",
"GetVolumeId",
"(",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"vols",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"NotFound",
",",
"\"",
"\"",
",",
"req",
".",
"GetVolumeId",
"(",
")",
")",
"\n",
"}",
"\n",
"v",
"=",
"vols",
"[",
"0",
"]",
"\n",
"}",
"else",
"{",
"vols",
",",
"err",
":=",
"s",
".",
"driver",
"(",
"ctx",
")",
".",
"Inspect",
"(",
"[",
"]",
"string",
"{",
"req",
".",
"GetVolumeId",
"(",
")",
"}",
")",
"\n",
"if",
"err",
"==",
"kvdb",
".",
"ErrNotFound",
"||",
"(",
"err",
"==",
"nil",
"&&",
"len",
"(",
"vols",
")",
"==",
"0",
")",
"{",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"NotFound",
",",
"\"",
"\"",
",",
"req",
".",
"GetVolumeId",
"(",
")",
")",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"Internal",
",",
"\"",
"\"",
",",
"req",
".",
"GetVolumeId",
"(",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"v",
"=",
"vols",
"[",
"0",
"]",
"\n",
"}",
"\n\n",
"// Check ownership",
"if",
"!",
"v",
".",
"IsPermitted",
"(",
"ctx",
",",
"api",
".",
"Ownership_Read",
")",
"{",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"PermissionDenied",
",",
"\"",
"\"",
",",
"v",
".",
"GetId",
"(",
")",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"api",
".",
"SdkVolumeInspectResponse",
"{",
"Volume",
":",
"v",
",",
"Name",
":",
"v",
".",
"GetLocator",
"(",
")",
".",
"GetName",
"(",
")",
",",
"Labels",
":",
"v",
".",
"GetLocator",
"(",
")",
".",
"GetVolumeLabels",
"(",
")",
",",
"}",
",",
"nil",
"\n",
"}"
] | // Inspect returns information about a volume | [
"Inspect",
"returns",
"information",
"about",
"a",
"volume"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/volume_ops.go#L349-L405 | train |
libopenstorage/openstorage | api/server/sdk/volume_ops.go | Enumerate | func (s *VolumeServer) Enumerate(
ctx context.Context,
req *api.SdkVolumeEnumerateRequest,
) (*api.SdkVolumeEnumerateResponse, error) {
if s.cluster() == nil || s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
resp, err := s.EnumerateWithFilters(
ctx,
&api.SdkVolumeEnumerateWithFiltersRequest{},
)
if err != nil {
return nil, err
}
return &api.SdkVolumeEnumerateResponse{
VolumeIds: resp.GetVolumeIds(),
}, nil
} | go | func (s *VolumeServer) Enumerate(
ctx context.Context,
req *api.SdkVolumeEnumerateRequest,
) (*api.SdkVolumeEnumerateResponse, error) {
if s.cluster() == nil || s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
resp, err := s.EnumerateWithFilters(
ctx,
&api.SdkVolumeEnumerateWithFiltersRequest{},
)
if err != nil {
return nil, err
}
return &api.SdkVolumeEnumerateResponse{
VolumeIds: resp.GetVolumeIds(),
}, nil
} | [
"func",
"(",
"s",
"*",
"VolumeServer",
")",
"Enumerate",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"api",
".",
"SdkVolumeEnumerateRequest",
",",
")",
"(",
"*",
"api",
".",
"SdkVolumeEnumerateResponse",
",",
"error",
")",
"{",
"if",
"s",
".",
"cluster",
"(",
")",
"==",
"nil",
"||",
"s",
".",
"driver",
"(",
"ctx",
")",
"==",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"Unavailable",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"resp",
",",
"err",
":=",
"s",
".",
"EnumerateWithFilters",
"(",
"ctx",
",",
"&",
"api",
".",
"SdkVolumeEnumerateWithFiltersRequest",
"{",
"}",
",",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"api",
".",
"SdkVolumeEnumerateResponse",
"{",
"VolumeIds",
":",
"resp",
".",
"GetVolumeIds",
"(",
")",
",",
"}",
",",
"nil",
"\n\n",
"}"
] | // Enumerate returns a list of volumes | [
"Enumerate",
"returns",
"a",
"list",
"of",
"volumes"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/volume_ops.go#L408-L428 | train |
libopenstorage/openstorage | api/server/sdk/volume_ops.go | EnumerateWithFilters | func (s *VolumeServer) EnumerateWithFilters(
ctx context.Context,
req *api.SdkVolumeEnumerateWithFiltersRequest,
) (*api.SdkVolumeEnumerateWithFiltersResponse, error) {
if s.cluster() == nil || s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
var locator *api.VolumeLocator
if len(req.GetName()) != 0 ||
len(req.GetLabels()) != 0 ||
req.GetOwnership() != nil {
locator = &api.VolumeLocator{
Name: req.GetName(),
VolumeLabels: req.GetLabels(),
Ownership: req.GetOwnership(),
}
}
vols, err := s.driver(ctx).Enumerate(locator, nil)
if err != nil {
return nil, status.Errorf(
codes.Internal,
"Failed to enumerate volumes: %v",
err.Error())
}
ids := make([]string, 0)
for _, vol := range vols {
// Check access
if vol.IsPermitted(ctx, api.Ownership_Read) {
ids = append(ids, vol.GetId())
}
}
return &api.SdkVolumeEnumerateWithFiltersResponse{
VolumeIds: ids,
}, nil
} | go | func (s *VolumeServer) EnumerateWithFilters(
ctx context.Context,
req *api.SdkVolumeEnumerateWithFiltersRequest,
) (*api.SdkVolumeEnumerateWithFiltersResponse, error) {
if s.cluster() == nil || s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
var locator *api.VolumeLocator
if len(req.GetName()) != 0 ||
len(req.GetLabels()) != 0 ||
req.GetOwnership() != nil {
locator = &api.VolumeLocator{
Name: req.GetName(),
VolumeLabels: req.GetLabels(),
Ownership: req.GetOwnership(),
}
}
vols, err := s.driver(ctx).Enumerate(locator, nil)
if err != nil {
return nil, status.Errorf(
codes.Internal,
"Failed to enumerate volumes: %v",
err.Error())
}
ids := make([]string, 0)
for _, vol := range vols {
// Check access
if vol.IsPermitted(ctx, api.Ownership_Read) {
ids = append(ids, vol.GetId())
}
}
return &api.SdkVolumeEnumerateWithFiltersResponse{
VolumeIds: ids,
}, nil
} | [
"func",
"(",
"s",
"*",
"VolumeServer",
")",
"EnumerateWithFilters",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"api",
".",
"SdkVolumeEnumerateWithFiltersRequest",
",",
")",
"(",
"*",
"api",
".",
"SdkVolumeEnumerateWithFiltersResponse",
",",
"error",
")",
"{",
"if",
"s",
".",
"cluster",
"(",
")",
"==",
"nil",
"||",
"s",
".",
"driver",
"(",
"ctx",
")",
"==",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"Unavailable",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"var",
"locator",
"*",
"api",
".",
"VolumeLocator",
"\n",
"if",
"len",
"(",
"req",
".",
"GetName",
"(",
")",
")",
"!=",
"0",
"||",
"len",
"(",
"req",
".",
"GetLabels",
"(",
")",
")",
"!=",
"0",
"||",
"req",
".",
"GetOwnership",
"(",
")",
"!=",
"nil",
"{",
"locator",
"=",
"&",
"api",
".",
"VolumeLocator",
"{",
"Name",
":",
"req",
".",
"GetName",
"(",
")",
",",
"VolumeLabels",
":",
"req",
".",
"GetLabels",
"(",
")",
",",
"Ownership",
":",
"req",
".",
"GetOwnership",
"(",
")",
",",
"}",
"\n",
"}",
"\n\n",
"vols",
",",
"err",
":=",
"s",
".",
"driver",
"(",
"ctx",
")",
".",
"Enumerate",
"(",
"locator",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"Internal",
",",
"\"",
"\"",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n\n",
"ids",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
")",
"\n",
"for",
"_",
",",
"vol",
":=",
"range",
"vols",
"{",
"// Check access",
"if",
"vol",
".",
"IsPermitted",
"(",
"ctx",
",",
"api",
".",
"Ownership_Read",
")",
"{",
"ids",
"=",
"append",
"(",
"ids",
",",
"vol",
".",
"GetId",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"&",
"api",
".",
"SdkVolumeEnumerateWithFiltersResponse",
"{",
"VolumeIds",
":",
"ids",
",",
"}",
",",
"nil",
"\n",
"}"
] | // EnumerateWithFilters returns a list of volumes for the provided filters | [
"EnumerateWithFilters",
"returns",
"a",
"list",
"of",
"volumes",
"for",
"the",
"provided",
"filters"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/volume_ops.go#L431-L470 | train |
libopenstorage/openstorage | api/server/sdk/volume_ops.go | Update | func (s *VolumeServer) Update(
ctx context.Context,
req *api.SdkVolumeUpdateRequest,
) (*api.SdkVolumeUpdateResponse, error) {
if s.cluster() == nil || s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
if len(req.GetVolumeId()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Must supply volume id")
}
// Get current state
// This checks for Read access in ownership
resp, err := s.Inspect(ctx, &api.SdkVolumeInspectRequest{
VolumeId: req.GetVolumeId(),
})
if err != nil {
return nil, err
}
// Check if the caller can update the volume
if !resp.GetVolume().IsPermitted(ctx, api.Ownership_Write) {
return nil, status.Errorf(codes.PermissionDenied, "Cannot update volume")
}
// Merge specs
spec := s.mergeVolumeSpecs(resp.GetVolume().GetSpec(), req.GetSpec())
// Update Ownership... carefully
// First point to the original ownership
spec.Ownership = resp.GetVolume().GetSpec().GetOwnership()
// Check if we have been provided an update to the ownership
if req.GetSpec().GetOwnership() != nil {
if spec.Ownership == nil {
spec.Ownership = &api.Ownership{}
}
user, _ := auth.NewUserInfoFromContext(ctx)
if err := spec.Ownership.Update(req.GetSpec().GetOwnership(), user); err != nil {
return nil, err
}
}
// Check if labels have been updated
var locator *api.VolumeLocator
if len(req.GetLabels()) != 0 {
locator = &api.VolumeLocator{VolumeLabels: req.GetLabels()}
}
// Validate/Update given spec according to default storage policy set
// to make sure if update does not violates default policy
updatedSpec, err := GetDefaultVolSpecs(ctx, spec, true)
if err != nil {
return nil, err
}
// Send to driver
if err := s.driver(ctx).Set(req.GetVolumeId(), locator, updatedSpec); err != nil {
return nil, status.Errorf(codes.Internal, "Failed to update volume: %v", err)
}
return &api.SdkVolumeUpdateResponse{}, nil
} | go | func (s *VolumeServer) Update(
ctx context.Context,
req *api.SdkVolumeUpdateRequest,
) (*api.SdkVolumeUpdateResponse, error) {
if s.cluster() == nil || s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
if len(req.GetVolumeId()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Must supply volume id")
}
// Get current state
// This checks for Read access in ownership
resp, err := s.Inspect(ctx, &api.SdkVolumeInspectRequest{
VolumeId: req.GetVolumeId(),
})
if err != nil {
return nil, err
}
// Check if the caller can update the volume
if !resp.GetVolume().IsPermitted(ctx, api.Ownership_Write) {
return nil, status.Errorf(codes.PermissionDenied, "Cannot update volume")
}
// Merge specs
spec := s.mergeVolumeSpecs(resp.GetVolume().GetSpec(), req.GetSpec())
// Update Ownership... carefully
// First point to the original ownership
spec.Ownership = resp.GetVolume().GetSpec().GetOwnership()
// Check if we have been provided an update to the ownership
if req.GetSpec().GetOwnership() != nil {
if spec.Ownership == nil {
spec.Ownership = &api.Ownership{}
}
user, _ := auth.NewUserInfoFromContext(ctx)
if err := spec.Ownership.Update(req.GetSpec().GetOwnership(), user); err != nil {
return nil, err
}
}
// Check if labels have been updated
var locator *api.VolumeLocator
if len(req.GetLabels()) != 0 {
locator = &api.VolumeLocator{VolumeLabels: req.GetLabels()}
}
// Validate/Update given spec according to default storage policy set
// to make sure if update does not violates default policy
updatedSpec, err := GetDefaultVolSpecs(ctx, spec, true)
if err != nil {
return nil, err
}
// Send to driver
if err := s.driver(ctx).Set(req.GetVolumeId(), locator, updatedSpec); err != nil {
return nil, status.Errorf(codes.Internal, "Failed to update volume: %v", err)
}
return &api.SdkVolumeUpdateResponse{}, nil
} | [
"func",
"(",
"s",
"*",
"VolumeServer",
")",
"Update",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"api",
".",
"SdkVolumeUpdateRequest",
",",
")",
"(",
"*",
"api",
".",
"SdkVolumeUpdateResponse",
",",
"error",
")",
"{",
"if",
"s",
".",
"cluster",
"(",
")",
"==",
"nil",
"||",
"s",
".",
"driver",
"(",
"ctx",
")",
"==",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"Unavailable",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"req",
".",
"GetVolumeId",
"(",
")",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"InvalidArgument",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Get current state",
"// This checks for Read access in ownership",
"resp",
",",
"err",
":=",
"s",
".",
"Inspect",
"(",
"ctx",
",",
"&",
"api",
".",
"SdkVolumeInspectRequest",
"{",
"VolumeId",
":",
"req",
".",
"GetVolumeId",
"(",
")",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Check if the caller can update the volume",
"if",
"!",
"resp",
".",
"GetVolume",
"(",
")",
".",
"IsPermitted",
"(",
"ctx",
",",
"api",
".",
"Ownership_Write",
")",
"{",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"PermissionDenied",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Merge specs",
"spec",
":=",
"s",
".",
"mergeVolumeSpecs",
"(",
"resp",
".",
"GetVolume",
"(",
")",
".",
"GetSpec",
"(",
")",
",",
"req",
".",
"GetSpec",
"(",
")",
")",
"\n",
"// Update Ownership... carefully",
"// First point to the original ownership",
"spec",
".",
"Ownership",
"=",
"resp",
".",
"GetVolume",
"(",
")",
".",
"GetSpec",
"(",
")",
".",
"GetOwnership",
"(",
")",
"\n\n",
"// Check if we have been provided an update to the ownership",
"if",
"req",
".",
"GetSpec",
"(",
")",
".",
"GetOwnership",
"(",
")",
"!=",
"nil",
"{",
"if",
"spec",
".",
"Ownership",
"==",
"nil",
"{",
"spec",
".",
"Ownership",
"=",
"&",
"api",
".",
"Ownership",
"{",
"}",
"\n",
"}",
"\n\n",
"user",
",",
"_",
":=",
"auth",
".",
"NewUserInfoFromContext",
"(",
"ctx",
")",
"\n",
"if",
"err",
":=",
"spec",
".",
"Ownership",
".",
"Update",
"(",
"req",
".",
"GetSpec",
"(",
")",
".",
"GetOwnership",
"(",
")",
",",
"user",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Check if labels have been updated",
"var",
"locator",
"*",
"api",
".",
"VolumeLocator",
"\n",
"if",
"len",
"(",
"req",
".",
"GetLabels",
"(",
")",
")",
"!=",
"0",
"{",
"locator",
"=",
"&",
"api",
".",
"VolumeLocator",
"{",
"VolumeLabels",
":",
"req",
".",
"GetLabels",
"(",
")",
"}",
"\n",
"}",
"\n\n",
"// Validate/Update given spec according to default storage policy set",
"// to make sure if update does not violates default policy",
"updatedSpec",
",",
"err",
":=",
"GetDefaultVolSpecs",
"(",
"ctx",
",",
"spec",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"// Send to driver",
"if",
"err",
":=",
"s",
".",
"driver",
"(",
"ctx",
")",
".",
"Set",
"(",
"req",
".",
"GetVolumeId",
"(",
")",
",",
"locator",
",",
"updatedSpec",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"Internal",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"api",
".",
"SdkVolumeUpdateResponse",
"{",
"}",
",",
"nil",
"\n",
"}"
] | // Update allows the caller to change values in the volume specification | [
"Update",
"allows",
"the",
"caller",
"to",
"change",
"values",
"in",
"the",
"volume",
"specification"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/volume_ops.go#L473-L535 | train |
libopenstorage/openstorage | api/server/sdk/volume_ops.go | Stats | func (s *VolumeServer) Stats(
ctx context.Context,
req *api.SdkVolumeStatsRequest,
) (*api.SdkVolumeStatsResponse, error) {
if s.cluster() == nil || s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
if len(req.GetVolumeId()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Must supply volume id")
}
// Get access rights
if err := s.checkAccessForVolumeId(ctx, req.GetVolumeId(), api.Ownership_Read); err != nil {
return nil, err
}
stats, err := s.driver(ctx).Stats(req.GetVolumeId(), !req.GetNotCumulative())
if err != nil {
return nil, status.Errorf(
codes.Internal,
"Failed to obtain stats for volume %s: %v",
req.GetVolumeId(),
err.Error())
}
return &api.SdkVolumeStatsResponse{
Stats: stats,
}, nil
} | go | func (s *VolumeServer) Stats(
ctx context.Context,
req *api.SdkVolumeStatsRequest,
) (*api.SdkVolumeStatsResponse, error) {
if s.cluster() == nil || s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
if len(req.GetVolumeId()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Must supply volume id")
}
// Get access rights
if err := s.checkAccessForVolumeId(ctx, req.GetVolumeId(), api.Ownership_Read); err != nil {
return nil, err
}
stats, err := s.driver(ctx).Stats(req.GetVolumeId(), !req.GetNotCumulative())
if err != nil {
return nil, status.Errorf(
codes.Internal,
"Failed to obtain stats for volume %s: %v",
req.GetVolumeId(),
err.Error())
}
return &api.SdkVolumeStatsResponse{
Stats: stats,
}, nil
} | [
"func",
"(",
"s",
"*",
"VolumeServer",
")",
"Stats",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"api",
".",
"SdkVolumeStatsRequest",
",",
")",
"(",
"*",
"api",
".",
"SdkVolumeStatsResponse",
",",
"error",
")",
"{",
"if",
"s",
".",
"cluster",
"(",
")",
"==",
"nil",
"||",
"s",
".",
"driver",
"(",
"ctx",
")",
"==",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"Unavailable",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"req",
".",
"GetVolumeId",
"(",
")",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"InvalidArgument",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Get access rights",
"if",
"err",
":=",
"s",
".",
"checkAccessForVolumeId",
"(",
"ctx",
",",
"req",
".",
"GetVolumeId",
"(",
")",
",",
"api",
".",
"Ownership_Read",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"stats",
",",
"err",
":=",
"s",
".",
"driver",
"(",
"ctx",
")",
".",
"Stats",
"(",
"req",
".",
"GetVolumeId",
"(",
")",
",",
"!",
"req",
".",
"GetNotCumulative",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"Internal",
",",
"\"",
"\"",
",",
"req",
".",
"GetVolumeId",
"(",
")",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"api",
".",
"SdkVolumeStatsResponse",
"{",
"Stats",
":",
"stats",
",",
"}",
",",
"nil",
"\n",
"}"
] | // Stats returns volume statistics | [
"Stats",
"returns",
"volume",
"statistics"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/volume_ops.go#L538-L567 | train |
libopenstorage/openstorage | api/server/sdk/volume_ops.go | GetDefaultVolSpecs | func GetDefaultVolSpecs(
ctx context.Context,
spec *api.VolumeSpec,
isUpdate bool,
) (*api.VolumeSpec, error) {
storPolicy, err := policy.Inst()
if err != nil {
return nil, status.Errorf(codes.Internal, "Unable to get storage policy instance %v", err)
}
var policy *api.SdkStoragePolicy
// check if custom policy passed with volume
if spec.GetStoragePolicy() != "" {
inspReq := &api.SdkOpenStoragePolicyInspectRequest{
// name of storage policy specified in volSpecs
Name: spec.GetStoragePolicy(),
}
// inspect will make sure user will atleast have read access
customPolicy, customErr := storPolicy.Inspect(ctx, inspReq)
if customErr != nil {
return nil, customErr
}
policy = customPolicy.GetStoragePolicy()
} else {
// check if default storage policy is set
defPolicy, err := storPolicy.DefaultInspect(context.Background(), &api.SdkOpenStoragePolicyDefaultInspectRequest{})
if err != nil {
// err means there is policy stored, but we are not able to retrive it
// hence we are not allowing volume create operation
return nil, status.Errorf(codes.Internal, "Unable to get default policy details %v", err)
} else if defPolicy.GetStoragePolicy() == nil {
// no default storage policy found
return spec, nil
}
policy = defPolicy.GetStoragePolicy()
}
// track volume created using storage policy
spec.StoragePolicy = policy.GetName()
// check if volume update request, if allowupdate is set
// return spec received as it is
if isUpdate && policy.GetAllowUpdate() {
if !policy.IsPermitted(ctx, api.Ownership_Write) {
return nil, status.Errorf(codes.PermissionDenied, "Cannot use storage policy %v", policy.GetName())
}
return spec, nil
}
return mergeVolumeSpecsPolicy(spec, policy.GetPolicy(), policy.GetForce())
} | go | func GetDefaultVolSpecs(
ctx context.Context,
spec *api.VolumeSpec,
isUpdate bool,
) (*api.VolumeSpec, error) {
storPolicy, err := policy.Inst()
if err != nil {
return nil, status.Errorf(codes.Internal, "Unable to get storage policy instance %v", err)
}
var policy *api.SdkStoragePolicy
// check if custom policy passed with volume
if spec.GetStoragePolicy() != "" {
inspReq := &api.SdkOpenStoragePolicyInspectRequest{
// name of storage policy specified in volSpecs
Name: spec.GetStoragePolicy(),
}
// inspect will make sure user will atleast have read access
customPolicy, customErr := storPolicy.Inspect(ctx, inspReq)
if customErr != nil {
return nil, customErr
}
policy = customPolicy.GetStoragePolicy()
} else {
// check if default storage policy is set
defPolicy, err := storPolicy.DefaultInspect(context.Background(), &api.SdkOpenStoragePolicyDefaultInspectRequest{})
if err != nil {
// err means there is policy stored, but we are not able to retrive it
// hence we are not allowing volume create operation
return nil, status.Errorf(codes.Internal, "Unable to get default policy details %v", err)
} else if defPolicy.GetStoragePolicy() == nil {
// no default storage policy found
return spec, nil
}
policy = defPolicy.GetStoragePolicy()
}
// track volume created using storage policy
spec.StoragePolicy = policy.GetName()
// check if volume update request, if allowupdate is set
// return spec received as it is
if isUpdate && policy.GetAllowUpdate() {
if !policy.IsPermitted(ctx, api.Ownership_Write) {
return nil, status.Errorf(codes.PermissionDenied, "Cannot use storage policy %v", policy.GetName())
}
return spec, nil
}
return mergeVolumeSpecsPolicy(spec, policy.GetPolicy(), policy.GetForce())
} | [
"func",
"GetDefaultVolSpecs",
"(",
"ctx",
"context",
".",
"Context",
",",
"spec",
"*",
"api",
".",
"VolumeSpec",
",",
"isUpdate",
"bool",
",",
")",
"(",
"*",
"api",
".",
"VolumeSpec",
",",
"error",
")",
"{",
"storPolicy",
",",
"err",
":=",
"policy",
".",
"Inst",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"Internal",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"var",
"policy",
"*",
"api",
".",
"SdkStoragePolicy",
"\n",
"// check if custom policy passed with volume",
"if",
"spec",
".",
"GetStoragePolicy",
"(",
")",
"!=",
"\"",
"\"",
"{",
"inspReq",
":=",
"&",
"api",
".",
"SdkOpenStoragePolicyInspectRequest",
"{",
"// name of storage policy specified in volSpecs",
"Name",
":",
"spec",
".",
"GetStoragePolicy",
"(",
")",
",",
"}",
"\n",
"// inspect will make sure user will atleast have read access",
"customPolicy",
",",
"customErr",
":=",
"storPolicy",
".",
"Inspect",
"(",
"ctx",
",",
"inspReq",
")",
"\n",
"if",
"customErr",
"!=",
"nil",
"{",
"return",
"nil",
",",
"customErr",
"\n",
"}",
"\n\n",
"policy",
"=",
"customPolicy",
".",
"GetStoragePolicy",
"(",
")",
"\n",
"}",
"else",
"{",
"// check if default storage policy is set",
"defPolicy",
",",
"err",
":=",
"storPolicy",
".",
"DefaultInspect",
"(",
"context",
".",
"Background",
"(",
")",
",",
"&",
"api",
".",
"SdkOpenStoragePolicyDefaultInspectRequest",
"{",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// err means there is policy stored, but we are not able to retrive it",
"// hence we are not allowing volume create operation",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"Internal",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"else",
"if",
"defPolicy",
".",
"GetStoragePolicy",
"(",
")",
"==",
"nil",
"{",
"// no default storage policy found",
"return",
"spec",
",",
"nil",
"\n",
"}",
"\n",
"policy",
"=",
"defPolicy",
".",
"GetStoragePolicy",
"(",
")",
"\n",
"}",
"\n\n",
"// track volume created using storage policy",
"spec",
".",
"StoragePolicy",
"=",
"policy",
".",
"GetName",
"(",
")",
"\n",
"// check if volume update request, if allowupdate is set",
"// return spec received as it is",
"if",
"isUpdate",
"&&",
"policy",
".",
"GetAllowUpdate",
"(",
")",
"{",
"if",
"!",
"policy",
".",
"IsPermitted",
"(",
"ctx",
",",
"api",
".",
"Ownership_Write",
")",
"{",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"PermissionDenied",
",",
"\"",
"\"",
",",
"policy",
".",
"GetName",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"spec",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"mergeVolumeSpecsPolicy",
"(",
"spec",
",",
"policy",
".",
"GetPolicy",
"(",
")",
",",
"policy",
".",
"GetForce",
"(",
")",
")",
"\n",
"}"
] | // GetDefaultVolSpecs returns volume spec merged with default storage policy applied if any | [
"GetDefaultVolSpecs",
"returns",
"volume",
"spec",
"merged",
"with",
"default",
"storage",
"policy",
"applied",
"if",
"any"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/volume_ops.go#L751-L801 | train |
libopenstorage/openstorage | alerts/alerts.go | Tag | func (e Error) Tag(tag Error) Error {
return Error(string(tag) + ":" + string(e))
} | go | func (e Error) Tag(tag Error) Error {
return Error(string(tag) + ":" + string(e))
} | [
"func",
"(",
"e",
"Error",
")",
"Tag",
"(",
"tag",
"Error",
")",
"Error",
"{",
"return",
"Error",
"(",
"string",
"(",
"tag",
")",
"+",
"\"",
"\"",
"+",
"string",
"(",
"e",
")",
")",
"\n",
"}"
] | // Tag tags an error with a tag string.
// Helpful for providing error contexts. | [
"Tag",
"tags",
"an",
"error",
"with",
"a",
"tag",
"string",
".",
"Helpful",
"for",
"providing",
"error",
"contexts",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/alerts/alerts.go#L27-L29 | train |
libopenstorage/openstorage | alerts/alerts.go | Enumerate | func (m *manager) Enumerate(filters ...Filter) ([]*api.Alert, error) {
myAlerts := make([]*api.Alert, 0, 0)
keys, err := getUniqueKeysFromFilters(filters...)
if err != nil {
return nil, err
}
// enumerate for unique keys
for key := range keys {
kvps, err := enumerate(m.kv, key)
if err != nil {
return nil, err
}
for _, kvp := range kvps {
alert := new(api.Alert)
if err := json.Unmarshal(kvp.Value, alert); err != nil {
return nil, err
}
if len(filters) == 0 {
myAlerts = append(myAlerts, alert)
continue
}
for _, filter := range filters {
if match, err := filter.Match(alert); err != nil {
return nil, err
} else {
// if alert is matched by at least one filter,
// include it and break out of loop to avoid further checks.
if match {
myAlerts = append(myAlerts, alert)
break
}
}
}
}
}
return myAlerts, nil
} | go | func (m *manager) Enumerate(filters ...Filter) ([]*api.Alert, error) {
myAlerts := make([]*api.Alert, 0, 0)
keys, err := getUniqueKeysFromFilters(filters...)
if err != nil {
return nil, err
}
// enumerate for unique keys
for key := range keys {
kvps, err := enumerate(m.kv, key)
if err != nil {
return nil, err
}
for _, kvp := range kvps {
alert := new(api.Alert)
if err := json.Unmarshal(kvp.Value, alert); err != nil {
return nil, err
}
if len(filters) == 0 {
myAlerts = append(myAlerts, alert)
continue
}
for _, filter := range filters {
if match, err := filter.Match(alert); err != nil {
return nil, err
} else {
// if alert is matched by at least one filter,
// include it and break out of loop to avoid further checks.
if match {
myAlerts = append(myAlerts, alert)
break
}
}
}
}
}
return myAlerts, nil
} | [
"func",
"(",
"m",
"*",
"manager",
")",
"Enumerate",
"(",
"filters",
"...",
"Filter",
")",
"(",
"[",
"]",
"*",
"api",
".",
"Alert",
",",
"error",
")",
"{",
"myAlerts",
":=",
"make",
"(",
"[",
"]",
"*",
"api",
".",
"Alert",
",",
"0",
",",
"0",
")",
"\n",
"keys",
",",
"err",
":=",
"getUniqueKeysFromFilters",
"(",
"filters",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// enumerate for unique keys",
"for",
"key",
":=",
"range",
"keys",
"{",
"kvps",
",",
"err",
":=",
"enumerate",
"(",
"m",
".",
"kv",
",",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"kvp",
":=",
"range",
"kvps",
"{",
"alert",
":=",
"new",
"(",
"api",
".",
"Alert",
")",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"kvp",
".",
"Value",
",",
"alert",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"filters",
")",
"==",
"0",
"{",
"myAlerts",
"=",
"append",
"(",
"myAlerts",
",",
"alert",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"filter",
":=",
"range",
"filters",
"{",
"if",
"match",
",",
"err",
":=",
"filter",
".",
"Match",
"(",
"alert",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"else",
"{",
"// if alert is matched by at least one filter,",
"// include it and break out of loop to avoid further checks.",
"if",
"match",
"{",
"myAlerts",
"=",
"append",
"(",
"myAlerts",
",",
"alert",
")",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"myAlerts",
",",
"nil",
"\n",
"}"
] | // Enumerate takes a variadic list of filters that are first analyzed to see if one filter
// is inclusive of other. Only the filters that are unique supersets are retained and their contents
// is fetched using kvdb enumerate. | [
"Enumerate",
"takes",
"a",
"variadic",
"list",
"of",
"filters",
"that",
"are",
"first",
"analyzed",
"to",
"see",
"if",
"one",
"filter",
"is",
"inclusive",
"of",
"other",
".",
"Only",
"the",
"filters",
"that",
"are",
"unique",
"supersets",
"are",
"retained",
"and",
"their",
"contents",
"is",
"fetched",
"using",
"kvdb",
"enumerate",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/alerts/alerts.go#L139-L180 | train |
libopenstorage/openstorage | osdconfig/callback.go | execClusterCallbacks | func (manager *configManager) execClusterCallbacks(f CallbackClusterConfigFunc, data *data) {
config := new(ClusterConfig)
if err := json.Unmarshal(data.Value, config); err != nil {
logrus.Error(err)
return
}
f(config)
} | go | func (manager *configManager) execClusterCallbacks(f CallbackClusterConfigFunc, data *data) {
config := new(ClusterConfig)
if err := json.Unmarshal(data.Value, config); err != nil {
logrus.Error(err)
return
}
f(config)
} | [
"func",
"(",
"manager",
"*",
"configManager",
")",
"execClusterCallbacks",
"(",
"f",
"CallbackClusterConfigFunc",
",",
"data",
"*",
"data",
")",
"{",
"config",
":=",
"new",
"(",
"ClusterConfig",
")",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
".",
"Value",
",",
"config",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Error",
"(",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"f",
"(",
"config",
")",
"\n",
"}"
] | // execClusterCallbacks executes a registered cluster watcher | [
"execClusterCallbacks",
"executes",
"a",
"registered",
"cluster",
"watcher"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/osdconfig/callback.go#L12-L20 | train |
libopenstorage/openstorage | osdconfig/callback.go | execNodeCallbacks | func (manager *configManager) execNodeCallbacks(f CallbackNodeConfigFunc, data *data) {
config := new(NodeConfig)
if err := json.Unmarshal(data.Value, config); err != nil {
logrus.Error(err)
return
}
f(config)
} | go | func (manager *configManager) execNodeCallbacks(f CallbackNodeConfigFunc, data *data) {
config := new(NodeConfig)
if err := json.Unmarshal(data.Value, config); err != nil {
logrus.Error(err)
return
}
f(config)
} | [
"func",
"(",
"manager",
"*",
"configManager",
")",
"execNodeCallbacks",
"(",
"f",
"CallbackNodeConfigFunc",
",",
"data",
"*",
"data",
")",
"{",
"config",
":=",
"new",
"(",
"NodeConfig",
")",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
".",
"Value",
",",
"config",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Error",
"(",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"f",
"(",
"config",
")",
"\n",
"}"
] | // execNodeCallbacks executes a registered node watcher | [
"execNodeCallbacks",
"executes",
"a",
"registered",
"node",
"watcher"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/osdconfig/callback.go#L23-L31 | train |
libopenstorage/openstorage | osdconfig/callback.go | kvdbCallback | func (manager *configManager) kvdbCallback(prefix string,
opaque interface{}, kvp *kvdb.KVPair, err error) error {
manager.Lock()
defer manager.Unlock()
c, ok := opaque.(*dataToKvdb)
if !ok {
return fmt.Errorf("opaque value type is incorrect")
}
x := new(data)
if kvp != nil {
x.Key = kvp.Key
x.Value = kvp.Value
}
x.Type = c.Type
switch c.Type {
case clusterWatcher:
for _, f := range manager.cbCluster {
go func(f1 CallbackClusterConfigFunc, wd *data) {
manager.execClusterCallbacks(f1, wd)
}(f, copyData(x))
}
case nodeWatcher:
for _, f := range manager.cbNode {
go func(f1 CallbackNodeConfigFunc, wd *data) {
manager.execNodeCallbacks(f1, wd)
}(f, copyData(x))
}
}
return nil
} | go | func (manager *configManager) kvdbCallback(prefix string,
opaque interface{}, kvp *kvdb.KVPair, err error) error {
manager.Lock()
defer manager.Unlock()
c, ok := opaque.(*dataToKvdb)
if !ok {
return fmt.Errorf("opaque value type is incorrect")
}
x := new(data)
if kvp != nil {
x.Key = kvp.Key
x.Value = kvp.Value
}
x.Type = c.Type
switch c.Type {
case clusterWatcher:
for _, f := range manager.cbCluster {
go func(f1 CallbackClusterConfigFunc, wd *data) {
manager.execClusterCallbacks(f1, wd)
}(f, copyData(x))
}
case nodeWatcher:
for _, f := range manager.cbNode {
go func(f1 CallbackNodeConfigFunc, wd *data) {
manager.execNodeCallbacks(f1, wd)
}(f, copyData(x))
}
}
return nil
} | [
"func",
"(",
"manager",
"*",
"configManager",
")",
"kvdbCallback",
"(",
"prefix",
"string",
",",
"opaque",
"interface",
"{",
"}",
",",
"kvp",
"*",
"kvdb",
".",
"KVPair",
",",
"err",
"error",
")",
"error",
"{",
"manager",
".",
"Lock",
"(",
")",
"\n",
"defer",
"manager",
".",
"Unlock",
"(",
")",
"\n\n",
"c",
",",
"ok",
":=",
"opaque",
".",
"(",
"*",
"dataToKvdb",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"x",
":=",
"new",
"(",
"data",
")",
"\n",
"if",
"kvp",
"!=",
"nil",
"{",
"x",
".",
"Key",
"=",
"kvp",
".",
"Key",
"\n",
"x",
".",
"Value",
"=",
"kvp",
".",
"Value",
"\n",
"}",
"\n",
"x",
".",
"Type",
"=",
"c",
".",
"Type",
"\n",
"switch",
"c",
".",
"Type",
"{",
"case",
"clusterWatcher",
":",
"for",
"_",
",",
"f",
":=",
"range",
"manager",
".",
"cbCluster",
"{",
"go",
"func",
"(",
"f1",
"CallbackClusterConfigFunc",
",",
"wd",
"*",
"data",
")",
"{",
"manager",
".",
"execClusterCallbacks",
"(",
"f1",
",",
"wd",
")",
"\n",
"}",
"(",
"f",
",",
"copyData",
"(",
"x",
")",
")",
"\n",
"}",
"\n",
"case",
"nodeWatcher",
":",
"for",
"_",
",",
"f",
":=",
"range",
"manager",
".",
"cbNode",
"{",
"go",
"func",
"(",
"f1",
"CallbackNodeConfigFunc",
",",
"wd",
"*",
"data",
")",
"{",
"manager",
".",
"execNodeCallbacks",
"(",
"f1",
",",
"wd",
")",
"\n",
"}",
"(",
"f",
",",
"copyData",
"(",
"x",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // kvdbCallback is a callback to be registered with kvdb.
// this callback simply receives data from kvdb and reflects it on a channel it receives in opaque | [
"kvdbCallback",
"is",
"a",
"callback",
"to",
"be",
"registered",
"with",
"kvdb",
".",
"this",
"callback",
"simply",
"receives",
"data",
"from",
"kvdb",
"and",
"reflects",
"it",
"on",
"a",
"channel",
"it",
"receives",
"in",
"opaque"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/osdconfig/callback.go#L35-L67 | train |
libopenstorage/openstorage | api/server/volume.go | create | func (vd *volAPI) create(w http.ResponseWriter, r *http.Request) {
var dcRes api.VolumeCreateResponse
var dcReq api.VolumeCreateRequest
method := "create"
if err := json.NewDecoder(r.Body).Decode(&dcReq); err != nil {
fmt.Println("returning error here")
vd.sendError(vd.name, method, w, err.Error(), http.StatusBadRequest)
return
}
// Get context with auth token
ctx, err := vd.annotateContext(r)
if err != nil {
vd.sendError(vd.name, method, w, err.Error(), http.StatusBadRequest)
return
}
// Get gRPC connection
conn, err := vd.getConn()
if err != nil {
vd.sendError(vd.name, method, w, err.Error(), http.StatusInternalServerError)
return
}
spec := dcReq.GetSpec()
if spec.VolumeLabels == nil {
spec.VolumeLabels = make(map[string]string)
}
for k, v := range dcReq.Locator.GetVolumeLabels() {
spec.VolumeLabels[k] = v
}
volumes := api.NewOpenStorageVolumeClient(conn)
id, err := volumes.Create(ctx, &api.SdkVolumeCreateRequest{
Name: dcReq.Locator.GetName(),
Labels: dcReq.Locator.GetVolumeLabels(),
Spec: dcReq.GetSpec(),
})
dcRes.VolumeResponse = &api.VolumeResponse{Error: responseStatus(err)}
if err == nil {
dcRes.Id = id.GetVolumeId()
}
json.NewEncoder(w).Encode(&dcRes)
} | go | func (vd *volAPI) create(w http.ResponseWriter, r *http.Request) {
var dcRes api.VolumeCreateResponse
var dcReq api.VolumeCreateRequest
method := "create"
if err := json.NewDecoder(r.Body).Decode(&dcReq); err != nil {
fmt.Println("returning error here")
vd.sendError(vd.name, method, w, err.Error(), http.StatusBadRequest)
return
}
// Get context with auth token
ctx, err := vd.annotateContext(r)
if err != nil {
vd.sendError(vd.name, method, w, err.Error(), http.StatusBadRequest)
return
}
// Get gRPC connection
conn, err := vd.getConn()
if err != nil {
vd.sendError(vd.name, method, w, err.Error(), http.StatusInternalServerError)
return
}
spec := dcReq.GetSpec()
if spec.VolumeLabels == nil {
spec.VolumeLabels = make(map[string]string)
}
for k, v := range dcReq.Locator.GetVolumeLabels() {
spec.VolumeLabels[k] = v
}
volumes := api.NewOpenStorageVolumeClient(conn)
id, err := volumes.Create(ctx, &api.SdkVolumeCreateRequest{
Name: dcReq.Locator.GetName(),
Labels: dcReq.Locator.GetVolumeLabels(),
Spec: dcReq.GetSpec(),
})
dcRes.VolumeResponse = &api.VolumeResponse{Error: responseStatus(err)}
if err == nil {
dcRes.Id = id.GetVolumeId()
}
json.NewEncoder(w).Encode(&dcRes)
} | [
"func",
"(",
"vd",
"*",
"volAPI",
")",
"create",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"var",
"dcRes",
"api",
".",
"VolumeCreateResponse",
"\n",
"var",
"dcReq",
"api",
".",
"VolumeCreateRequest",
"\n",
"method",
":=",
"\"",
"\"",
"\n\n",
"if",
"err",
":=",
"json",
".",
"NewDecoder",
"(",
"r",
".",
"Body",
")",
".",
"Decode",
"(",
"&",
"dcReq",
")",
";",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"vd",
".",
"sendError",
"(",
"vd",
".",
"name",
",",
"method",
",",
"w",
",",
"err",
".",
"Error",
"(",
")",
",",
"http",
".",
"StatusBadRequest",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// Get context with auth token",
"ctx",
",",
"err",
":=",
"vd",
".",
"annotateContext",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"vd",
".",
"sendError",
"(",
"vd",
".",
"name",
",",
"method",
",",
"w",
",",
"err",
".",
"Error",
"(",
")",
",",
"http",
".",
"StatusBadRequest",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// Get gRPC connection",
"conn",
",",
"err",
":=",
"vd",
".",
"getConn",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"vd",
".",
"sendError",
"(",
"vd",
".",
"name",
",",
"method",
",",
"w",
",",
"err",
".",
"Error",
"(",
")",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"return",
"\n",
"}",
"\n",
"spec",
":=",
"dcReq",
".",
"GetSpec",
"(",
")",
"\n",
"if",
"spec",
".",
"VolumeLabels",
"==",
"nil",
"{",
"spec",
".",
"VolumeLabels",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"}",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"dcReq",
".",
"Locator",
".",
"GetVolumeLabels",
"(",
")",
"{",
"spec",
".",
"VolumeLabels",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n\n",
"volumes",
":=",
"api",
".",
"NewOpenStorageVolumeClient",
"(",
"conn",
")",
"\n",
"id",
",",
"err",
":=",
"volumes",
".",
"Create",
"(",
"ctx",
",",
"&",
"api",
".",
"SdkVolumeCreateRequest",
"{",
"Name",
":",
"dcReq",
".",
"Locator",
".",
"GetName",
"(",
")",
",",
"Labels",
":",
"dcReq",
".",
"Locator",
".",
"GetVolumeLabels",
"(",
")",
",",
"Spec",
":",
"dcReq",
".",
"GetSpec",
"(",
")",
",",
"}",
")",
"\n\n",
"dcRes",
".",
"VolumeResponse",
"=",
"&",
"api",
".",
"VolumeResponse",
"{",
"Error",
":",
"responseStatus",
"(",
"err",
")",
"}",
"\n",
"if",
"err",
"==",
"nil",
"{",
"dcRes",
".",
"Id",
"=",
"id",
".",
"GetVolumeId",
"(",
")",
"\n",
"}",
"\n\n",
"json",
".",
"NewEncoder",
"(",
"w",
")",
".",
"Encode",
"(",
"&",
"dcRes",
")",
"\n",
"}"
] | // Creates a single volume with given spec. | [
"Creates",
"a",
"single",
"volume",
"with",
"given",
"spec",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/volume.go#L187-L232 | train |
libopenstorage/openstorage | api/server/volume.go | GetVolumeAPIRoutes | func GetVolumeAPIRoutes(name, sdkUds string) []*Route {
volMgmtApi := newVolumeAPI(name, sdkUds)
return volMgmtApi.Routes()
} | go | func GetVolumeAPIRoutes(name, sdkUds string) []*Route {
volMgmtApi := newVolumeAPI(name, sdkUds)
return volMgmtApi.Routes()
} | [
"func",
"GetVolumeAPIRoutes",
"(",
"name",
",",
"sdkUds",
"string",
")",
"[",
"]",
"*",
"Route",
"{",
"volMgmtApi",
":=",
"newVolumeAPI",
"(",
"name",
",",
"sdkUds",
")",
"\n",
"return",
"volMgmtApi",
".",
"Routes",
"(",
")",
"\n",
"}"
] | // GetVolumeAPIRoutes returns all the volume routes.
// A driver could use this function if it does not want openstorage
// to setup the REST server but it sets up its own and wants to add
// volume routes | [
"GetVolumeAPIRoutes",
"returns",
"all",
"the",
"volume",
"routes",
".",
"A",
"driver",
"could",
"use",
"this",
"function",
"if",
"it",
"does",
"not",
"want",
"openstorage",
"to",
"setup",
"the",
"REST",
"server",
"but",
"it",
"sets",
"up",
"its",
"own",
"and",
"wants",
"to",
"add",
"volume",
"routes"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/volume.go#L1748-L1751 | train |
libopenstorage/openstorage | api/server/volume.go | GetVolumeAPIRoutesWithAuth | func GetVolumeAPIRoutesWithAuth(
name, sdkUds string,
authProviderType secrets.AuthTokenProviders,
authProvider osecrets.Secrets,
router *mux.Router,
serverRegisterRoute ServerRegisterRoute,
preRouteCheckFn func(http.ResponseWriter, *http.Request) bool,
) (*mux.Router, error) {
vd := &volAPI{
restBase: restBase{version: volume.APIVersion, name: name},
sdkUds: sdkUds,
dummyMux: runtime.NewServeMux(),
}
authM, err := NewAuthMiddleware(authProvider, authProviderType)
if err != nil {
return router, err
}
// We setup auth middlewares for all the APIs that get invoked
// from a Container Orchestrator.
// - CREATE
// - ATTACH/MOUNT
// - DETACH/UNMOUNT
// - DELETE
// For all other routes it is expected that the REST client uses an auth token
// Setup middleware for Create
nCreate := negroni.New()
nCreate.Use(negroni.HandlerFunc(authM.createWithAuth))
createRoute := vd.volumeCreateRoute()
nCreate.UseHandlerFunc(serverRegisterRoute(createRoute.fn, preRouteCheckFn))
router.Methods(createRoute.verb).Path(createRoute.path).Handler(nCreate)
// Setup middleware for Delete
nDelete := negroni.New()
nDelete.Use(negroni.HandlerFunc(authM.deleteWithAuth))
deleteRoute := vd.volumeDeleteRoute()
nDelete.UseHandlerFunc(serverRegisterRoute(deleteRoute.fn, preRouteCheckFn))
router.Methods(deleteRoute.verb).Path(deleteRoute.path).Handler(nDelete)
// Setup middleware for Set
nSet := negroni.New()
nSet.Use(negroni.HandlerFunc(authM.setWithAuth))
setRoute := vd.volumeSetRoute()
nSet.UseHandlerFunc(serverRegisterRoute(setRoute.fn, preRouteCheckFn))
router.Methods(setRoute.verb).Path(setRoute.path).Handler(nSet)
// Setup middleware for Inspect
nInspect := negroni.New()
nInspect.Use(negroni.HandlerFunc(authM.inspectWithAuth))
inspectRoute := vd.volumeInspectRoute()
nInspect.UseHandlerFunc(serverRegisterRoute(inspectRoute.fn, preRouteCheckFn))
router.Methods(inspectRoute.verb).Path(inspectRoute.path).Handler(nInspect)
routes := []*Route{vd.versionRoute()}
routes = append(routes, vd.otherVolumeRoutes()...)
routes = append(routes, vd.snapRoutes()...)
routes = append(routes, vd.backupRoutes()...)
routes = append(routes, vd.credsRoutes()...)
routes = append(routes, vd.migrateRoutes()...)
for _, v := range routes {
router.Methods(v.verb).Path(v.path).HandlerFunc(serverRegisterRoute(v.fn, preRouteCheckFn))
}
return router, nil
} | go | func GetVolumeAPIRoutesWithAuth(
name, sdkUds string,
authProviderType secrets.AuthTokenProviders,
authProvider osecrets.Secrets,
router *mux.Router,
serverRegisterRoute ServerRegisterRoute,
preRouteCheckFn func(http.ResponseWriter, *http.Request) bool,
) (*mux.Router, error) {
vd := &volAPI{
restBase: restBase{version: volume.APIVersion, name: name},
sdkUds: sdkUds,
dummyMux: runtime.NewServeMux(),
}
authM, err := NewAuthMiddleware(authProvider, authProviderType)
if err != nil {
return router, err
}
// We setup auth middlewares for all the APIs that get invoked
// from a Container Orchestrator.
// - CREATE
// - ATTACH/MOUNT
// - DETACH/UNMOUNT
// - DELETE
// For all other routes it is expected that the REST client uses an auth token
// Setup middleware for Create
nCreate := negroni.New()
nCreate.Use(negroni.HandlerFunc(authM.createWithAuth))
createRoute := vd.volumeCreateRoute()
nCreate.UseHandlerFunc(serverRegisterRoute(createRoute.fn, preRouteCheckFn))
router.Methods(createRoute.verb).Path(createRoute.path).Handler(nCreate)
// Setup middleware for Delete
nDelete := negroni.New()
nDelete.Use(negroni.HandlerFunc(authM.deleteWithAuth))
deleteRoute := vd.volumeDeleteRoute()
nDelete.UseHandlerFunc(serverRegisterRoute(deleteRoute.fn, preRouteCheckFn))
router.Methods(deleteRoute.verb).Path(deleteRoute.path).Handler(nDelete)
// Setup middleware for Set
nSet := negroni.New()
nSet.Use(negroni.HandlerFunc(authM.setWithAuth))
setRoute := vd.volumeSetRoute()
nSet.UseHandlerFunc(serverRegisterRoute(setRoute.fn, preRouteCheckFn))
router.Methods(setRoute.verb).Path(setRoute.path).Handler(nSet)
// Setup middleware for Inspect
nInspect := negroni.New()
nInspect.Use(negroni.HandlerFunc(authM.inspectWithAuth))
inspectRoute := vd.volumeInspectRoute()
nInspect.UseHandlerFunc(serverRegisterRoute(inspectRoute.fn, preRouteCheckFn))
router.Methods(inspectRoute.verb).Path(inspectRoute.path).Handler(nInspect)
routes := []*Route{vd.versionRoute()}
routes = append(routes, vd.otherVolumeRoutes()...)
routes = append(routes, vd.snapRoutes()...)
routes = append(routes, vd.backupRoutes()...)
routes = append(routes, vd.credsRoutes()...)
routes = append(routes, vd.migrateRoutes()...)
for _, v := range routes {
router.Methods(v.verb).Path(v.path).HandlerFunc(serverRegisterRoute(v.fn, preRouteCheckFn))
}
return router, nil
} | [
"func",
"GetVolumeAPIRoutesWithAuth",
"(",
"name",
",",
"sdkUds",
"string",
",",
"authProviderType",
"secrets",
".",
"AuthTokenProviders",
",",
"authProvider",
"osecrets",
".",
"Secrets",
",",
"router",
"*",
"mux",
".",
"Router",
",",
"serverRegisterRoute",
"ServerRegisterRoute",
",",
"preRouteCheckFn",
"func",
"(",
"http",
".",
"ResponseWriter",
",",
"*",
"http",
".",
"Request",
")",
"bool",
",",
")",
"(",
"*",
"mux",
".",
"Router",
",",
"error",
")",
"{",
"vd",
":=",
"&",
"volAPI",
"{",
"restBase",
":",
"restBase",
"{",
"version",
":",
"volume",
".",
"APIVersion",
",",
"name",
":",
"name",
"}",
",",
"sdkUds",
":",
"sdkUds",
",",
"dummyMux",
":",
"runtime",
".",
"NewServeMux",
"(",
")",
",",
"}",
"\n\n",
"authM",
",",
"err",
":=",
"NewAuthMiddleware",
"(",
"authProvider",
",",
"authProviderType",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"router",
",",
"err",
"\n",
"}",
"\n\n",
"// We setup auth middlewares for all the APIs that get invoked",
"// from a Container Orchestrator.",
"// - CREATE",
"// - ATTACH/MOUNT",
"// - DETACH/UNMOUNT",
"// - DELETE",
"// For all other routes it is expected that the REST client uses an auth token",
"// Setup middleware for Create",
"nCreate",
":=",
"negroni",
".",
"New",
"(",
")",
"\n",
"nCreate",
".",
"Use",
"(",
"negroni",
".",
"HandlerFunc",
"(",
"authM",
".",
"createWithAuth",
")",
")",
"\n",
"createRoute",
":=",
"vd",
".",
"volumeCreateRoute",
"(",
")",
"\n",
"nCreate",
".",
"UseHandlerFunc",
"(",
"serverRegisterRoute",
"(",
"createRoute",
".",
"fn",
",",
"preRouteCheckFn",
")",
")",
"\n",
"router",
".",
"Methods",
"(",
"createRoute",
".",
"verb",
")",
".",
"Path",
"(",
"createRoute",
".",
"path",
")",
".",
"Handler",
"(",
"nCreate",
")",
"\n\n",
"// Setup middleware for Delete",
"nDelete",
":=",
"negroni",
".",
"New",
"(",
")",
"\n",
"nDelete",
".",
"Use",
"(",
"negroni",
".",
"HandlerFunc",
"(",
"authM",
".",
"deleteWithAuth",
")",
")",
"\n",
"deleteRoute",
":=",
"vd",
".",
"volumeDeleteRoute",
"(",
")",
"\n",
"nDelete",
".",
"UseHandlerFunc",
"(",
"serverRegisterRoute",
"(",
"deleteRoute",
".",
"fn",
",",
"preRouteCheckFn",
")",
")",
"\n",
"router",
".",
"Methods",
"(",
"deleteRoute",
".",
"verb",
")",
".",
"Path",
"(",
"deleteRoute",
".",
"path",
")",
".",
"Handler",
"(",
"nDelete",
")",
"\n\n",
"// Setup middleware for Set",
"nSet",
":=",
"negroni",
".",
"New",
"(",
")",
"\n",
"nSet",
".",
"Use",
"(",
"negroni",
".",
"HandlerFunc",
"(",
"authM",
".",
"setWithAuth",
")",
")",
"\n",
"setRoute",
":=",
"vd",
".",
"volumeSetRoute",
"(",
")",
"\n",
"nSet",
".",
"UseHandlerFunc",
"(",
"serverRegisterRoute",
"(",
"setRoute",
".",
"fn",
",",
"preRouteCheckFn",
")",
")",
"\n",
"router",
".",
"Methods",
"(",
"setRoute",
".",
"verb",
")",
".",
"Path",
"(",
"setRoute",
".",
"path",
")",
".",
"Handler",
"(",
"nSet",
")",
"\n\n",
"// Setup middleware for Inspect",
"nInspect",
":=",
"negroni",
".",
"New",
"(",
")",
"\n",
"nInspect",
".",
"Use",
"(",
"negroni",
".",
"HandlerFunc",
"(",
"authM",
".",
"inspectWithAuth",
")",
")",
"\n",
"inspectRoute",
":=",
"vd",
".",
"volumeInspectRoute",
"(",
")",
"\n",
"nInspect",
".",
"UseHandlerFunc",
"(",
"serverRegisterRoute",
"(",
"inspectRoute",
".",
"fn",
",",
"preRouteCheckFn",
")",
")",
"\n",
"router",
".",
"Methods",
"(",
"inspectRoute",
".",
"verb",
")",
".",
"Path",
"(",
"inspectRoute",
".",
"path",
")",
".",
"Handler",
"(",
"nInspect",
")",
"\n\n",
"routes",
":=",
"[",
"]",
"*",
"Route",
"{",
"vd",
".",
"versionRoute",
"(",
")",
"}",
"\n",
"routes",
"=",
"append",
"(",
"routes",
",",
"vd",
".",
"otherVolumeRoutes",
"(",
")",
"...",
")",
"\n",
"routes",
"=",
"append",
"(",
"routes",
",",
"vd",
".",
"snapRoutes",
"(",
")",
"...",
")",
"\n",
"routes",
"=",
"append",
"(",
"routes",
",",
"vd",
".",
"backupRoutes",
"(",
")",
"...",
")",
"\n",
"routes",
"=",
"append",
"(",
"routes",
",",
"vd",
".",
"credsRoutes",
"(",
")",
"...",
")",
"\n",
"routes",
"=",
"append",
"(",
"routes",
",",
"vd",
".",
"migrateRoutes",
"(",
")",
"...",
")",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"routes",
"{",
"router",
".",
"Methods",
"(",
"v",
".",
"verb",
")",
".",
"Path",
"(",
"v",
".",
"path",
")",
".",
"HandlerFunc",
"(",
"serverRegisterRoute",
"(",
"v",
".",
"fn",
",",
"preRouteCheckFn",
")",
")",
"\n",
"}",
"\n",
"return",
"router",
",",
"nil",
"\n\n",
"}"
] | // GetVolumeAPIRoutesWithAuth returns a router with all the volume routes
// added to the router along with the auth middleware
// - preRouteCheckFn is a handler that gets executed before the actual volume handler
// is invoked. It is added for legacy support where negroni middleware was not used | [
"GetVolumeAPIRoutesWithAuth",
"returns",
"a",
"router",
"with",
"all",
"the",
"volume",
"routes",
"added",
"to",
"the",
"router",
"along",
"with",
"the",
"auth",
"middleware",
"-",
"preRouteCheckFn",
"is",
"a",
"handler",
"that",
"gets",
"executed",
"before",
"the",
"actual",
"volume",
"handler",
"is",
"invoked",
".",
"It",
"is",
"added",
"for",
"legacy",
"support",
"where",
"negroni",
"middleware",
"was",
"not",
"used"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/volume.go#L1765-L1831 | train |
libopenstorage/openstorage | api/client/volume/client.go | Create | func (v *volumeClient) Create(locator *api.VolumeLocator, source *api.Source,
spec *api.VolumeSpec) (string, error) {
response := &api.VolumeCreateResponse{}
request := &api.VolumeCreateRequest{
Locator: locator,
Source: source,
Spec: spec,
}
if err := v.c.Post().Resource(volumePath).Body(request).Do().Unmarshal(response); err != nil {
return "", err
}
if response.VolumeResponse != nil && response.VolumeResponse.Error != "" {
return "", errors.New(response.VolumeResponse.Error)
}
return response.Id, nil
} | go | func (v *volumeClient) Create(locator *api.VolumeLocator, source *api.Source,
spec *api.VolumeSpec) (string, error) {
response := &api.VolumeCreateResponse{}
request := &api.VolumeCreateRequest{
Locator: locator,
Source: source,
Spec: spec,
}
if err := v.c.Post().Resource(volumePath).Body(request).Do().Unmarshal(response); err != nil {
return "", err
}
if response.VolumeResponse != nil && response.VolumeResponse.Error != "" {
return "", errors.New(response.VolumeResponse.Error)
}
return response.Id, nil
} | [
"func",
"(",
"v",
"*",
"volumeClient",
")",
"Create",
"(",
"locator",
"*",
"api",
".",
"VolumeLocator",
",",
"source",
"*",
"api",
".",
"Source",
",",
"spec",
"*",
"api",
".",
"VolumeSpec",
")",
"(",
"string",
",",
"error",
")",
"{",
"response",
":=",
"&",
"api",
".",
"VolumeCreateResponse",
"{",
"}",
"\n",
"request",
":=",
"&",
"api",
".",
"VolumeCreateRequest",
"{",
"Locator",
":",
"locator",
",",
"Source",
":",
"source",
",",
"Spec",
":",
"spec",
",",
"}",
"\n",
"if",
"err",
":=",
"v",
".",
"c",
".",
"Post",
"(",
")",
".",
"Resource",
"(",
"volumePath",
")",
".",
"Body",
"(",
"request",
")",
".",
"Do",
"(",
")",
".",
"Unmarshal",
"(",
"response",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"response",
".",
"VolumeResponse",
"!=",
"nil",
"&&",
"response",
".",
"VolumeResponse",
".",
"Error",
"!=",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"response",
".",
"VolumeResponse",
".",
"Error",
")",
"\n",
"}",
"\n",
"return",
"response",
".",
"Id",
",",
"nil",
"\n",
"}"
] | // Create a new Vol for the specific volume spev.c.
// It returns a system generated VolumeID that uniquely identifies the volume | [
"Create",
"a",
"new",
"Vol",
"for",
"the",
"specific",
"volume",
"spev",
".",
"c",
".",
"It",
"returns",
"a",
"system",
"generated",
"VolumeID",
"that",
"uniquely",
"identifies",
"the",
"volume"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/client/volume/client.go#L125-L140 | train |
libopenstorage/openstorage | api/client/volume/client.go | Inspect | func (v *volumeClient) Inspect(ids []string) ([]*api.Volume, error) {
if len(ids) == 0 {
return nil, nil
}
var volumes []*api.Volume
request := v.c.Get().Resource(volumePath)
for _, id := range ids {
request.QueryOption(api.OptVolumeID, id)
}
if err := request.Do().Unmarshal(&volumes); err != nil {
return nil, err
}
return volumes, nil
} | go | func (v *volumeClient) Inspect(ids []string) ([]*api.Volume, error) {
if len(ids) == 0 {
return nil, nil
}
var volumes []*api.Volume
request := v.c.Get().Resource(volumePath)
for _, id := range ids {
request.QueryOption(api.OptVolumeID, id)
}
if err := request.Do().Unmarshal(&volumes); err != nil {
return nil, err
}
return volumes, nil
} | [
"func",
"(",
"v",
"*",
"volumeClient",
")",
"Inspect",
"(",
"ids",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"*",
"api",
".",
"Volume",
",",
"error",
")",
"{",
"if",
"len",
"(",
"ids",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"var",
"volumes",
"[",
"]",
"*",
"api",
".",
"Volume",
"\n",
"request",
":=",
"v",
".",
"c",
".",
"Get",
"(",
")",
".",
"Resource",
"(",
"volumePath",
")",
"\n",
"for",
"_",
",",
"id",
":=",
"range",
"ids",
"{",
"request",
".",
"QueryOption",
"(",
"api",
".",
"OptVolumeID",
",",
"id",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"request",
".",
"Do",
"(",
")",
".",
"Unmarshal",
"(",
"&",
"volumes",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"volumes",
",",
"nil",
"\n",
"}"
] | // Inspect specified volumes.
// Errors ErrEnoEnt may be returned. | [
"Inspect",
"specified",
"volumes",
".",
"Errors",
"ErrEnoEnt",
"may",
"be",
"returned",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/client/volume/client.go#L149-L162 | train |
libopenstorage/openstorage | api/client/volume/client.go | Snapshot | func (v *volumeClient) Snapshot(volumeID string,
readonly bool,
locator *api.VolumeLocator,
noRetry bool,
) (string, error) {
response := &api.SnapCreateResponse{}
request := &api.SnapCreateRequest{
Id: volumeID,
Readonly: readonly,
Locator: locator,
NoRetry: noRetry,
}
if err := v.c.Post().Resource(snapPath).Body(request).Do().Unmarshal(response); err != nil {
return "", err
}
// TODO(pedge): this probably should not be embedded in this way
if response.VolumeCreateResponse != nil &&
response.VolumeCreateResponse.VolumeResponse != nil &&
response.VolumeCreateResponse.VolumeResponse.Error != "" {
return "", errors.New(
response.VolumeCreateResponse.VolumeResponse.Error)
}
if response.VolumeCreateResponse != nil {
return response.VolumeCreateResponse.Id, nil
}
return "", nil
} | go | func (v *volumeClient) Snapshot(volumeID string,
readonly bool,
locator *api.VolumeLocator,
noRetry bool,
) (string, error) {
response := &api.SnapCreateResponse{}
request := &api.SnapCreateRequest{
Id: volumeID,
Readonly: readonly,
Locator: locator,
NoRetry: noRetry,
}
if err := v.c.Post().Resource(snapPath).Body(request).Do().Unmarshal(response); err != nil {
return "", err
}
// TODO(pedge): this probably should not be embedded in this way
if response.VolumeCreateResponse != nil &&
response.VolumeCreateResponse.VolumeResponse != nil &&
response.VolumeCreateResponse.VolumeResponse.Error != "" {
return "", errors.New(
response.VolumeCreateResponse.VolumeResponse.Error)
}
if response.VolumeCreateResponse != nil {
return response.VolumeCreateResponse.Id, nil
}
return "", nil
} | [
"func",
"(",
"v",
"*",
"volumeClient",
")",
"Snapshot",
"(",
"volumeID",
"string",
",",
"readonly",
"bool",
",",
"locator",
"*",
"api",
".",
"VolumeLocator",
",",
"noRetry",
"bool",
",",
")",
"(",
"string",
",",
"error",
")",
"{",
"response",
":=",
"&",
"api",
".",
"SnapCreateResponse",
"{",
"}",
"\n",
"request",
":=",
"&",
"api",
".",
"SnapCreateRequest",
"{",
"Id",
":",
"volumeID",
",",
"Readonly",
":",
"readonly",
",",
"Locator",
":",
"locator",
",",
"NoRetry",
":",
"noRetry",
",",
"}",
"\n",
"if",
"err",
":=",
"v",
".",
"c",
".",
"Post",
"(",
")",
".",
"Resource",
"(",
"snapPath",
")",
".",
"Body",
"(",
"request",
")",
".",
"Do",
"(",
")",
".",
"Unmarshal",
"(",
"response",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"// TODO(pedge): this probably should not be embedded in this way",
"if",
"response",
".",
"VolumeCreateResponse",
"!=",
"nil",
"&&",
"response",
".",
"VolumeCreateResponse",
".",
"VolumeResponse",
"!=",
"nil",
"&&",
"response",
".",
"VolumeCreateResponse",
".",
"VolumeResponse",
".",
"Error",
"!=",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"response",
".",
"VolumeCreateResponse",
".",
"VolumeResponse",
".",
"Error",
")",
"\n",
"}",
"\n",
"if",
"response",
".",
"VolumeCreateResponse",
"!=",
"nil",
"{",
"return",
"response",
".",
"VolumeCreateResponse",
".",
"Id",
",",
"nil",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"nil",
"\n",
"}"
] | // Snap specified volume. IO to the underlying volume should be quiesced before
// calling this function.
// Errors ErrEnoEnt may be returned | [
"Snap",
"specified",
"volume",
".",
"IO",
"to",
"the",
"underlying",
"volume",
"should",
"be",
"quiesced",
"before",
"calling",
"this",
"function",
".",
"Errors",
"ErrEnoEnt",
"may",
"be",
"returned"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/client/volume/client.go#L180-L207 | train |
libopenstorage/openstorage | api/client/volume/client.go | Restore | func (v *volumeClient) Restore(volumeID string, snapID string) error {
response := &api.VolumeResponse{}
req := v.c.Post().Resource(snapPath + "/restore").Instance(volumeID)
req.QueryOption(api.OptSnapID, snapID)
if err := req.Do().Unmarshal(response); err != nil {
return err
}
if response.Error != "" {
return errors.New(response.Error)
}
return nil
} | go | func (v *volumeClient) Restore(volumeID string, snapID string) error {
response := &api.VolumeResponse{}
req := v.c.Post().Resource(snapPath + "/restore").Instance(volumeID)
req.QueryOption(api.OptSnapID, snapID)
if err := req.Do().Unmarshal(response); err != nil {
return err
}
if response.Error != "" {
return errors.New(response.Error)
}
return nil
} | [
"func",
"(",
"v",
"*",
"volumeClient",
")",
"Restore",
"(",
"volumeID",
"string",
",",
"snapID",
"string",
")",
"error",
"{",
"response",
":=",
"&",
"api",
".",
"VolumeResponse",
"{",
"}",
"\n",
"req",
":=",
"v",
".",
"c",
".",
"Post",
"(",
")",
".",
"Resource",
"(",
"snapPath",
"+",
"\"",
"\"",
")",
".",
"Instance",
"(",
"volumeID",
")",
"\n",
"req",
".",
"QueryOption",
"(",
"api",
".",
"OptSnapID",
",",
"snapID",
")",
"\n\n",
"if",
"err",
":=",
"req",
".",
"Do",
"(",
")",
".",
"Unmarshal",
"(",
"response",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"response",
".",
"Error",
"!=",
"\"",
"\"",
"{",
"return",
"errors",
".",
"New",
"(",
"response",
".",
"Error",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Restore specified volume to given snapshot state | [
"Restore",
"specified",
"volume",
"to",
"given",
"snapshot",
"state"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/client/volume/client.go#L210-L222 | train |
libopenstorage/openstorage | api/client/volume/client.go | Stats | func (v *volumeClient) Stats(
volumeID string,
cumulative bool,
) (*api.Stats, error) {
stats := &api.Stats{}
req := v.c.Get().Resource(volumePath + "/stats").Instance(volumeID)
req.QueryOption(api.OptCumulative, strconv.FormatBool(cumulative))
err := req.Do().Unmarshal(stats)
return stats, err
} | go | func (v *volumeClient) Stats(
volumeID string,
cumulative bool,
) (*api.Stats, error) {
stats := &api.Stats{}
req := v.c.Get().Resource(volumePath + "/stats").Instance(volumeID)
req.QueryOption(api.OptCumulative, strconv.FormatBool(cumulative))
err := req.Do().Unmarshal(stats)
return stats, err
} | [
"func",
"(",
"v",
"*",
"volumeClient",
")",
"Stats",
"(",
"volumeID",
"string",
",",
"cumulative",
"bool",
",",
")",
"(",
"*",
"api",
".",
"Stats",
",",
"error",
")",
"{",
"stats",
":=",
"&",
"api",
".",
"Stats",
"{",
"}",
"\n",
"req",
":=",
"v",
".",
"c",
".",
"Get",
"(",
")",
".",
"Resource",
"(",
"volumePath",
"+",
"\"",
"\"",
")",
".",
"Instance",
"(",
"volumeID",
")",
"\n",
"req",
".",
"QueryOption",
"(",
"api",
".",
"OptCumulative",
",",
"strconv",
".",
"FormatBool",
"(",
"cumulative",
")",
")",
"\n\n",
"err",
":=",
"req",
".",
"Do",
"(",
")",
".",
"Unmarshal",
"(",
"stats",
")",
"\n",
"return",
"stats",
",",
"err",
"\n\n",
"}"
] | // Stats for specified volume.
// Errors ErrEnoEnt may be returned | [
"Stats",
"for",
"specified",
"volume",
".",
"Errors",
"ErrEnoEnt",
"may",
"be",
"returned"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/client/volume/client.go#L226-L237 | train |
libopenstorage/openstorage | api/client/volume/client.go | UsedSize | func (v *volumeClient) UsedSize(
volumeID string,
) (uint64, error) {
var usedSize uint64
req := v.c.Get().Resource(volumePath + "/usedsize").Instance(volumeID)
err := req.Do().Unmarshal(&usedSize)
return usedSize, err
} | go | func (v *volumeClient) UsedSize(
volumeID string,
) (uint64, error) {
var usedSize uint64
req := v.c.Get().Resource(volumePath + "/usedsize").Instance(volumeID)
err := req.Do().Unmarshal(&usedSize)
return usedSize, err
} | [
"func",
"(",
"v",
"*",
"volumeClient",
")",
"UsedSize",
"(",
"volumeID",
"string",
",",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"var",
"usedSize",
"uint64",
"\n",
"req",
":=",
"v",
".",
"c",
".",
"Get",
"(",
")",
".",
"Resource",
"(",
"volumePath",
"+",
"\"",
"\"",
")",
".",
"Instance",
"(",
"volumeID",
")",
"\n",
"err",
":=",
"req",
".",
"Do",
"(",
")",
".",
"Unmarshal",
"(",
"&",
"usedSize",
")",
"\n",
"return",
"usedSize",
",",
"err",
"\n",
"}"
] | // UsedSize returns allocated volume size.
// Errors ErrEnoEnt may be returned | [
"UsedSize",
"returns",
"allocated",
"volume",
"size",
".",
"Errors",
"ErrEnoEnt",
"may",
"be",
"returned"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/client/volume/client.go#L241-L248 | train |
libopenstorage/openstorage | api/client/volume/client.go | GetActiveRequests | func (v *volumeClient) GetActiveRequests() (*api.ActiveRequests, error) {
requests := &api.ActiveRequests{}
resp := v.c.Get().Resource(volumePath + "/requests").Instance("vol_id").Do()
if resp.Error() != nil {
return nil, resp.FormatError()
}
if err := resp.Unmarshal(requests); err != nil {
return nil, err
}
return requests, nil
} | go | func (v *volumeClient) GetActiveRequests() (*api.ActiveRequests, error) {
requests := &api.ActiveRequests{}
resp := v.c.Get().Resource(volumePath + "/requests").Instance("vol_id").Do()
if resp.Error() != nil {
return nil, resp.FormatError()
}
if err := resp.Unmarshal(requests); err != nil {
return nil, err
}
return requests, nil
} | [
"func",
"(",
"v",
"*",
"volumeClient",
")",
"GetActiveRequests",
"(",
")",
"(",
"*",
"api",
".",
"ActiveRequests",
",",
"error",
")",
"{",
"requests",
":=",
"&",
"api",
".",
"ActiveRequests",
"{",
"}",
"\n",
"resp",
":=",
"v",
".",
"c",
".",
"Get",
"(",
")",
".",
"Resource",
"(",
"volumePath",
"+",
"\"",
"\"",
")",
".",
"Instance",
"(",
"\"",
"\"",
")",
".",
"Do",
"(",
")",
"\n\n",
"if",
"resp",
".",
"Error",
"(",
")",
"!=",
"nil",
"{",
"return",
"nil",
",",
"resp",
".",
"FormatError",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"resp",
".",
"Unmarshal",
"(",
"requests",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"requests",
",",
"nil",
"\n",
"}"
] | // Active Requests on all volume. | [
"Active",
"Requests",
"on",
"all",
"volume",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/client/volume/client.go#L251-L265 | train |
libopenstorage/openstorage | api/client/volume/client.go | Enumerate | func (v *volumeClient) Enumerate(locator *api.VolumeLocator,
labels map[string]string) ([]*api.Volume, error) {
var volumes []*api.Volume
req := v.c.Get().Resource(volumePath)
if locator.Name != "" {
req.QueryOption(api.OptName, locator.Name)
}
if len(locator.VolumeLabels) != 0 {
req.QueryOptionLabel(api.OptLabel, locator.VolumeLabels)
}
if len(labels) != 0 {
req.QueryOptionLabel(api.OptConfigLabel, labels)
}
resp := req.Do()
if resp.Error() != nil {
return nil, resp.FormatError()
}
if err := resp.Unmarshal(&volumes); err != nil {
return nil, err
}
return volumes, nil
} | go | func (v *volumeClient) Enumerate(locator *api.VolumeLocator,
labels map[string]string) ([]*api.Volume, error) {
var volumes []*api.Volume
req := v.c.Get().Resource(volumePath)
if locator.Name != "" {
req.QueryOption(api.OptName, locator.Name)
}
if len(locator.VolumeLabels) != 0 {
req.QueryOptionLabel(api.OptLabel, locator.VolumeLabels)
}
if len(labels) != 0 {
req.QueryOptionLabel(api.OptConfigLabel, labels)
}
resp := req.Do()
if resp.Error() != nil {
return nil, resp.FormatError()
}
if err := resp.Unmarshal(&volumes); err != nil {
return nil, err
}
return volumes, nil
} | [
"func",
"(",
"v",
"*",
"volumeClient",
")",
"Enumerate",
"(",
"locator",
"*",
"api",
".",
"VolumeLocator",
",",
"labels",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"[",
"]",
"*",
"api",
".",
"Volume",
",",
"error",
")",
"{",
"var",
"volumes",
"[",
"]",
"*",
"api",
".",
"Volume",
"\n",
"req",
":=",
"v",
".",
"c",
".",
"Get",
"(",
")",
".",
"Resource",
"(",
"volumePath",
")",
"\n",
"if",
"locator",
".",
"Name",
"!=",
"\"",
"\"",
"{",
"req",
".",
"QueryOption",
"(",
"api",
".",
"OptName",
",",
"locator",
".",
"Name",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"locator",
".",
"VolumeLabels",
")",
"!=",
"0",
"{",
"req",
".",
"QueryOptionLabel",
"(",
"api",
".",
"OptLabel",
",",
"locator",
".",
"VolumeLabels",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"labels",
")",
"!=",
"0",
"{",
"req",
".",
"QueryOptionLabel",
"(",
"api",
".",
"OptConfigLabel",
",",
"labels",
")",
"\n",
"}",
"\n",
"resp",
":=",
"req",
".",
"Do",
"(",
")",
"\n",
"if",
"resp",
".",
"Error",
"(",
")",
"!=",
"nil",
"{",
"return",
"nil",
",",
"resp",
".",
"FormatError",
"(",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"resp",
".",
"Unmarshal",
"(",
"&",
"volumes",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"volumes",
",",
"nil",
"\n",
"}"
] | // Enumerate volumes that map to the volumeLocator. Locator fields may be regexp.
// If locator fields are left blank, this will return all volumes. | [
"Enumerate",
"volumes",
"that",
"map",
"to",
"the",
"volumeLocator",
".",
"Locator",
"fields",
"may",
"be",
"regexp",
".",
"If",
"locator",
"fields",
"are",
"left",
"blank",
"this",
"will",
"return",
"all",
"volumes",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/client/volume/client.go#L291-L313 | train |
libopenstorage/openstorage | api/client/volume/client.go | SnapEnumerate | func (v *volumeClient) SnapEnumerate(ids []string,
snapLabels map[string]string) ([]*api.Volume, error) {
var volumes []*api.Volume
request := v.c.Get().Resource(snapPath)
for _, id := range ids {
request.QueryOption(api.OptVolumeID, id)
}
if len(snapLabels) != 0 {
request.QueryOptionLabel(api.OptLabel, snapLabels)
}
if err := request.Do().Unmarshal(&volumes); err != nil {
return nil, err
}
return volumes, nil
} | go | func (v *volumeClient) SnapEnumerate(ids []string,
snapLabels map[string]string) ([]*api.Volume, error) {
var volumes []*api.Volume
request := v.c.Get().Resource(snapPath)
for _, id := range ids {
request.QueryOption(api.OptVolumeID, id)
}
if len(snapLabels) != 0 {
request.QueryOptionLabel(api.OptLabel, snapLabels)
}
if err := request.Do().Unmarshal(&volumes); err != nil {
return nil, err
}
return volumes, nil
} | [
"func",
"(",
"v",
"*",
"volumeClient",
")",
"SnapEnumerate",
"(",
"ids",
"[",
"]",
"string",
",",
"snapLabels",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"[",
"]",
"*",
"api",
".",
"Volume",
",",
"error",
")",
"{",
"var",
"volumes",
"[",
"]",
"*",
"api",
".",
"Volume",
"\n",
"request",
":=",
"v",
".",
"c",
".",
"Get",
"(",
")",
".",
"Resource",
"(",
"snapPath",
")",
"\n",
"for",
"_",
",",
"id",
":=",
"range",
"ids",
"{",
"request",
".",
"QueryOption",
"(",
"api",
".",
"OptVolumeID",
",",
"id",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"snapLabels",
")",
"!=",
"0",
"{",
"request",
".",
"QueryOptionLabel",
"(",
"api",
".",
"OptLabel",
",",
"snapLabels",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"request",
".",
"Do",
"(",
")",
".",
"Unmarshal",
"(",
"&",
"volumes",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"volumes",
",",
"nil",
"\n",
"}"
] | // Enumerate snaps for specified volume
// Count indicates the number of snaps populated. | [
"Enumerate",
"snaps",
"for",
"specified",
"volume",
"Count",
"indicates",
"the",
"number",
"of",
"snaps",
"populated",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/client/volume/client.go#L317-L331 | train |
libopenstorage/openstorage | api/client/volume/client.go | Attach | func (v *volumeClient) Attach(volumeID string, attachOptions map[string]string) (string, error) {
response, err := v.doVolumeSetGetResponse(
volumeID,
&api.VolumeSetRequest{
Action: &api.VolumeStateAction{
Attach: api.VolumeActionParam_VOLUME_ACTION_PARAM_ON,
},
Options: attachOptions,
},
)
if err != nil {
return "", err
}
if response.Volume != nil {
if response.Volume.Spec.Encrypted {
return response.Volume.SecureDevicePath, nil
} else {
return response.Volume.DevicePath, nil
}
}
return "", nil
} | go | func (v *volumeClient) Attach(volumeID string, attachOptions map[string]string) (string, error) {
response, err := v.doVolumeSetGetResponse(
volumeID,
&api.VolumeSetRequest{
Action: &api.VolumeStateAction{
Attach: api.VolumeActionParam_VOLUME_ACTION_PARAM_ON,
},
Options: attachOptions,
},
)
if err != nil {
return "", err
}
if response.Volume != nil {
if response.Volume.Spec.Encrypted {
return response.Volume.SecureDevicePath, nil
} else {
return response.Volume.DevicePath, nil
}
}
return "", nil
} | [
"func",
"(",
"v",
"*",
"volumeClient",
")",
"Attach",
"(",
"volumeID",
"string",
",",
"attachOptions",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"response",
",",
"err",
":=",
"v",
".",
"doVolumeSetGetResponse",
"(",
"volumeID",
",",
"&",
"api",
".",
"VolumeSetRequest",
"{",
"Action",
":",
"&",
"api",
".",
"VolumeStateAction",
"{",
"Attach",
":",
"api",
".",
"VolumeActionParam_VOLUME_ACTION_PARAM_ON",
",",
"}",
",",
"Options",
":",
"attachOptions",
",",
"}",
",",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"response",
".",
"Volume",
"!=",
"nil",
"{",
"if",
"response",
".",
"Volume",
".",
"Spec",
".",
"Encrypted",
"{",
"return",
"response",
".",
"Volume",
".",
"SecureDevicePath",
",",
"nil",
"\n",
"}",
"else",
"{",
"return",
"response",
".",
"Volume",
".",
"DevicePath",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"nil",
"\n",
"}"
] | // Attach map device to the host.
// On success the devicePath specifies location where the device is exported
// Errors ErrEnoEnt, ErrVolAttached may be returned. | [
"Attach",
"map",
"device",
"to",
"the",
"host",
".",
"On",
"success",
"the",
"devicePath",
"specifies",
"location",
"where",
"the",
"device",
"is",
"exported",
"Errors",
"ErrEnoEnt",
"ErrVolAttached",
"may",
"be",
"returned",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/client/volume/client.go#L336-L357 | train |
libopenstorage/openstorage | api/client/volume/client.go | Detach | func (v *volumeClient) Detach(volumeID string, options map[string]string) error {
return v.doVolumeSet(
volumeID,
&api.VolumeSetRequest{
Action: &api.VolumeStateAction{
Attach: api.VolumeActionParam_VOLUME_ACTION_PARAM_OFF,
},
Options: options,
},
)
} | go | func (v *volumeClient) Detach(volumeID string, options map[string]string) error {
return v.doVolumeSet(
volumeID,
&api.VolumeSetRequest{
Action: &api.VolumeStateAction{
Attach: api.VolumeActionParam_VOLUME_ACTION_PARAM_OFF,
},
Options: options,
},
)
} | [
"func",
"(",
"v",
"*",
"volumeClient",
")",
"Detach",
"(",
"volumeID",
"string",
",",
"options",
"map",
"[",
"string",
"]",
"string",
")",
"error",
"{",
"return",
"v",
".",
"doVolumeSet",
"(",
"volumeID",
",",
"&",
"api",
".",
"VolumeSetRequest",
"{",
"Action",
":",
"&",
"api",
".",
"VolumeStateAction",
"{",
"Attach",
":",
"api",
".",
"VolumeActionParam_VOLUME_ACTION_PARAM_OFF",
",",
"}",
",",
"Options",
":",
"options",
",",
"}",
",",
")",
"\n",
"}"
] | // Detach device from the host.
// Errors ErrEnoEnt, ErrVolDetached may be returned. | [
"Detach",
"device",
"from",
"the",
"host",
".",
"Errors",
"ErrEnoEnt",
"ErrVolDetached",
"may",
"be",
"returned",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/client/volume/client.go#L361-L371 | train |
libopenstorage/openstorage | api/client/volume/client.go | CredsEnumerate | func (v *volumeClient) CredsEnumerate() (map[string]interface{}, error) {
creds := make(map[string]interface{}, 0)
err := v.c.Get().Resource(api.OsdCredsPath).Do().Unmarshal(&creds)
return creds, err
} | go | func (v *volumeClient) CredsEnumerate() (map[string]interface{}, error) {
creds := make(map[string]interface{}, 0)
err := v.c.Get().Resource(api.OsdCredsPath).Do().Unmarshal(&creds)
return creds, err
} | [
"func",
"(",
"v",
"*",
"volumeClient",
")",
"CredsEnumerate",
"(",
")",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"creds",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"0",
")",
"\n",
"err",
":=",
"v",
".",
"c",
".",
"Get",
"(",
")",
".",
"Resource",
"(",
"api",
".",
"OsdCredsPath",
")",
".",
"Do",
"(",
")",
".",
"Unmarshal",
"(",
"&",
"creds",
")",
"\n",
"return",
"creds",
",",
"err",
"\n",
"}"
] | // CredsEnumerate enumerates configured credentials in the cluster | [
"CredsEnumerate",
"enumerates",
"configured",
"credentials",
"in",
"the",
"cluster"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/client/volume/client.go#L470-L474 | train |
libopenstorage/openstorage | api/client/volume/client.go | CredsCreate | func (v *volumeClient) CredsCreate(params map[string]string) (string, error) {
createResponse := api.CredCreateResponse{}
request := &api.CredCreateRequest{
InputParams: params,
}
req := v.c.Post().Resource(api.OsdCredsPath).Body(request)
response := req.Do()
if response.Error() != nil {
return "", response.FormatError()
}
if err := response.Unmarshal(&createResponse); err != nil {
return "", err
}
return createResponse.UUID, nil
} | go | func (v *volumeClient) CredsCreate(params map[string]string) (string, error) {
createResponse := api.CredCreateResponse{}
request := &api.CredCreateRequest{
InputParams: params,
}
req := v.c.Post().Resource(api.OsdCredsPath).Body(request)
response := req.Do()
if response.Error() != nil {
return "", response.FormatError()
}
if err := response.Unmarshal(&createResponse); err != nil {
return "", err
}
return createResponse.UUID, nil
} | [
"func",
"(",
"v",
"*",
"volumeClient",
")",
"CredsCreate",
"(",
"params",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"createResponse",
":=",
"api",
".",
"CredCreateResponse",
"{",
"}",
"\n",
"request",
":=",
"&",
"api",
".",
"CredCreateRequest",
"{",
"InputParams",
":",
"params",
",",
"}",
"\n",
"req",
":=",
"v",
".",
"c",
".",
"Post",
"(",
")",
".",
"Resource",
"(",
"api",
".",
"OsdCredsPath",
")",
".",
"Body",
"(",
"request",
")",
"\n",
"response",
":=",
"req",
".",
"Do",
"(",
")",
"\n",
"if",
"response",
".",
"Error",
"(",
")",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"response",
".",
"FormatError",
"(",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"response",
".",
"Unmarshal",
"(",
"&",
"createResponse",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"createResponse",
".",
"UUID",
",",
"nil",
"\n",
"}"
] | // CredsCreate creates credentials for a given cloud provider | [
"CredsCreate",
"creates",
"credentials",
"for",
"a",
"given",
"cloud",
"provider"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/client/volume/client.go#L477-L491 | train |
libopenstorage/openstorage | api/client/volume/client.go | CredsDelete | func (v *volumeClient) CredsDelete(uuid string) error {
req := v.c.Delete().Resource(api.OsdCredsPath).Instance(uuid)
response := req.Do()
if response.Error() != nil {
return response.FormatError()
}
return nil
} | go | func (v *volumeClient) CredsDelete(uuid string) error {
req := v.c.Delete().Resource(api.OsdCredsPath).Instance(uuid)
response := req.Do()
if response.Error() != nil {
return response.FormatError()
}
return nil
} | [
"func",
"(",
"v",
"*",
"volumeClient",
")",
"CredsDelete",
"(",
"uuid",
"string",
")",
"error",
"{",
"req",
":=",
"v",
".",
"c",
".",
"Delete",
"(",
")",
".",
"Resource",
"(",
"api",
".",
"OsdCredsPath",
")",
".",
"Instance",
"(",
"uuid",
")",
"\n",
"response",
":=",
"req",
".",
"Do",
"(",
")",
"\n",
"if",
"response",
".",
"Error",
"(",
")",
"!=",
"nil",
"{",
"return",
"response",
".",
"FormatError",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // CredsDelete deletes the credential with given UUID | [
"CredsDelete",
"deletes",
"the",
"credential",
"with",
"given",
"UUID"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/client/volume/client.go#L494-L501 | train |
libopenstorage/openstorage | api/client/volume/client.go | CredsValidate | func (v *volumeClient) CredsValidate(uuid string) error {
req := v.c.Put().Resource(api.OsdCredsPath + "/validate").Instance(uuid)
response := req.Do()
if response.Error() != nil {
if response.StatusCode() == http.StatusUnprocessableEntity {
return volume.NewCredentialError(response.Error().Error())
}
return response.FormatError()
}
return nil
} | go | func (v *volumeClient) CredsValidate(uuid string) error {
req := v.c.Put().Resource(api.OsdCredsPath + "/validate").Instance(uuid)
response := req.Do()
if response.Error() != nil {
if response.StatusCode() == http.StatusUnprocessableEntity {
return volume.NewCredentialError(response.Error().Error())
}
return response.FormatError()
}
return nil
} | [
"func",
"(",
"v",
"*",
"volumeClient",
")",
"CredsValidate",
"(",
"uuid",
"string",
")",
"error",
"{",
"req",
":=",
"v",
".",
"c",
".",
"Put",
"(",
")",
".",
"Resource",
"(",
"api",
".",
"OsdCredsPath",
"+",
"\"",
"\"",
")",
".",
"Instance",
"(",
"uuid",
")",
"\n",
"response",
":=",
"req",
".",
"Do",
"(",
")",
"\n",
"if",
"response",
".",
"Error",
"(",
")",
"!=",
"nil",
"{",
"if",
"response",
".",
"StatusCode",
"(",
")",
"==",
"http",
".",
"StatusUnprocessableEntity",
"{",
"return",
"volume",
".",
"NewCredentialError",
"(",
"response",
".",
"Error",
"(",
")",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"response",
".",
"FormatError",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // CredsValidate validates the credential by accessuing the cloud
// provider with the given credential | [
"CredsValidate",
"validates",
"the",
"credential",
"by",
"accessuing",
"the",
"cloud",
"provider",
"with",
"the",
"given",
"credential"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/client/volume/client.go#L505-L515 | train |
libopenstorage/openstorage | api/client/volume/client.go | CloudBackupCreate | func (v *volumeClient) CloudBackupCreate(
input *api.CloudBackupCreateRequest,
) (*api.CloudBackupCreateResponse, error) {
createResp := &api.CloudBackupCreateResponse{}
req := v.c.Post().Resource(api.OsdBackupPath).Body(input)
response := req.Do()
if response.Error() != nil {
if response.StatusCode() == http.StatusConflict {
return nil, &ost_errors.ErrExists{
Type: "CloudBackupCreate",
ID: input.Name,
}
}
return nil, response.FormatError()
}
if err := response.Unmarshal(&createResp); err != nil {
return nil, err
}
return createResp, nil
} | go | func (v *volumeClient) CloudBackupCreate(
input *api.CloudBackupCreateRequest,
) (*api.CloudBackupCreateResponse, error) {
createResp := &api.CloudBackupCreateResponse{}
req := v.c.Post().Resource(api.OsdBackupPath).Body(input)
response := req.Do()
if response.Error() != nil {
if response.StatusCode() == http.StatusConflict {
return nil, &ost_errors.ErrExists{
Type: "CloudBackupCreate",
ID: input.Name,
}
}
return nil, response.FormatError()
}
if err := response.Unmarshal(&createResp); err != nil {
return nil, err
}
return createResp, nil
} | [
"func",
"(",
"v",
"*",
"volumeClient",
")",
"CloudBackupCreate",
"(",
"input",
"*",
"api",
".",
"CloudBackupCreateRequest",
",",
")",
"(",
"*",
"api",
".",
"CloudBackupCreateResponse",
",",
"error",
")",
"{",
"createResp",
":=",
"&",
"api",
".",
"CloudBackupCreateResponse",
"{",
"}",
"\n",
"req",
":=",
"v",
".",
"c",
".",
"Post",
"(",
")",
".",
"Resource",
"(",
"api",
".",
"OsdBackupPath",
")",
".",
"Body",
"(",
"input",
")",
"\n",
"response",
":=",
"req",
".",
"Do",
"(",
")",
"\n",
"if",
"response",
".",
"Error",
"(",
")",
"!=",
"nil",
"{",
"if",
"response",
".",
"StatusCode",
"(",
")",
"==",
"http",
".",
"StatusConflict",
"{",
"return",
"nil",
",",
"&",
"ost_errors",
".",
"ErrExists",
"{",
"Type",
":",
"\"",
"\"",
",",
"ID",
":",
"input",
".",
"Name",
",",
"}",
"\n",
"}",
"\n",
"return",
"nil",
",",
"response",
".",
"FormatError",
"(",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"response",
".",
"Unmarshal",
"(",
"&",
"createResp",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"createResp",
",",
"nil",
"\n",
"}"
] | // CloudBackupCreate uploads snapshot of a volume to cloud | [
"CloudBackupCreate",
"uploads",
"snapshot",
"of",
"a",
"volume",
"to",
"cloud"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/client/volume/client.go#L518-L537 | train |
libopenstorage/openstorage | api/client/volume/client.go | CloudBackupGroupCreate | func (v *volumeClient) CloudBackupGroupCreate(
input *api.CloudBackupGroupCreateRequest,
) (*api.CloudBackupGroupCreateResponse, error) {
createResp := &api.CloudBackupGroupCreateResponse{}
req := v.c.Post().Resource(api.OsdBackupPath + "/group").Body(input)
response := req.Do()
if response.Error() != nil {
return nil, response.FormatError()
}
if err := response.Unmarshal(&createResp); err != nil {
return nil, err
}
return createResp, nil
} | go | func (v *volumeClient) CloudBackupGroupCreate(
input *api.CloudBackupGroupCreateRequest,
) (*api.CloudBackupGroupCreateResponse, error) {
createResp := &api.CloudBackupGroupCreateResponse{}
req := v.c.Post().Resource(api.OsdBackupPath + "/group").Body(input)
response := req.Do()
if response.Error() != nil {
return nil, response.FormatError()
}
if err := response.Unmarshal(&createResp); err != nil {
return nil, err
}
return createResp, nil
} | [
"func",
"(",
"v",
"*",
"volumeClient",
")",
"CloudBackupGroupCreate",
"(",
"input",
"*",
"api",
".",
"CloudBackupGroupCreateRequest",
",",
")",
"(",
"*",
"api",
".",
"CloudBackupGroupCreateResponse",
",",
"error",
")",
"{",
"createResp",
":=",
"&",
"api",
".",
"CloudBackupGroupCreateResponse",
"{",
"}",
"\n",
"req",
":=",
"v",
".",
"c",
".",
"Post",
"(",
")",
".",
"Resource",
"(",
"api",
".",
"OsdBackupPath",
"+",
"\"",
"\"",
")",
".",
"Body",
"(",
"input",
")",
"\n",
"response",
":=",
"req",
".",
"Do",
"(",
")",
"\n",
"if",
"response",
".",
"Error",
"(",
")",
"!=",
"nil",
"{",
"return",
"nil",
",",
"response",
".",
"FormatError",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"response",
".",
"Unmarshal",
"(",
"&",
"createResp",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"createResp",
",",
"nil",
"\n",
"}"
] | // CloudBackupGroupCreate uploads snapshots of a volume group to cloud | [
"CloudBackupGroupCreate",
"uploads",
"snapshots",
"of",
"a",
"volume",
"group",
"to",
"cloud"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/client/volume/client.go#L540-L556 | train |
libopenstorage/openstorage | api/client/volume/client.go | CloudBackupRestore | func (v *volumeClient) CloudBackupRestore(
input *api.CloudBackupRestoreRequest,
) (*api.CloudBackupRestoreResponse, error) {
restoreResponse := &api.CloudBackupRestoreResponse{}
req := v.c.Post().Resource(api.OsdBackupPath + "/restore").Body(input)
response := req.Do()
if response.Error() != nil {
if response.StatusCode() == http.StatusConflict {
return nil, &ost_errors.ErrExists{
Type: "CloudBackupRestore",
ID: input.Name,
}
}
return nil, response.FormatError()
}
if err := response.Unmarshal(&restoreResponse); err != nil {
return nil, err
}
return restoreResponse, nil
} | go | func (v *volumeClient) CloudBackupRestore(
input *api.CloudBackupRestoreRequest,
) (*api.CloudBackupRestoreResponse, error) {
restoreResponse := &api.CloudBackupRestoreResponse{}
req := v.c.Post().Resource(api.OsdBackupPath + "/restore").Body(input)
response := req.Do()
if response.Error() != nil {
if response.StatusCode() == http.StatusConflict {
return nil, &ost_errors.ErrExists{
Type: "CloudBackupRestore",
ID: input.Name,
}
}
return nil, response.FormatError()
}
if err := response.Unmarshal(&restoreResponse); err != nil {
return nil, err
}
return restoreResponse, nil
} | [
"func",
"(",
"v",
"*",
"volumeClient",
")",
"CloudBackupRestore",
"(",
"input",
"*",
"api",
".",
"CloudBackupRestoreRequest",
",",
")",
"(",
"*",
"api",
".",
"CloudBackupRestoreResponse",
",",
"error",
")",
"{",
"restoreResponse",
":=",
"&",
"api",
".",
"CloudBackupRestoreResponse",
"{",
"}",
"\n",
"req",
":=",
"v",
".",
"c",
".",
"Post",
"(",
")",
".",
"Resource",
"(",
"api",
".",
"OsdBackupPath",
"+",
"\"",
"\"",
")",
".",
"Body",
"(",
"input",
")",
"\n",
"response",
":=",
"req",
".",
"Do",
"(",
")",
"\n",
"if",
"response",
".",
"Error",
"(",
")",
"!=",
"nil",
"{",
"if",
"response",
".",
"StatusCode",
"(",
")",
"==",
"http",
".",
"StatusConflict",
"{",
"return",
"nil",
",",
"&",
"ost_errors",
".",
"ErrExists",
"{",
"Type",
":",
"\"",
"\"",
",",
"ID",
":",
"input",
".",
"Name",
",",
"}",
"\n",
"}",
"\n",
"return",
"nil",
",",
"response",
".",
"FormatError",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"response",
".",
"Unmarshal",
"(",
"&",
"restoreResponse",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"restoreResponse",
",",
"nil",
"\n",
"}"
] | // CloudBackupRestore downloads a cloud backup to a newly created volume | [
"CloudBackupRestore",
"downloads",
"a",
"cloud",
"backup",
"to",
"a",
"newly",
"created",
"volume"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/client/volume/client.go#L559-L579 | train |
libopenstorage/openstorage | api/client/volume/client.go | CloudBackupSchedCreate | func (v *volumeClient) CloudBackupSchedCreate(
input *api.CloudBackupSchedCreateRequest,
) (*api.CloudBackupSchedCreateResponse, error) {
createResponse := &api.CloudBackupSchedCreateResponse{}
req := v.c.Post().Resource(api.OsdBackupPath + "/sched").Body(input)
response := req.Do()
if response.Error() != nil {
return nil, response.FormatError()
}
if err := response.Unmarshal(&createResponse); err != nil {
return nil, err
}
return createResponse, nil
} | go | func (v *volumeClient) CloudBackupSchedCreate(
input *api.CloudBackupSchedCreateRequest,
) (*api.CloudBackupSchedCreateResponse, error) {
createResponse := &api.CloudBackupSchedCreateResponse{}
req := v.c.Post().Resource(api.OsdBackupPath + "/sched").Body(input)
response := req.Do()
if response.Error() != nil {
return nil, response.FormatError()
}
if err := response.Unmarshal(&createResponse); err != nil {
return nil, err
}
return createResponse, nil
} | [
"func",
"(",
"v",
"*",
"volumeClient",
")",
"CloudBackupSchedCreate",
"(",
"input",
"*",
"api",
".",
"CloudBackupSchedCreateRequest",
",",
")",
"(",
"*",
"api",
".",
"CloudBackupSchedCreateResponse",
",",
"error",
")",
"{",
"createResponse",
":=",
"&",
"api",
".",
"CloudBackupSchedCreateResponse",
"{",
"}",
"\n",
"req",
":=",
"v",
".",
"c",
".",
"Post",
"(",
")",
".",
"Resource",
"(",
"api",
".",
"OsdBackupPath",
"+",
"\"",
"\"",
")",
".",
"Body",
"(",
"input",
")",
"\n",
"response",
":=",
"req",
".",
"Do",
"(",
")",
"\n",
"if",
"response",
".",
"Error",
"(",
")",
"!=",
"nil",
"{",
"return",
"nil",
",",
"response",
".",
"FormatError",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"response",
".",
"Unmarshal",
"(",
"&",
"createResponse",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"createResponse",
",",
"nil",
"\n",
"}"
] | // CloudBackupSchedCreate for a volume creates a schedule to backup volume to cloud | [
"CloudBackupSchedCreate",
"for",
"a",
"volume",
"creates",
"a",
"schedule",
"to",
"backup",
"volume",
"to",
"cloud"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/client/volume/client.go#L687-L701 | train |
libopenstorage/openstorage | api/client/volume/client.go | CloudBackupSchedDelete | func (v *volumeClient) CloudBackupSchedDelete(
input *api.CloudBackupSchedDeleteRequest,
) error {
req := v.c.Delete().Resource(api.OsdBackupPath + "/sched").Body(input)
response := req.Do()
if response.Error() != nil {
return response.FormatError()
}
return nil
} | go | func (v *volumeClient) CloudBackupSchedDelete(
input *api.CloudBackupSchedDeleteRequest,
) error {
req := v.c.Delete().Resource(api.OsdBackupPath + "/sched").Body(input)
response := req.Do()
if response.Error() != nil {
return response.FormatError()
}
return nil
} | [
"func",
"(",
"v",
"*",
"volumeClient",
")",
"CloudBackupSchedDelete",
"(",
"input",
"*",
"api",
".",
"CloudBackupSchedDeleteRequest",
",",
")",
"error",
"{",
"req",
":=",
"v",
".",
"c",
".",
"Delete",
"(",
")",
".",
"Resource",
"(",
"api",
".",
"OsdBackupPath",
"+",
"\"",
"\"",
")",
".",
"Body",
"(",
"input",
")",
"\n",
"response",
":=",
"req",
".",
"Do",
"(",
")",
"\n",
"if",
"response",
".",
"Error",
"(",
")",
"!=",
"nil",
"{",
"return",
"response",
".",
"FormatError",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // CloudBackupSchedDelete delete a volume's cloud backup-schedule | [
"CloudBackupSchedDelete",
"delete",
"a",
"volume",
"s",
"cloud",
"backup",
"-",
"schedule"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/client/volume/client.go#L722-L731 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.