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
pkg/storagepolicy/sdkstoragepolicy.go
Enumerate
func (p *SdkPolicyManager) Enumerate( ctx context.Context, req *api.SdkOpenStoragePolicyEnumerateRequest, ) (*api.SdkOpenStoragePolicyEnumerateResponse, error) { // get all keyValue pair at /storage/policy/policies kvp, err := p.kv.Enumerate(policyPrefix + policyPath) if err != nil { return nil, status.Errorf(codes.Internal, "Failed to get policies from database: %v", err) } policies := make([]*api.SdkStoragePolicy, 0) for _, policy := range kvp { sdkPolicy := &api.SdkStoragePolicy{} err = jsonpb.UnmarshalString(string(policy.Value), sdkPolicy) if err != nil { return nil, status.Errorf(codes.Internal, "Json Unmarshal failed for policy %s: %v", policy.Key, err) } // only enum volumes, owner has read access to if sdkPolicy.IsPermitted(ctx, api.Ownership_Read) { policies = append(policies, sdkPolicy) } } return &api.SdkOpenStoragePolicyEnumerateResponse{ StoragePolicies: policies, }, nil }
go
func (p *SdkPolicyManager) Enumerate( ctx context.Context, req *api.SdkOpenStoragePolicyEnumerateRequest, ) (*api.SdkOpenStoragePolicyEnumerateResponse, error) { // get all keyValue pair at /storage/policy/policies kvp, err := p.kv.Enumerate(policyPrefix + policyPath) if err != nil { return nil, status.Errorf(codes.Internal, "Failed to get policies from database: %v", err) } policies := make([]*api.SdkStoragePolicy, 0) for _, policy := range kvp { sdkPolicy := &api.SdkStoragePolicy{} err = jsonpb.UnmarshalString(string(policy.Value), sdkPolicy) if err != nil { return nil, status.Errorf(codes.Internal, "Json Unmarshal failed for policy %s: %v", policy.Key, err) } // only enum volumes, owner has read access to if sdkPolicy.IsPermitted(ctx, api.Ownership_Read) { policies = append(policies, sdkPolicy) } } return &api.SdkOpenStoragePolicyEnumerateResponse{ StoragePolicies: policies, }, nil }
[ "func", "(", "p", "*", "SdkPolicyManager", ")", "Enumerate", "(", "ctx", "context", ".", "Context", ",", "req", "*", "api", ".", "SdkOpenStoragePolicyEnumerateRequest", ",", ")", "(", "*", "api", ".", "SdkOpenStoragePolicyEnumerateResponse", ",", "error", ")", "{", "// get all keyValue pair at /storage/policy/policies", "kvp", ",", "err", ":=", "p", ".", "kv", ".", "Enumerate", "(", "policyPrefix", "+", "policyPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "status", ".", "Errorf", "(", "codes", ".", "Internal", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "policies", ":=", "make", "(", "[", "]", "*", "api", ".", "SdkStoragePolicy", ",", "0", ")", "\n", "for", "_", ",", "policy", ":=", "range", "kvp", "{", "sdkPolicy", ":=", "&", "api", ".", "SdkStoragePolicy", "{", "}", "\n", "err", "=", "jsonpb", ".", "UnmarshalString", "(", "string", "(", "policy", ".", "Value", ")", ",", "sdkPolicy", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "status", ".", "Errorf", "(", "codes", ".", "Internal", ",", "\"", "\"", ",", "policy", ".", "Key", ",", "err", ")", "\n", "}", "\n", "// only enum volumes, owner has read access to", "if", "sdkPolicy", ".", "IsPermitted", "(", "ctx", ",", "api", ".", "Ownership_Read", ")", "{", "policies", "=", "append", "(", "policies", ",", "sdkPolicy", ")", "\n", "}", "\n", "}", "\n\n", "return", "&", "api", ".", "SdkOpenStoragePolicyEnumerateResponse", "{", "StoragePolicies", ":", "policies", ",", "}", ",", "nil", "\n", "}" ]
// Enumerate all of storage policies
[ "Enumerate", "all", "of", "storage", "policies" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/storagepolicy/sdkstoragepolicy.go#L267-L293
train
libopenstorage/openstorage
pkg/storagepolicy/sdkstoragepolicy.go
SetDefault
func (p *SdkPolicyManager) SetDefault( ctx context.Context, req *api.SdkOpenStoragePolicySetDefaultRequest, ) (*api.SdkOpenStoragePolicySetDefaultResponse, error) { if req.GetName() == "" { return nil, status.Error(codes.InvalidArgument, "Must supply a Storage Policy Name") } // verify policy exists, before setting it as default policy, err := p.Inspect(ctx, &api.SdkOpenStoragePolicyInspectRequest{ Name: req.GetName(), }, ) if err != nil { return nil, err } // Only administrator can set policy as default storage // policy restriction user, _ := auth.NewUserInfoFromContext(ctx) if !policy.GetStoragePolicy().GetOwnership().IsAdminByUser(user) { return nil, status.Errorf(codes.PermissionDenied, "Only the storage system admin can set storage policy as default %v", req.GetName()) } policyStr, err := json.Marshal(policy.GetStoragePolicy().GetName()) if err != nil { return nil, status.Errorf(codes.Internal, "Json marshal failed for policy %s :%v", req.GetName(), err) } _, err = p.kv.Update(defaultPath, policyStr, 0) if err == kvdb.ErrNotFound { if _, err := p.kv.Create(defaultPath, policyStr, 0); err != nil { return nil, status.Errorf(codes.Internal, "Unable to save default policy details %v", err) } } else if err != nil { return nil, status.Errorf(codes.Internal, "Failed to set default policy: %v", err) } logrus.Infof("Storage Policy %v is set as default", policy.GetStoragePolicy().GetName()) return &api.SdkOpenStoragePolicySetDefaultResponse{}, nil }
go
func (p *SdkPolicyManager) SetDefault( ctx context.Context, req *api.SdkOpenStoragePolicySetDefaultRequest, ) (*api.SdkOpenStoragePolicySetDefaultResponse, error) { if req.GetName() == "" { return nil, status.Error(codes.InvalidArgument, "Must supply a Storage Policy Name") } // verify policy exists, before setting it as default policy, err := p.Inspect(ctx, &api.SdkOpenStoragePolicyInspectRequest{ Name: req.GetName(), }, ) if err != nil { return nil, err } // Only administrator can set policy as default storage // policy restriction user, _ := auth.NewUserInfoFromContext(ctx) if !policy.GetStoragePolicy().GetOwnership().IsAdminByUser(user) { return nil, status.Errorf(codes.PermissionDenied, "Only the storage system admin can set storage policy as default %v", req.GetName()) } policyStr, err := json.Marshal(policy.GetStoragePolicy().GetName()) if err != nil { return nil, status.Errorf(codes.Internal, "Json marshal failed for policy %s :%v", req.GetName(), err) } _, err = p.kv.Update(defaultPath, policyStr, 0) if err == kvdb.ErrNotFound { if _, err := p.kv.Create(defaultPath, policyStr, 0); err != nil { return nil, status.Errorf(codes.Internal, "Unable to save default policy details %v", err) } } else if err != nil { return nil, status.Errorf(codes.Internal, "Failed to set default policy: %v", err) } logrus.Infof("Storage Policy %v is set as default", policy.GetStoragePolicy().GetName()) return &api.SdkOpenStoragePolicySetDefaultResponse{}, nil }
[ "func", "(", "p", "*", "SdkPolicyManager", ")", "SetDefault", "(", "ctx", "context", ".", "Context", ",", "req", "*", "api", ".", "SdkOpenStoragePolicySetDefaultRequest", ",", ")", "(", "*", "api", ".", "SdkOpenStoragePolicySetDefaultResponse", ",", "error", ")", "{", "if", "req", ".", "GetName", "(", ")", "==", "\"", "\"", "{", "return", "nil", ",", "status", ".", "Error", "(", "codes", ".", "InvalidArgument", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// verify policy exists, before setting it as default", "policy", ",", "err", ":=", "p", ".", "Inspect", "(", "ctx", ",", "&", "api", ".", "SdkOpenStoragePolicyInspectRequest", "{", "Name", ":", "req", ".", "GetName", "(", ")", ",", "}", ",", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// Only administrator can set policy as default storage", "// policy restriction", "user", ",", "_", ":=", "auth", ".", "NewUserInfoFromContext", "(", "ctx", ")", "\n", "if", "!", "policy", ".", "GetStoragePolicy", "(", ")", ".", "GetOwnership", "(", ")", ".", "IsAdminByUser", "(", "user", ")", "{", "return", "nil", ",", "status", ".", "Errorf", "(", "codes", ".", "PermissionDenied", ",", "\"", "\"", ",", "req", ".", "GetName", "(", ")", ")", "\n", "}", "\n\n", "policyStr", ",", "err", ":=", "json", ".", "Marshal", "(", "policy", ".", "GetStoragePolicy", "(", ")", ".", "GetName", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "status", ".", "Errorf", "(", "codes", ".", "Internal", ",", "\"", "\"", ",", "req", ".", "GetName", "(", ")", ",", "err", ")", "\n", "}", "\n\n", "_", ",", "err", "=", "p", ".", "kv", ".", "Update", "(", "defaultPath", ",", "policyStr", ",", "0", ")", "\n", "if", "err", "==", "kvdb", ".", "ErrNotFound", "{", "if", "_", ",", "err", ":=", "p", ".", "kv", ".", "Create", "(", "defaultPath", ",", "policyStr", ",", "0", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "status", ".", "Errorf", "(", "codes", ".", "Internal", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "}", "else", "if", "err", "!=", "nil", "{", "return", "nil", ",", "status", ".", "Errorf", "(", "codes", ".", "Internal", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "logrus", ".", "Infof", "(", "\"", "\"", ",", "policy", ".", "GetStoragePolicy", "(", ")", ".", "GetName", "(", ")", ")", "\n", "return", "&", "api", ".", "SdkOpenStoragePolicySetDefaultResponse", "{", "}", ",", "nil", "\n", "}" ]
// SetDefault storage policy
[ "SetDefault", "storage", "policy" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/storagepolicy/sdkstoragepolicy.go#L296-L336
train
libopenstorage/openstorage
pkg/storagepolicy/sdkstoragepolicy.go
Release
func (p *SdkPolicyManager) Release( ctx context.Context, req *api.SdkOpenStoragePolicyReleaseRequest, ) (*api.SdkOpenStoragePolicyReleaseResponse, error) { policy, err := p.DefaultInspect(ctx, &api.SdkOpenStoragePolicyDefaultInspectRequest{}) if err != nil { return nil, err } // only administrator can remove storage policy restriction user, _ := auth.NewUserInfoFromContext(ctx) if !policy.GetStoragePolicy().GetOwnership().IsAdminByUser(user) { return nil, status.Errorf(codes.PermissionDenied, "Only the storage system admin can remove storage policy restriction") } // empty represents no policy is set as default strB, _ := json.Marshal("") _, err = p.kv.Update(defaultPath, strB, 0) if err != kvdb.ErrNotFound && err != nil { return nil, status.Errorf(codes.Internal, "Remove storage policy restriction failed with: %v", err) } logrus.Infof("Storage Policy %v restriction is removed", policy.GetStoragePolicy().GetName()) return &api.SdkOpenStoragePolicyReleaseResponse{}, nil }
go
func (p *SdkPolicyManager) Release( ctx context.Context, req *api.SdkOpenStoragePolicyReleaseRequest, ) (*api.SdkOpenStoragePolicyReleaseResponse, error) { policy, err := p.DefaultInspect(ctx, &api.SdkOpenStoragePolicyDefaultInspectRequest{}) if err != nil { return nil, err } // only administrator can remove storage policy restriction user, _ := auth.NewUserInfoFromContext(ctx) if !policy.GetStoragePolicy().GetOwnership().IsAdminByUser(user) { return nil, status.Errorf(codes.PermissionDenied, "Only the storage system admin can remove storage policy restriction") } // empty represents no policy is set as default strB, _ := json.Marshal("") _, err = p.kv.Update(defaultPath, strB, 0) if err != kvdb.ErrNotFound && err != nil { return nil, status.Errorf(codes.Internal, "Remove storage policy restriction failed with: %v", err) } logrus.Infof("Storage Policy %v restriction is removed", policy.GetStoragePolicy().GetName()) return &api.SdkOpenStoragePolicyReleaseResponse{}, nil }
[ "func", "(", "p", "*", "SdkPolicyManager", ")", "Release", "(", "ctx", "context", ".", "Context", ",", "req", "*", "api", ".", "SdkOpenStoragePolicyReleaseRequest", ",", ")", "(", "*", "api", ".", "SdkOpenStoragePolicyReleaseResponse", ",", "error", ")", "{", "policy", ",", "err", ":=", "p", ".", "DefaultInspect", "(", "ctx", ",", "&", "api", ".", "SdkOpenStoragePolicyDefaultInspectRequest", "{", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// only administrator can remove storage policy restriction", "user", ",", "_", ":=", "auth", ".", "NewUserInfoFromContext", "(", "ctx", ")", "\n", "if", "!", "policy", ".", "GetStoragePolicy", "(", ")", ".", "GetOwnership", "(", ")", ".", "IsAdminByUser", "(", "user", ")", "{", "return", "nil", ",", "status", ".", "Errorf", "(", "codes", ".", "PermissionDenied", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// empty represents no policy is set as default", "strB", ",", "_", ":=", "json", ".", "Marshal", "(", "\"", "\"", ")", "\n", "_", ",", "err", "=", "p", ".", "kv", ".", "Update", "(", "defaultPath", ",", "strB", ",", "0", ")", "\n", "if", "err", "!=", "kvdb", ".", "ErrNotFound", "&&", "err", "!=", "nil", "{", "return", "nil", ",", "status", ".", "Errorf", "(", "codes", ".", "Internal", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "logrus", ".", "Infof", "(", "\"", "\"", ",", "policy", ".", "GetStoragePolicy", "(", ")", ".", "GetName", "(", ")", ")", "\n", "return", "&", "api", ".", "SdkOpenStoragePolicyReleaseResponse", "{", "}", ",", "nil", "\n", "}" ]
// Release storage policy if set as default
[ "Release", "storage", "policy", "if", "set", "as", "default" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/storagepolicy/sdkstoragepolicy.go#L339-L364
train
libopenstorage/openstorage
pkg/storagepolicy/sdkstoragepolicy.go
DefaultInspect
func (p *SdkPolicyManager) DefaultInspect( ctx context.Context, req *api.SdkOpenStoragePolicyDefaultInspectRequest, ) (*api.SdkOpenStoragePolicyDefaultInspectResponse, error) { var policyName string defaultPolicy := &api.SdkOpenStoragePolicyDefaultInspectResponse{} _, err := p.kv.GetVal(defaultPath, &policyName) // defaultPath key is not created if err == kvdb.ErrNotFound { return defaultPolicy, nil } else if err != nil { return nil, status.Errorf(codes.Internal, "Unable to retrive default policy details: %v", err) } // no default policy found if policyName == "" { return defaultPolicy, nil } // retrive default storage policy details inspResp, err := p.Inspect(context.Background(), &api.SdkOpenStoragePolicyInspectRequest{ Name: policyName, }, ) if err != nil { return nil, err } return &api.SdkOpenStoragePolicyDefaultInspectResponse{ StoragePolicy: inspResp.GetStoragePolicy(), }, nil }
go
func (p *SdkPolicyManager) DefaultInspect( ctx context.Context, req *api.SdkOpenStoragePolicyDefaultInspectRequest, ) (*api.SdkOpenStoragePolicyDefaultInspectResponse, error) { var policyName string defaultPolicy := &api.SdkOpenStoragePolicyDefaultInspectResponse{} _, err := p.kv.GetVal(defaultPath, &policyName) // defaultPath key is not created if err == kvdb.ErrNotFound { return defaultPolicy, nil } else if err != nil { return nil, status.Errorf(codes.Internal, "Unable to retrive default policy details: %v", err) } // no default policy found if policyName == "" { return defaultPolicy, nil } // retrive default storage policy details inspResp, err := p.Inspect(context.Background(), &api.SdkOpenStoragePolicyInspectRequest{ Name: policyName, }, ) if err != nil { return nil, err } return &api.SdkOpenStoragePolicyDefaultInspectResponse{ StoragePolicy: inspResp.GetStoragePolicy(), }, nil }
[ "func", "(", "p", "*", "SdkPolicyManager", ")", "DefaultInspect", "(", "ctx", "context", ".", "Context", ",", "req", "*", "api", ".", "SdkOpenStoragePolicyDefaultInspectRequest", ",", ")", "(", "*", "api", ".", "SdkOpenStoragePolicyDefaultInspectResponse", ",", "error", ")", "{", "var", "policyName", "string", "\n", "defaultPolicy", ":=", "&", "api", ".", "SdkOpenStoragePolicyDefaultInspectResponse", "{", "}", "\n\n", "_", ",", "err", ":=", "p", ".", "kv", ".", "GetVal", "(", "defaultPath", ",", "&", "policyName", ")", "\n", "// defaultPath key is not created", "if", "err", "==", "kvdb", ".", "ErrNotFound", "{", "return", "defaultPolicy", ",", "nil", "\n", "}", "else", "if", "err", "!=", "nil", "{", "return", "nil", ",", "status", ".", "Errorf", "(", "codes", ".", "Internal", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// no default policy found", "if", "policyName", "==", "\"", "\"", "{", "return", "defaultPolicy", ",", "nil", "\n", "}", "\n\n", "// retrive default storage policy details", "inspResp", ",", "err", ":=", "p", ".", "Inspect", "(", "context", ".", "Background", "(", ")", ",", "&", "api", ".", "SdkOpenStoragePolicyInspectRequest", "{", "Name", ":", "policyName", ",", "}", ",", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "api", ".", "SdkOpenStoragePolicyDefaultInspectResponse", "{", "StoragePolicy", ":", "inspResp", ".", "GetStoragePolicy", "(", ")", ",", "}", ",", "nil", "\n", "}" ]
// DefaultInspect return default storeage policy details
[ "DefaultInspect", "return", "default", "storeage", "policy", "details" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/storagepolicy/sdkstoragepolicy.go#L367-L400
train
libopenstorage/openstorage
api/server/sdk/cluster_pair.go
Create
func (s *ClusterPairServer) Create( ctx context.Context, req *api.SdkClusterPairCreateRequest, ) (*api.SdkClusterPairCreateResponse, error) { if s.cluster() == 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") } resp, err := s.cluster().CreatePair(req.GetRequest()) if err != nil { return nil, status.Errorf(codes.Internal, "Cannot create cluster with remote pair %s : %v", req.GetRequest().GetRemoteClusterIp(), err) } return &api.SdkClusterPairCreateResponse{ Result: resp, }, nil }
go
func (s *ClusterPairServer) Create( ctx context.Context, req *api.SdkClusterPairCreateRequest, ) (*api.SdkClusterPairCreateResponse, error) { if s.cluster() == 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") } resp, err := s.cluster().CreatePair(req.GetRequest()) if err != nil { return nil, status.Errorf(codes.Internal, "Cannot create cluster with remote pair %s : %v", req.GetRequest().GetRemoteClusterIp(), err) } return &api.SdkClusterPairCreateResponse{ Result: resp, }, nil }
[ "func", "(", "s", "*", "ClusterPairServer", ")", "Create", "(", "ctx", "context", ".", "Context", ",", "req", "*", "api", ".", "SdkClusterPairCreateRequest", ",", ")", "(", "*", "api", ".", "SdkClusterPairCreateResponse", ",", "error", ")", "{", "if", "s", ".", "cluster", "(", ")", "==", "nil", "{", "return", "nil", ",", "status", ".", "Error", "(", "codes", ".", "Unavailable", ",", "\"", "\"", ")", "\n", "}", "\n\n", "if", "req", ".", "GetRequest", "(", ")", "==", "nil", "{", "return", "nil", ",", "status", ".", "Errorf", "(", "codes", ".", "InvalidArgument", ",", "\"", "\"", ")", "\n", "}", "\n\n", "resp", ",", "err", ":=", "s", ".", "cluster", "(", ")", ".", "CreatePair", "(", "req", ".", "GetRequest", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "status", ".", "Errorf", "(", "codes", ".", "Internal", ",", "\"", "\"", ",", "req", ".", "GetRequest", "(", ")", ".", "GetRemoteClusterIp", "(", ")", ",", "err", ")", "\n", "}", "\n\n", "return", "&", "api", ".", "SdkClusterPairCreateResponse", "{", "Result", ":", "resp", ",", "}", ",", "nil", "\n", "}" ]
// Create a new cluster with remote pair
[ "Create", "a", "new", "cluster", "with", "remote", "pair" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/cluster_pair.go#L39-L60
train
libopenstorage/openstorage
api/server/sdk/cluster_pair.go
Inspect
func (s *ClusterPairServer) Inspect( ctx context.Context, req *api.SdkClusterPairInspectRequest, ) (*api.SdkClusterPairInspectResponse, error) { if s.cluster() == nil { return nil, status.Error(codes.Unavailable, "Resource has not been initialized") } if len(req.GetId()) == 0 { return nil, status.Error(codes.InvalidArgument, "Must supply cluster ID") } resp, err := s.cluster().GetPair(req.GetId()) if err != nil { return nil, status.Errorf(codes.Internal, "Cannot Get cluster information for %s : %v", req.GetId(), err) } return &api.SdkClusterPairInspectResponse{ Result: resp, }, nil }
go
func (s *ClusterPairServer) Inspect( ctx context.Context, req *api.SdkClusterPairInspectRequest, ) (*api.SdkClusterPairInspectResponse, error) { if s.cluster() == nil { return nil, status.Error(codes.Unavailable, "Resource has not been initialized") } if len(req.GetId()) == 0 { return nil, status.Error(codes.InvalidArgument, "Must supply cluster ID") } resp, err := s.cluster().GetPair(req.GetId()) if err != nil { return nil, status.Errorf(codes.Internal, "Cannot Get cluster information for %s : %v", req.GetId(), err) } return &api.SdkClusterPairInspectResponse{ Result: resp, }, nil }
[ "func", "(", "s", "*", "ClusterPairServer", ")", "Inspect", "(", "ctx", "context", ".", "Context", ",", "req", "*", "api", ".", "SdkClusterPairInspectRequest", ",", ")", "(", "*", "api", ".", "SdkClusterPairInspectResponse", ",", "error", ")", "{", "if", "s", ".", "cluster", "(", ")", "==", "nil", "{", "return", "nil", ",", "status", ".", "Error", "(", "codes", ".", "Unavailable", ",", "\"", "\"", ")", "\n", "}", "\n\n", "if", "len", "(", "req", ".", "GetId", "(", ")", ")", "==", "0", "{", "return", "nil", ",", "status", ".", "Error", "(", "codes", ".", "InvalidArgument", ",", "\"", "\"", ")", "\n", "}", "\n", "resp", ",", "err", ":=", "s", ".", "cluster", "(", ")", ".", "GetPair", "(", "req", ".", "GetId", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "status", ".", "Errorf", "(", "codes", ".", "Internal", ",", "\"", "\"", ",", "req", ".", "GetId", "(", ")", ",", "err", ")", "\n", "}", "\n", "return", "&", "api", ".", "SdkClusterPairInspectResponse", "{", "Result", ":", "resp", ",", "}", ",", "nil", "\n", "}" ]
// Inspect information about a cluster pair
[ "Inspect", "information", "about", "a", "cluster", "pair" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/cluster_pair.go#L63-L81
train
libopenstorage/openstorage
api/server/sdk/cluster_pair.go
Enumerate
func (s *ClusterPairServer) Enumerate( ctx context.Context, req *api.SdkClusterPairEnumerateRequest, ) (*api.SdkClusterPairEnumerateResponse, error) { if s.cluster() == nil { return nil, status.Error(codes.Unavailable, "Resource has not been initialized") } resp, err := s.cluster().EnumeratePairs() if err != nil { return nil, status.Errorf(codes.Internal, "Cannot list cluster pairs : %v", err) } return &api.SdkClusterPairEnumerateResponse{ Result: resp, }, nil }
go
func (s *ClusterPairServer) Enumerate( ctx context.Context, req *api.SdkClusterPairEnumerateRequest, ) (*api.SdkClusterPairEnumerateResponse, error) { if s.cluster() == nil { return nil, status.Error(codes.Unavailable, "Resource has not been initialized") } resp, err := s.cluster().EnumeratePairs() if err != nil { return nil, status.Errorf(codes.Internal, "Cannot list cluster pairs : %v", err) } return &api.SdkClusterPairEnumerateResponse{ Result: resp, }, nil }
[ "func", "(", "s", "*", "ClusterPairServer", ")", "Enumerate", "(", "ctx", "context", ".", "Context", ",", "req", "*", "api", ".", "SdkClusterPairEnumerateRequest", ",", ")", "(", "*", "api", ".", "SdkClusterPairEnumerateResponse", ",", "error", ")", "{", "if", "s", ".", "cluster", "(", ")", "==", "nil", "{", "return", "nil", ",", "status", ".", "Error", "(", "codes", ".", "Unavailable", ",", "\"", "\"", ")", "\n", "}", "\n\n", "resp", ",", "err", ":=", "s", ".", "cluster", "(", ")", ".", "EnumeratePairs", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "status", ".", "Errorf", "(", "codes", ".", "Internal", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "&", "api", ".", "SdkClusterPairEnumerateResponse", "{", "Result", ":", "resp", ",", "}", ",", "nil", "\n", "}" ]
// Enumerate returns list of cluster pairs
[ "Enumerate", "returns", "list", "of", "cluster", "pairs" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/cluster_pair.go#L84-L99
train
libopenstorage/openstorage
api/server/sdk/cluster_pair.go
GetToken
func (s *ClusterPairServer) GetToken( ctx context.Context, req *api.SdkClusterPairGetTokenRequest, ) (*api.SdkClusterPairGetTokenResponse, error) { if s.cluster() == nil { return nil, status.Error(codes.Unavailable, "Resource has not been initialized") } // Check if admin user - only system.admin can get cluster pair tokens if userInfo, ok := auth.NewUserInfoFromContext(ctx); ok { o := api.Ownership{} if !o.IsAdminByUser(userInfo) { return nil, status.Error(codes.Unauthenticated, "Must be system admin to get pair token") } } resp, err := s.cluster().GetPairToken(false) if err != nil { return nil, status.Errorf(codes.Internal, "Cannot generate token: %v", err) } return &api.SdkClusterPairGetTokenResponse{ Result: resp, }, nil }
go
func (s *ClusterPairServer) GetToken( ctx context.Context, req *api.SdkClusterPairGetTokenRequest, ) (*api.SdkClusterPairGetTokenResponse, error) { if s.cluster() == nil { return nil, status.Error(codes.Unavailable, "Resource has not been initialized") } // Check if admin user - only system.admin can get cluster pair tokens if userInfo, ok := auth.NewUserInfoFromContext(ctx); ok { o := api.Ownership{} if !o.IsAdminByUser(userInfo) { return nil, status.Error(codes.Unauthenticated, "Must be system admin to get pair token") } } resp, err := s.cluster().GetPairToken(false) if err != nil { return nil, status.Errorf(codes.Internal, "Cannot generate token: %v", err) } return &api.SdkClusterPairGetTokenResponse{ Result: resp, }, nil }
[ "func", "(", "s", "*", "ClusterPairServer", ")", "GetToken", "(", "ctx", "context", ".", "Context", ",", "req", "*", "api", ".", "SdkClusterPairGetTokenRequest", ",", ")", "(", "*", "api", ".", "SdkClusterPairGetTokenResponse", ",", "error", ")", "{", "if", "s", ".", "cluster", "(", ")", "==", "nil", "{", "return", "nil", ",", "status", ".", "Error", "(", "codes", ".", "Unavailable", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// Check if admin user - only system.admin can get cluster pair tokens", "if", "userInfo", ",", "ok", ":=", "auth", ".", "NewUserInfoFromContext", "(", "ctx", ")", ";", "ok", "{", "o", ":=", "api", ".", "Ownership", "{", "}", "\n", "if", "!", "o", ".", "IsAdminByUser", "(", "userInfo", ")", "{", "return", "nil", ",", "status", ".", "Error", "(", "codes", ".", "Unauthenticated", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n\n", "resp", ",", "err", ":=", "s", ".", "cluster", "(", ")", ".", "GetPairToken", "(", "false", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "status", ".", "Errorf", "(", "codes", ".", "Internal", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "&", "api", ".", "SdkClusterPairGetTokenResponse", "{", "Result", ":", "resp", ",", "}", ",", "nil", "\n", "}" ]
// GetToken gets the authentication token for this cluster
[ "GetToken", "gets", "the", "authentication", "token", "for", "this", "cluster" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/cluster_pair.go#L102-L125
train
libopenstorage/openstorage
api/server/sdk/cluster_pair.go
ResetToken
func (s *ClusterPairServer) ResetToken( ctx context.Context, req *api.SdkClusterPairResetTokenRequest, ) (*api.SdkClusterPairResetTokenResponse, error) { if s.cluster() == nil { return nil, status.Error(codes.Unavailable, "Resource has not been initialized") } resp, err := s.cluster().GetPairToken(true) if err != nil { return nil, status.Errorf(codes.Internal, "Cannot generate token: %v", err) } return &api.SdkClusterPairResetTokenResponse{ Result: resp, }, nil }
go
func (s *ClusterPairServer) ResetToken( ctx context.Context, req *api.SdkClusterPairResetTokenRequest, ) (*api.SdkClusterPairResetTokenResponse, error) { if s.cluster() == nil { return nil, status.Error(codes.Unavailable, "Resource has not been initialized") } resp, err := s.cluster().GetPairToken(true) if err != nil { return nil, status.Errorf(codes.Internal, "Cannot generate token: %v", err) } return &api.SdkClusterPairResetTokenResponse{ Result: resp, }, nil }
[ "func", "(", "s", "*", "ClusterPairServer", ")", "ResetToken", "(", "ctx", "context", ".", "Context", ",", "req", "*", "api", ".", "SdkClusterPairResetTokenRequest", ",", ")", "(", "*", "api", ".", "SdkClusterPairResetTokenResponse", ",", "error", ")", "{", "if", "s", ".", "cluster", "(", ")", "==", "nil", "{", "return", "nil", ",", "status", ".", "Error", "(", "codes", ".", "Unavailable", ",", "\"", "\"", ")", "\n", "}", "\n\n", "resp", ",", "err", ":=", "s", ".", "cluster", "(", ")", ".", "GetPairToken", "(", "true", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "status", ".", "Errorf", "(", "codes", ".", "Internal", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "&", "api", ".", "SdkClusterPairResetTokenResponse", "{", "Result", ":", "resp", ",", "}", ",", "nil", "\n", "}" ]
// ResetToken gets the authentication token for this cluster
[ "ResetToken", "gets", "the", "authentication", "token", "for", "this", "cluster" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/cluster_pair.go#L128-L143
train
libopenstorage/openstorage
api/server/sdk/cluster_pair.go
Delete
func (s *ClusterPairServer) Delete( ctx context.Context, req *api.SdkClusterPairDeleteRequest, ) (*api.SdkClusterPairDeleteResponse, error) { if s.cluster() == nil { return nil, status.Error(codes.Unavailable, "Resource has not been initialized") } if len(req.GetClusterId()) == 0 { return nil, status.Error(codes.InvalidArgument, "Must supply valid cluster ID") } err := s.cluster().DeletePair(req.GetClusterId()) if err != nil { return nil, status.Errorf(codes.Internal, "Cannot delete the cluster pair %s : %v", req.GetClusterId(), err) } return &api.SdkClusterPairDeleteResponse{}, nil }
go
func (s *ClusterPairServer) Delete( ctx context.Context, req *api.SdkClusterPairDeleteRequest, ) (*api.SdkClusterPairDeleteResponse, error) { if s.cluster() == nil { return nil, status.Error(codes.Unavailable, "Resource has not been initialized") } if len(req.GetClusterId()) == 0 { return nil, status.Error(codes.InvalidArgument, "Must supply valid cluster ID") } err := s.cluster().DeletePair(req.GetClusterId()) if err != nil { return nil, status.Errorf(codes.Internal, "Cannot delete the cluster pair %s : %v", req.GetClusterId(), err) } return &api.SdkClusterPairDeleteResponse{}, nil }
[ "func", "(", "s", "*", "ClusterPairServer", ")", "Delete", "(", "ctx", "context", ".", "Context", ",", "req", "*", "api", ".", "SdkClusterPairDeleteRequest", ",", ")", "(", "*", "api", ".", "SdkClusterPairDeleteResponse", ",", "error", ")", "{", "if", "s", ".", "cluster", "(", ")", "==", "nil", "{", "return", "nil", ",", "status", ".", "Error", "(", "codes", ".", "Unavailable", ",", "\"", "\"", ")", "\n", "}", "\n\n", "if", "len", "(", "req", ".", "GetClusterId", "(", ")", ")", "==", "0", "{", "return", "nil", ",", "status", ".", "Error", "(", "codes", ".", "InvalidArgument", ",", "\"", "\"", ")", "\n", "}", "\n", "err", ":=", "s", ".", "cluster", "(", ")", ".", "DeletePair", "(", "req", ".", "GetClusterId", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "status", ".", "Errorf", "(", "codes", ".", "Internal", ",", "\"", "\"", ",", "req", ".", "GetClusterId", "(", ")", ",", "err", ")", "\n", "}", "\n", "return", "&", "api", ".", "SdkClusterPairDeleteResponse", "{", "}", ",", "nil", "\n", "}" ]
// Delete removes the cluster pairing
[ "Delete", "removes", "the", "cluster", "pairing" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/cluster_pair.go#L146-L162
train
libopenstorage/openstorage
cluster/cluster_not_supported.go
Inspect
func (m *NullClusterManager) Inspect(arg0 string) (api.Node, error) { return api.Node{}, ErrNotImplemented }
go
func (m *NullClusterManager) Inspect(arg0 string) (api.Node, error) { return api.Node{}, ErrNotImplemented }
[ "func", "(", "m", "*", "NullClusterManager", ")", "Inspect", "(", "arg0", "string", ")", "(", "api", ".", "Node", ",", "error", ")", "{", "return", "api", ".", "Node", "{", "}", ",", "ErrNotImplemented", "\n", "}" ]
// NullClusterManager implementations // Inspect
[ "NullClusterManager", "implementations", "Inspect" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/cluster/cluster_not_supported.go#L78-L80
train
libopenstorage/openstorage
cluster/cluster_not_supported.go
Remove
func (m *NullClusterRemove) Remove(arg0 []api.Node, arg1 bool) error { return ErrNotImplemented }
go
func (m *NullClusterRemove) Remove(arg0 []api.Node, arg1 bool) error { return ErrNotImplemented }
[ "func", "(", "m", "*", "NullClusterRemove", ")", "Remove", "(", "arg0", "[", "]", "api", ".", "Node", ",", "arg1", "bool", ")", "error", "{", "return", "ErrNotImplemented", "\n", "}" ]
// NullClusterRemove implementations // Remove
[ "NullClusterRemove", "implementations", "Remove" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/cluster/cluster_not_supported.go#L169-L171
train
libopenstorage/openstorage
cluster/cluster_not_supported.go
EnumerateAlerts
func (m *NullClusterAlerts) EnumerateAlerts(arg0, arg1 time.Time, arg2 api.ResourceType) (*api.Alerts, error) { return nil, ErrNotImplemented }
go
func (m *NullClusterAlerts) EnumerateAlerts(arg0, arg1 time.Time, arg2 api.ResourceType) (*api.Alerts, error) { return nil, ErrNotImplemented }
[ "func", "(", "m", "*", "NullClusterAlerts", ")", "EnumerateAlerts", "(", "arg0", ",", "arg1", "time", ".", "Time", ",", "arg2", "api", ".", "ResourceType", ")", "(", "*", "api", ".", "Alerts", ",", "error", ")", "{", "return", "nil", ",", "ErrNotImplemented", "\n", "}" ]
// NullClusterAlerts implementations // EnumerateAlerts
[ "NullClusterAlerts", "implementations", "EnumerateAlerts" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/cluster/cluster_not_supported.go#L193-L195
train
libopenstorage/openstorage
cluster/cluster_not_supported.go
CreatePair
func (m *NullClusterPair) CreatePair(arg0 *api.ClusterPairCreateRequest) (*api.ClusterPairCreateResponse, error) { return nil, ErrNotImplemented }
go
func (m *NullClusterPair) CreatePair(arg0 *api.ClusterPairCreateRequest) (*api.ClusterPairCreateResponse, error) { return nil, ErrNotImplemented }
[ "func", "(", "m", "*", "NullClusterPair", ")", "CreatePair", "(", "arg0", "*", "api", ".", "ClusterPairCreateRequest", ")", "(", "*", "api", ".", "ClusterPairCreateResponse", ",", "error", ")", "{", "return", "nil", ",", "ErrNotImplemented", "\n", "}" ]
// NullClusterPair implementations // CreatePair
[ "NullClusterPair", "implementations", "CreatePair" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/cluster/cluster_not_supported.go#L205-L207
train
libopenstorage/openstorage
csi/controller.go
ControllerExpandVolume
func (s *OsdCsiServer) ControllerExpandVolume( ctx context.Context, req *csi.ControllerExpandVolumeRequest, ) (*csi.ControllerExpandVolumeResponse, error) { if len(req.GetVolumeId()) == 0 { return nil, status.Error(codes.InvalidArgument, "Volume id must be provided") } else if req.GetCapacityRange() == nil { return nil, status.Error(codes.InvalidArgument, "Capacity range must be provided") } else if req.GetCapacityRange().GetRequiredBytes() < 0 || req.GetCapacityRange().GetLimitBytes() < 0 { return nil, status.Error(codes.InvalidArgument, "Capacity ranges values cannot be negative") } // Get Size spec := &api.VolumeSpecUpdate{} newSize := uint64(req.GetCapacityRange().GetRequiredBytes()) spec.SizeOpt = &api.VolumeSpecUpdate_Size{ Size: newSize, } // Get grpc connection conn, err := s.getConn() if err != nil { return nil, status.Errorf( codes.Internal, "Unable to connect to SDK server: %v", err) } // Get secret if any was passed ctx = s.setupContextWithToken(ctx, req.GetSecrets()) // If the new size is greater than the current size, a volume update // should be issued. Otherwise, no operation should occur. volumes := api.NewOpenStorageVolumeClient(conn) // Update volume with new size _, err = volumes.Update(ctx, &api.SdkVolumeUpdateRequest{ VolumeId: req.GetVolumeId(), Spec: spec, }) if err != nil { if err == kvdb.ErrNotFound { return nil, status.Errorf(codes.NotFound, "Volume id %s not found", req.GetVolumeId()) } return nil, status.Errorf(codes.Internal, "Failed to update volume size: %v", err) } return &csi.ControllerExpandVolumeResponse{ CapacityBytes: int64(newSize), NodeExpansionRequired: false, }, nil }
go
func (s *OsdCsiServer) ControllerExpandVolume( ctx context.Context, req *csi.ControllerExpandVolumeRequest, ) (*csi.ControllerExpandVolumeResponse, error) { if len(req.GetVolumeId()) == 0 { return nil, status.Error(codes.InvalidArgument, "Volume id must be provided") } else if req.GetCapacityRange() == nil { return nil, status.Error(codes.InvalidArgument, "Capacity range must be provided") } else if req.GetCapacityRange().GetRequiredBytes() < 0 || req.GetCapacityRange().GetLimitBytes() < 0 { return nil, status.Error(codes.InvalidArgument, "Capacity ranges values cannot be negative") } // Get Size spec := &api.VolumeSpecUpdate{} newSize := uint64(req.GetCapacityRange().GetRequiredBytes()) spec.SizeOpt = &api.VolumeSpecUpdate_Size{ Size: newSize, } // Get grpc connection conn, err := s.getConn() if err != nil { return nil, status.Errorf( codes.Internal, "Unable to connect to SDK server: %v", err) } // Get secret if any was passed ctx = s.setupContextWithToken(ctx, req.GetSecrets()) // If the new size is greater than the current size, a volume update // should be issued. Otherwise, no operation should occur. volumes := api.NewOpenStorageVolumeClient(conn) // Update volume with new size _, err = volumes.Update(ctx, &api.SdkVolumeUpdateRequest{ VolumeId: req.GetVolumeId(), Spec: spec, }) if err != nil { if err == kvdb.ErrNotFound { return nil, status.Errorf(codes.NotFound, "Volume id %s not found", req.GetVolumeId()) } return nil, status.Errorf(codes.Internal, "Failed to update volume size: %v", err) } return &csi.ControllerExpandVolumeResponse{ CapacityBytes: int64(newSize), NodeExpansionRequired: false, }, nil }
[ "func", "(", "s", "*", "OsdCsiServer", ")", "ControllerExpandVolume", "(", "ctx", "context", ".", "Context", ",", "req", "*", "csi", ".", "ControllerExpandVolumeRequest", ",", ")", "(", "*", "csi", ".", "ControllerExpandVolumeResponse", ",", "error", ")", "{", "if", "len", "(", "req", ".", "GetVolumeId", "(", ")", ")", "==", "0", "{", "return", "nil", ",", "status", ".", "Error", "(", "codes", ".", "InvalidArgument", ",", "\"", "\"", ")", "\n", "}", "else", "if", "req", ".", "GetCapacityRange", "(", ")", "==", "nil", "{", "return", "nil", ",", "status", ".", "Error", "(", "codes", ".", "InvalidArgument", ",", "\"", "\"", ")", "\n", "}", "else", "if", "req", ".", "GetCapacityRange", "(", ")", ".", "GetRequiredBytes", "(", ")", "<", "0", "||", "req", ".", "GetCapacityRange", "(", ")", ".", "GetLimitBytes", "(", ")", "<", "0", "{", "return", "nil", ",", "status", ".", "Error", "(", "codes", ".", "InvalidArgument", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// Get Size", "spec", ":=", "&", "api", ".", "VolumeSpecUpdate", "{", "}", "\n", "newSize", ":=", "uint64", "(", "req", ".", "GetCapacityRange", "(", ")", ".", "GetRequiredBytes", "(", ")", ")", "\n", "spec", ".", "SizeOpt", "=", "&", "api", ".", "VolumeSpecUpdate_Size", "{", "Size", ":", "newSize", ",", "}", "\n\n", "// Get grpc connection", "conn", ",", "err", ":=", "s", ".", "getConn", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "status", ".", "Errorf", "(", "codes", ".", "Internal", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// Get secret if any was passed", "ctx", "=", "s", ".", "setupContextWithToken", "(", "ctx", ",", "req", ".", "GetSecrets", "(", ")", ")", "\n\n", "// If the new size is greater than the current size, a volume update", "// should be issued. Otherwise, no operation should occur.", "volumes", ":=", "api", ".", "NewOpenStorageVolumeClient", "(", "conn", ")", "\n\n", "// Update volume with new size", "_", ",", "err", "=", "volumes", ".", "Update", "(", "ctx", ",", "&", "api", ".", "SdkVolumeUpdateRequest", "{", "VolumeId", ":", "req", ".", "GetVolumeId", "(", ")", ",", "Spec", ":", "spec", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "==", "kvdb", ".", "ErrNotFound", "{", "return", "nil", ",", "status", ".", "Errorf", "(", "codes", ".", "NotFound", ",", "\"", "\"", ",", "req", ".", "GetVolumeId", "(", ")", ")", "\n", "}", "\n", "return", "nil", ",", "status", ".", "Errorf", "(", "codes", ".", "Internal", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "return", "&", "csi", ".", "ControllerExpandVolumeResponse", "{", "CapacityBytes", ":", "int64", "(", "newSize", ")", ",", "NodeExpansionRequired", ":", "false", ",", "}", ",", "nil", "\n", "}" ]
// ControllerExpandVolume is a CSI API which resizes a volume
[ "ControllerExpandVolume", "is", "a", "CSI", "API", "which", "resizes", "a", "volume" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/csi/controller.go#L396-L446
train
libopenstorage/openstorage
cli/drivers.go
DriverCommands
func DriverCommands() []cli.Command { commands := []cli.Command{ { Name: "add", Aliases: []string{"a"}, Usage: "add a new driver", Action: driverAdd, Flags: []cli.Flag{ cli.StringFlag{ Name: "name,n", Usage: "Driver Name", }, cli.StringFlag{ Name: "options,o", Usage: "Comma separated name=value pairs, e.g disk=/dev/xvdg,mount=/var/openstorage/btrfs", }, }, }, { Name: "list", Aliases: []string{"l"}, Usage: "List drivers", Action: driverList, }, } return commands }
go
func DriverCommands() []cli.Command { commands := []cli.Command{ { Name: "add", Aliases: []string{"a"}, Usage: "add a new driver", Action: driverAdd, Flags: []cli.Flag{ cli.StringFlag{ Name: "name,n", Usage: "Driver Name", }, cli.StringFlag{ Name: "options,o", Usage: "Comma separated name=value pairs, e.g disk=/dev/xvdg,mount=/var/openstorage/btrfs", }, }, }, { Name: "list", Aliases: []string{"l"}, Usage: "List drivers", Action: driverList, }, } return commands }
[ "func", "DriverCommands", "(", ")", "[", "]", "cli", ".", "Command", "{", "commands", ":=", "[", "]", "cli", ".", "Command", "{", "{", "Name", ":", "\"", "\"", ",", "Aliases", ":", "[", "]", "string", "{", "\"", "\"", "}", ",", "Usage", ":", "\"", "\"", ",", "Action", ":", "driverAdd", ",", "Flags", ":", "[", "]", "cli", ".", "Flag", "{", "cli", ".", "StringFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "}", ",", "cli", ".", "StringFlag", "{", "Name", ":", "\"", "\"", ",", "Usage", ":", "\"", "\"", ",", "}", ",", "}", ",", "}", ",", "{", "Name", ":", "\"", "\"", ",", "Aliases", ":", "[", "]", "string", "{", "\"", "\"", "}", ",", "Usage", ":", "\"", "\"", ",", "Action", ":", "driverList", ",", "}", ",", "}", "\n", "return", "commands", "\n", "}" ]
// DriverCommands exports the list of CLI driver subcommands.
[ "DriverCommands", "exports", "the", "list", "of", "CLI", "driver", "subcommands", "." ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/cli/drivers.go#L14-L40
train
libopenstorage/openstorage
volume/drivers/buse/buse.go
Init
func Init(params map[string]string) (volume.VolumeDriver, error) { nbdInit() inst := &driver{ IODriver: volume.IONotSupported, StoreEnumerator: common.NewDefaultStoreEnumerator(Name, kvdb.Instance()), StatsDriver: volume.StatsNotSupported, QuiesceDriver: volume.QuiesceNotSupported, CredsDriver: volume.CredsNotSupported, CloudBackupDriver: volume.CloudBackupNotSupported, CloudMigrateDriver: volume.CloudMigrateNotSupported, } inst.buseDevices = make(map[string]*buseDev) if err := os.MkdirAll(BuseMountPath, 0744); err != nil { return nil, err } volumeInfo, err := inst.StoreEnumerator.Enumerate( &api.VolumeLocator{}, nil, ) if err == nil { for _, info := range volumeInfo { if info.Status == api.VolumeStatus_VOLUME_STATUS_NONE { info.Status = api.VolumeStatus_VOLUME_STATUS_UP inst.UpdateVol(info) } } } else { logrus.Println("Could not enumerate Volumes, ", err) } inst.cl = &clusterListener{} c, err := clustermanager.Inst() if err != nil { logrus.Println("BUSE initializing in single node mode") } else { logrus.Println("BUSE initializing in clustered mode") c.AddEventListener(inst.cl) } logrus.Println("BUSE initialized and driver mounted at: ", BuseMountPath) return inst, nil }
go
func Init(params map[string]string) (volume.VolumeDriver, error) { nbdInit() inst := &driver{ IODriver: volume.IONotSupported, StoreEnumerator: common.NewDefaultStoreEnumerator(Name, kvdb.Instance()), StatsDriver: volume.StatsNotSupported, QuiesceDriver: volume.QuiesceNotSupported, CredsDriver: volume.CredsNotSupported, CloudBackupDriver: volume.CloudBackupNotSupported, CloudMigrateDriver: volume.CloudMigrateNotSupported, } inst.buseDevices = make(map[string]*buseDev) if err := os.MkdirAll(BuseMountPath, 0744); err != nil { return nil, err } volumeInfo, err := inst.StoreEnumerator.Enumerate( &api.VolumeLocator{}, nil, ) if err == nil { for _, info := range volumeInfo { if info.Status == api.VolumeStatus_VOLUME_STATUS_NONE { info.Status = api.VolumeStatus_VOLUME_STATUS_UP inst.UpdateVol(info) } } } else { logrus.Println("Could not enumerate Volumes, ", err) } inst.cl = &clusterListener{} c, err := clustermanager.Inst() if err != nil { logrus.Println("BUSE initializing in single node mode") } else { logrus.Println("BUSE initializing in clustered mode") c.AddEventListener(inst.cl) } logrus.Println("BUSE initialized and driver mounted at: ", BuseMountPath) return inst, nil }
[ "func", "Init", "(", "params", "map", "[", "string", "]", "string", ")", "(", "volume", ".", "VolumeDriver", ",", "error", ")", "{", "nbdInit", "(", ")", "\n\n", "inst", ":=", "&", "driver", "{", "IODriver", ":", "volume", ".", "IONotSupported", ",", "StoreEnumerator", ":", "common", ".", "NewDefaultStoreEnumerator", "(", "Name", ",", "kvdb", ".", "Instance", "(", ")", ")", ",", "StatsDriver", ":", "volume", ".", "StatsNotSupported", ",", "QuiesceDriver", ":", "volume", ".", "QuiesceNotSupported", ",", "CredsDriver", ":", "volume", ".", "CredsNotSupported", ",", "CloudBackupDriver", ":", "volume", ".", "CloudBackupNotSupported", ",", "CloudMigrateDriver", ":", "volume", ".", "CloudMigrateNotSupported", ",", "}", "\n", "inst", ".", "buseDevices", "=", "make", "(", "map", "[", "string", "]", "*", "buseDev", ")", "\n", "if", "err", ":=", "os", ".", "MkdirAll", "(", "BuseMountPath", ",", "0744", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "volumeInfo", ",", "err", ":=", "inst", ".", "StoreEnumerator", ".", "Enumerate", "(", "&", "api", ".", "VolumeLocator", "{", "}", ",", "nil", ",", ")", "\n", "if", "err", "==", "nil", "{", "for", "_", ",", "info", ":=", "range", "volumeInfo", "{", "if", "info", ".", "Status", "==", "api", ".", "VolumeStatus_VOLUME_STATUS_NONE", "{", "info", ".", "Status", "=", "api", ".", "VolumeStatus_VOLUME_STATUS_UP", "\n", "inst", ".", "UpdateVol", "(", "info", ")", "\n", "}", "\n", "}", "\n", "}", "else", "{", "logrus", ".", "Println", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "inst", ".", "cl", "=", "&", "clusterListener", "{", "}", "\n", "c", ",", "err", ":=", "clustermanager", ".", "Inst", "(", ")", "\n", "if", "err", "!=", "nil", "{", "logrus", ".", "Println", "(", "\"", "\"", ")", "\n", "}", "else", "{", "logrus", ".", "Println", "(", "\"", "\"", ")", "\n", "c", ".", "AddEventListener", "(", "inst", ".", "cl", ")", "\n", "}", "\n\n", "logrus", ".", "Println", "(", "\"", "\"", ",", "BuseMountPath", ")", "\n", "return", "inst", ",", "nil", "\n", "}" ]
// Init intialized the buse driver
[ "Init", "intialized", "the", "buse", "driver" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/volume/drivers/buse/buse.go#L94-L137
train
libopenstorage/openstorage
pkg/mount/deleted_mount.go
NewDeletedMounter
func NewDeletedMounter( rootSubstring string, mountImpl MountImpl, ) (*deletedMounter, error) { devMounter, err := NewDeviceMounter([]string{"/dev/"}, mountImpl, nil, "") if err != nil { return nil, err } deletedMounts := make(DeviceMap) for k, v := range devMounter.mounts { if matchDeleted(rootSubstring, k) { deletedMounts[k] = v } else { for _, p := range v.Mountpoint { if matchDeleted(rootSubstring, p.Root) { addMountpoint(deletedMounts, k, p) } } } } devMounter.mounts = deletedMounts return &deletedMounter{deviceMounter: devMounter}, nil }
go
func NewDeletedMounter( rootSubstring string, mountImpl MountImpl, ) (*deletedMounter, error) { devMounter, err := NewDeviceMounter([]string{"/dev/"}, mountImpl, nil, "") if err != nil { return nil, err } deletedMounts := make(DeviceMap) for k, v := range devMounter.mounts { if matchDeleted(rootSubstring, k) { deletedMounts[k] = v } else { for _, p := range v.Mountpoint { if matchDeleted(rootSubstring, p.Root) { addMountpoint(deletedMounts, k, p) } } } } devMounter.mounts = deletedMounts return &deletedMounter{deviceMounter: devMounter}, nil }
[ "func", "NewDeletedMounter", "(", "rootSubstring", "string", ",", "mountImpl", "MountImpl", ",", ")", "(", "*", "deletedMounter", ",", "error", ")", "{", "devMounter", ",", "err", ":=", "NewDeviceMounter", "(", "[", "]", "string", "{", "\"", "\"", "}", ",", "mountImpl", ",", "nil", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "deletedMounts", ":=", "make", "(", "DeviceMap", ")", "\n", "for", "k", ",", "v", ":=", "range", "devMounter", ".", "mounts", "{", "if", "matchDeleted", "(", "rootSubstring", ",", "k", ")", "{", "deletedMounts", "[", "k", "]", "=", "v", "\n", "}", "else", "{", "for", "_", ",", "p", ":=", "range", "v", ".", "Mountpoint", "{", "if", "matchDeleted", "(", "rootSubstring", ",", "p", ".", "Root", ")", "{", "addMountpoint", "(", "deletedMounts", ",", "k", ",", "p", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "devMounter", ".", "mounts", "=", "deletedMounts", "\n", "return", "&", "deletedMounter", "{", "deviceMounter", ":", "devMounter", "}", ",", "nil", "\n", "}" ]
// NewDeletedMounter returns a new deletedMounter
[ "NewDeletedMounter", "returns", "a", "new", "deletedMounter" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/mount/deleted_mount.go#L23-L46
train
libopenstorage/openstorage
pkg/mount/deleted_mount.go
Unmount
func (m *deletedMounter) Unmount( sourcePath string, path string, flags int, timeout int, opts map[string]string, ) error { if sourcePath != AllDevices { return fmt.Errorf("DeletedMounter accepts only %v as sourcePath", AllDevices) } m.Lock() defer m.Unlock() failedUnmounts := make(DeviceMap) for k, v := range m.mounts { for _, p := range v.Mountpoint { logrus.Warnf("Unmounting deleted mount path %v->%v", k, p) if err := m.mountImpl.Unmount(p.Path, flags, timeout); err != nil { logrus.Warnf("Failed to unmount mount path %v->%v", k, p) addMountpoint(failedUnmounts, k, p) } } } m.mounts = failedUnmounts if len(m.mounts) > 0 { return fmt.Errorf("Not all paths could be unmounted") } return nil }
go
func (m *deletedMounter) Unmount( sourcePath string, path string, flags int, timeout int, opts map[string]string, ) error { if sourcePath != AllDevices { return fmt.Errorf("DeletedMounter accepts only %v as sourcePath", AllDevices) } m.Lock() defer m.Unlock() failedUnmounts := make(DeviceMap) for k, v := range m.mounts { for _, p := range v.Mountpoint { logrus.Warnf("Unmounting deleted mount path %v->%v", k, p) if err := m.mountImpl.Unmount(p.Path, flags, timeout); err != nil { logrus.Warnf("Failed to unmount mount path %v->%v", k, p) addMountpoint(failedUnmounts, k, p) } } } m.mounts = failedUnmounts if len(m.mounts) > 0 { return fmt.Errorf("Not all paths could be unmounted") } return nil }
[ "func", "(", "m", "*", "deletedMounter", ")", "Unmount", "(", "sourcePath", "string", ",", "path", "string", ",", "flags", "int", ",", "timeout", "int", ",", "opts", "map", "[", "string", "]", "string", ",", ")", "error", "{", "if", "sourcePath", "!=", "AllDevices", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "AllDevices", ")", "\n", "}", "\n\n", "m", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "Unlock", "(", ")", "\n\n", "failedUnmounts", ":=", "make", "(", "DeviceMap", ")", "\n", "for", "k", ",", "v", ":=", "range", "m", ".", "mounts", "{", "for", "_", ",", "p", ":=", "range", "v", ".", "Mountpoint", "{", "logrus", ".", "Warnf", "(", "\"", "\"", ",", "k", ",", "p", ")", "\n", "if", "err", ":=", "m", ".", "mountImpl", ".", "Unmount", "(", "p", ".", "Path", ",", "flags", ",", "timeout", ")", ";", "err", "!=", "nil", "{", "logrus", ".", "Warnf", "(", "\"", "\"", ",", "k", ",", "p", ")", "\n", "addMountpoint", "(", "failedUnmounts", ",", "k", ",", "p", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "m", ".", "mounts", "=", "failedUnmounts", "\n", "if", "len", "(", "m", ".", "mounts", ")", ">", "0", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Unmount all deleted mounts.
[ "Unmount", "all", "deleted", "mounts", "." ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/mount/deleted_mount.go#L66-L97
train
libopenstorage/openstorage
volume/drivers/fake/fake.go
CloudBackupCreate
func (d *driver) CloudBackupCreate( input *api.CloudBackupCreateRequest, ) (*api.CloudBackupCreateResponse, error) { name, _, err := d.cloudBackupCreate(input) if err == nil { resp := &api.CloudBackupCreateResponse{Name: name} return resp, err } return nil, err }
go
func (d *driver) CloudBackupCreate( input *api.CloudBackupCreateRequest, ) (*api.CloudBackupCreateResponse, error) { name, _, err := d.cloudBackupCreate(input) if err == nil { resp := &api.CloudBackupCreateResponse{Name: name} return resp, err } return nil, err }
[ "func", "(", "d", "*", "driver", ")", "CloudBackupCreate", "(", "input", "*", "api", ".", "CloudBackupCreateRequest", ",", ")", "(", "*", "api", ".", "CloudBackupCreateResponse", ",", "error", ")", "{", "name", ",", "_", ",", "err", ":=", "d", ".", "cloudBackupCreate", "(", "input", ")", "\n", "if", "err", "==", "nil", "{", "resp", ":=", "&", "api", ".", "CloudBackupCreateResponse", "{", "Name", ":", "name", "}", "\n", "return", "resp", ",", "err", "\n", "}", "\n", "return", "nil", ",", "err", "\n", "}" ]
// CloudBackupCreate uploads snapshot of a volume to the cloud
[ "CloudBackupCreate", "uploads", "snapshot", "of", "a", "volume", "to", "the", "cloud" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/volume/drivers/fake/fake.go#L465-L474
train
libopenstorage/openstorage
volume/drivers/fake/fake.go
cloudBackupCreate
func (d *driver) cloudBackupCreate(input *api.CloudBackupCreateRequest) (string, string, error) { // Confirm credential id if err := d.CredsValidate(input.CredentialUUID); err != nil { return "", "", err } // Get volume info vols, err := d.Inspect([]string{input.VolumeID}) if err != nil { return "", "", fmt.Errorf("Volume id not found") } if len(vols) < 1 { return "", "", fmt.Errorf("Internal error. Volume found but no data returned") } vol := vols[0] if vol.GetSpec() == nil { return "", "", fmt.Errorf("Internal error. Volume has no specificiation") } taskId := uuid.New() // Save cloud backup cloudId := uuid.New() clusterInfo, err := d.thisCluster.Enumerate() if err != nil { return "", "", err } _, err = d.kv.Put(backupsKeyPrefix+"/"+taskId, &fakeBackups{ Volume: *vol, ClusterId: clusterInfo.Id, Status: api.CloudBackupStatus{ ID: cloudId, OpType: api.CloudBackupOp, Status: api.CloudBackupStatusDone, BytesDone: vol.GetSpec().GetSize(), StartTime: time.Now(), CompletedTime: time.Now().Local().Add(1 * time.Second), NodeID: clusterInfo.NodeId, CredentialUUID: input.CredentialUUID, SrcVolumeID: input.VolumeID, }, Info: api.CloudBackupInfo{ ID: cloudId, SrcVolumeID: input.VolumeID, SrcVolumeName: vol.GetLocator().GetName(), Timestamp: time.Now(), Metadata: map[string]string{ "fake": "backup", }, Status: string(api.CloudBackupStatusDone), }, }, 0) if err != nil { return "", "", err } return taskId, cloudId, nil }
go
func (d *driver) cloudBackupCreate(input *api.CloudBackupCreateRequest) (string, string, error) { // Confirm credential id if err := d.CredsValidate(input.CredentialUUID); err != nil { return "", "", err } // Get volume info vols, err := d.Inspect([]string{input.VolumeID}) if err != nil { return "", "", fmt.Errorf("Volume id not found") } if len(vols) < 1 { return "", "", fmt.Errorf("Internal error. Volume found but no data returned") } vol := vols[0] if vol.GetSpec() == nil { return "", "", fmt.Errorf("Internal error. Volume has no specificiation") } taskId := uuid.New() // Save cloud backup cloudId := uuid.New() clusterInfo, err := d.thisCluster.Enumerate() if err != nil { return "", "", err } _, err = d.kv.Put(backupsKeyPrefix+"/"+taskId, &fakeBackups{ Volume: *vol, ClusterId: clusterInfo.Id, Status: api.CloudBackupStatus{ ID: cloudId, OpType: api.CloudBackupOp, Status: api.CloudBackupStatusDone, BytesDone: vol.GetSpec().GetSize(), StartTime: time.Now(), CompletedTime: time.Now().Local().Add(1 * time.Second), NodeID: clusterInfo.NodeId, CredentialUUID: input.CredentialUUID, SrcVolumeID: input.VolumeID, }, Info: api.CloudBackupInfo{ ID: cloudId, SrcVolumeID: input.VolumeID, SrcVolumeName: vol.GetLocator().GetName(), Timestamp: time.Now(), Metadata: map[string]string{ "fake": "backup", }, Status: string(api.CloudBackupStatusDone), }, }, 0) if err != nil { return "", "", err } return taskId, cloudId, nil }
[ "func", "(", "d", "*", "driver", ")", "cloudBackupCreate", "(", "input", "*", "api", ".", "CloudBackupCreateRequest", ")", "(", "string", ",", "string", ",", "error", ")", "{", "// Confirm credential id", "if", "err", ":=", "d", ".", "CredsValidate", "(", "input", ".", "CredentialUUID", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "\"", "\"", ",", "err", "\n", "}", "\n\n", "// Get volume info", "vols", ",", "err", ":=", "d", ".", "Inspect", "(", "[", "]", "string", "{", "input", ".", "VolumeID", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "len", "(", "vols", ")", "<", "1", "{", "return", "\"", "\"", ",", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "vol", ":=", "vols", "[", "0", "]", "\n", "if", "vol", ".", "GetSpec", "(", ")", "==", "nil", "{", "return", "\"", "\"", ",", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "taskId", ":=", "uuid", ".", "New", "(", ")", "\n", "// Save cloud backup", "cloudId", ":=", "uuid", ".", "New", "(", ")", "\n", "clusterInfo", ",", "err", ":=", "d", ".", "thisCluster", ".", "Enumerate", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "\"", "\"", ",", "err", "\n", "}", "\n", "_", ",", "err", "=", "d", ".", "kv", ".", "Put", "(", "backupsKeyPrefix", "+", "\"", "\"", "+", "taskId", ",", "&", "fakeBackups", "{", "Volume", ":", "*", "vol", ",", "ClusterId", ":", "clusterInfo", ".", "Id", ",", "Status", ":", "api", ".", "CloudBackupStatus", "{", "ID", ":", "cloudId", ",", "OpType", ":", "api", ".", "CloudBackupOp", ",", "Status", ":", "api", ".", "CloudBackupStatusDone", ",", "BytesDone", ":", "vol", ".", "GetSpec", "(", ")", ".", "GetSize", "(", ")", ",", "StartTime", ":", "time", ".", "Now", "(", ")", ",", "CompletedTime", ":", "time", ".", "Now", "(", ")", ".", "Local", "(", ")", ".", "Add", "(", "1", "*", "time", ".", "Second", ")", ",", "NodeID", ":", "clusterInfo", ".", "NodeId", ",", "CredentialUUID", ":", "input", ".", "CredentialUUID", ",", "SrcVolumeID", ":", "input", ".", "VolumeID", ",", "}", ",", "Info", ":", "api", ".", "CloudBackupInfo", "{", "ID", ":", "cloudId", ",", "SrcVolumeID", ":", "input", ".", "VolumeID", ",", "SrcVolumeName", ":", "vol", ".", "GetLocator", "(", ")", ".", "GetName", "(", ")", ",", "Timestamp", ":", "time", ".", "Now", "(", ")", ",", "Metadata", ":", "map", "[", "string", "]", "string", "{", "\"", "\"", ":", "\"", "\"", ",", "}", ",", "Status", ":", "string", "(", "api", ".", "CloudBackupStatusDone", ")", ",", "}", ",", "}", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "\"", "\"", ",", "err", "\n", "}", "\n", "return", "taskId", ",", "cloudId", ",", "nil", "\n", "}" ]
// cloudBackupCreate uploads snapshot of a volume to the cloud and returns the // backup task id
[ "cloudBackupCreate", "uploads", "snapshot", "of", "a", "volume", "to", "the", "cloud", "and", "returns", "the", "backup", "task", "id" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/volume/drivers/fake/fake.go#L478-L534
train
libopenstorage/openstorage
volume/drivers/fake/fake.go
CloudBackupRestore
func (d *driver) CloudBackupRestore( input *api.CloudBackupRestoreRequest, ) (*api.CloudBackupRestoreResponse, error) { // Confirm credential id if err := d.CredsValidate(input.CredentialUUID); err != nil { return nil, err } backup, _, err := d.backupEntry(input.ID, api.CloudBackupOp) if err != nil { return nil, err } volid, err := d.Create(&api.VolumeLocator{Name: input.RestoreVolumeName}, &api.Source{}, backup.Volume.GetSpec()) if err != nil { return nil, err } vols, err := d.Inspect([]string{volid}) if err != nil { return nil, fmt.Errorf("Volume id not found") } if len(vols) < 1 { return nil, fmt.Errorf("Internal error. Volume found but no data returned") } vol := vols[0] if vol.GetSpec() == nil { return nil, fmt.Errorf("Internal error. Volume has no specificiation") } cloudId := uuid.New() clusterInfo, err := d.thisCluster.Enumerate() if err != nil { return nil, err } _, err = d.kv.Put(backupsKeyPrefix+"/"+cloudId, &fakeBackups{ Volume: *vol, ClusterId: clusterInfo.Id, Status: api.CloudBackupStatus{ ID: cloudId, OpType: api.CloudRestoreOp, Status: api.CloudBackupStatusDone, BytesDone: vol.GetSpec().GetSize(), StartTime: time.Now(), CompletedTime: time.Now().Local().Add(1 * time.Second), NodeID: clusterInfo.NodeId, CredentialUUID: input.CredentialUUID, SrcVolumeID: volid, }, }, 0) if err != nil { return nil, err } return &api.CloudBackupRestoreResponse{ RestoreVolumeID: volid, }, nil }
go
func (d *driver) CloudBackupRestore( input *api.CloudBackupRestoreRequest, ) (*api.CloudBackupRestoreResponse, error) { // Confirm credential id if err := d.CredsValidate(input.CredentialUUID); err != nil { return nil, err } backup, _, err := d.backupEntry(input.ID, api.CloudBackupOp) if err != nil { return nil, err } volid, err := d.Create(&api.VolumeLocator{Name: input.RestoreVolumeName}, &api.Source{}, backup.Volume.GetSpec()) if err != nil { return nil, err } vols, err := d.Inspect([]string{volid}) if err != nil { return nil, fmt.Errorf("Volume id not found") } if len(vols) < 1 { return nil, fmt.Errorf("Internal error. Volume found but no data returned") } vol := vols[0] if vol.GetSpec() == nil { return nil, fmt.Errorf("Internal error. Volume has no specificiation") } cloudId := uuid.New() clusterInfo, err := d.thisCluster.Enumerate() if err != nil { return nil, err } _, err = d.kv.Put(backupsKeyPrefix+"/"+cloudId, &fakeBackups{ Volume: *vol, ClusterId: clusterInfo.Id, Status: api.CloudBackupStatus{ ID: cloudId, OpType: api.CloudRestoreOp, Status: api.CloudBackupStatusDone, BytesDone: vol.GetSpec().GetSize(), StartTime: time.Now(), CompletedTime: time.Now().Local().Add(1 * time.Second), NodeID: clusterInfo.NodeId, CredentialUUID: input.CredentialUUID, SrcVolumeID: volid, }, }, 0) if err != nil { return nil, err } return &api.CloudBackupRestoreResponse{ RestoreVolumeID: volid, }, nil }
[ "func", "(", "d", "*", "driver", ")", "CloudBackupRestore", "(", "input", "*", "api", ".", "CloudBackupRestoreRequest", ",", ")", "(", "*", "api", ".", "CloudBackupRestoreResponse", ",", "error", ")", "{", "// Confirm credential id", "if", "err", ":=", "d", ".", "CredsValidate", "(", "input", ".", "CredentialUUID", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "backup", ",", "_", ",", "err", ":=", "d", ".", "backupEntry", "(", "input", ".", "ID", ",", "api", ".", "CloudBackupOp", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "volid", ",", "err", ":=", "d", ".", "Create", "(", "&", "api", ".", "VolumeLocator", "{", "Name", ":", "input", ".", "RestoreVolumeName", "}", ",", "&", "api", ".", "Source", "{", "}", ",", "backup", ".", "Volume", ".", "GetSpec", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "vols", ",", "err", ":=", "d", ".", "Inspect", "(", "[", "]", "string", "{", "volid", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "len", "(", "vols", ")", "<", "1", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "vol", ":=", "vols", "[", "0", "]", "\n", "if", "vol", ".", "GetSpec", "(", ")", "==", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "cloudId", ":=", "uuid", ".", "New", "(", ")", "\n", "clusterInfo", ",", "err", ":=", "d", ".", "thisCluster", ".", "Enumerate", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "_", ",", "err", "=", "d", ".", "kv", ".", "Put", "(", "backupsKeyPrefix", "+", "\"", "\"", "+", "cloudId", ",", "&", "fakeBackups", "{", "Volume", ":", "*", "vol", ",", "ClusterId", ":", "clusterInfo", ".", "Id", ",", "Status", ":", "api", ".", "CloudBackupStatus", "{", "ID", ":", "cloudId", ",", "OpType", ":", "api", ".", "CloudRestoreOp", ",", "Status", ":", "api", ".", "CloudBackupStatusDone", ",", "BytesDone", ":", "vol", ".", "GetSpec", "(", ")", ".", "GetSize", "(", ")", ",", "StartTime", ":", "time", ".", "Now", "(", ")", ",", "CompletedTime", ":", "time", ".", "Now", "(", ")", ".", "Local", "(", ")", ".", "Add", "(", "1", "*", "time", ".", "Second", ")", ",", "NodeID", ":", "clusterInfo", ".", "NodeId", ",", "CredentialUUID", ":", "input", ".", "CredentialUUID", ",", "SrcVolumeID", ":", "volid", ",", "}", ",", "}", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "api", ".", "CloudBackupRestoreResponse", "{", "RestoreVolumeID", ":", "volid", ",", "}", ",", "nil", "\n\n", "}" ]
// CloudBackupRestore downloads a cloud backup and restores it to a volume
[ "CloudBackupRestore", "downloads", "a", "cloud", "backup", "and", "restores", "it", "to", "a", "volume" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/volume/drivers/fake/fake.go#L565-L622
train
libopenstorage/openstorage
volume/drivers/fake/fake.go
CloudBackupDelete
func (d *driver) CloudBackupDelete(input *api.CloudBackupDeleteRequest) error { // Confirm credential id if err := d.CredsValidate(input.CredentialUUID); err != nil { return err } _, id, err := d.backupEntry(input.ID, api.CloudBackupOp) if err != nil { return err } //_, err := d.kv.Delete(backupsKeyPrefix + "/" + id) _, err = d.kv.Delete(id) return err }
go
func (d *driver) CloudBackupDelete(input *api.CloudBackupDeleteRequest) error { // Confirm credential id if err := d.CredsValidate(input.CredentialUUID); err != nil { return err } _, id, err := d.backupEntry(input.ID, api.CloudBackupOp) if err != nil { return err } //_, err := d.kv.Delete(backupsKeyPrefix + "/" + id) _, err = d.kv.Delete(id) return err }
[ "func", "(", "d", "*", "driver", ")", "CloudBackupDelete", "(", "input", "*", "api", ".", "CloudBackupDeleteRequest", ")", "error", "{", "// Confirm credential id", "if", "err", ":=", "d", ".", "CredsValidate", "(", "input", ".", "CredentialUUID", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "_", ",", "id", ",", "err", ":=", "d", ".", "backupEntry", "(", "input", ".", "ID", ",", "api", ".", "CloudBackupOp", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "//_, err := d.kv.Delete(backupsKeyPrefix + \"/\" + id)", "_", ",", "err", "=", "d", ".", "kv", ".", "Delete", "(", "id", ")", "\n", "return", "err", "\n", "}" ]
// CloudBackupDelete deletes the specified backup in cloud
[ "CloudBackupDelete", "deletes", "the", "specified", "backup", "in", "cloud" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/volume/drivers/fake/fake.go#L625-L639
train
libopenstorage/openstorage
volume/drivers/fake/fake.go
CloudBackupDeleteAll
func (d *driver) CloudBackupDeleteAll(input *api.CloudBackupDeleteAllRequest) error { // Confirm credential id if err := d.CredsValidate(input.CredentialUUID); err != nil { return err } // Get volume info if len(input.SrcVolumeID) != 0 { vols, err := d.Inspect([]string{input.SrcVolumeID}) if err != nil { return fmt.Errorf("Volume id not found") } if len(vols) < 1 { return fmt.Errorf("Internal error. Volume found but no data returned") } vol := vols[0] if vol.GetSpec() == nil { return fmt.Errorf("Internal error. Volume has no specificiation") } } kvp, err := d.kv.Enumerate(backupsKeyPrefix) if err != nil { return err } for _, v := range kvp { elem := &fakeBackups{} if err := json.Unmarshal(v.Value, elem); err != nil { return err } if elem.Status.OpType == api.CloudRestoreOp { continue } if len(input.SrcVolumeID) == 0 && len(input.ClusterID) == 0 { _, err = d.kv.Delete(v.Key) } else if input.SrcVolumeID == elem.Volume.GetId() { _, err = d.kv.Delete(v.Key) } else if input.ClusterID == elem.ClusterId { _, err = d.kv.Delete(v.Key) } if err != nil { return err } } return nil }
go
func (d *driver) CloudBackupDeleteAll(input *api.CloudBackupDeleteAllRequest) error { // Confirm credential id if err := d.CredsValidate(input.CredentialUUID); err != nil { return err } // Get volume info if len(input.SrcVolumeID) != 0 { vols, err := d.Inspect([]string{input.SrcVolumeID}) if err != nil { return fmt.Errorf("Volume id not found") } if len(vols) < 1 { return fmt.Errorf("Internal error. Volume found but no data returned") } vol := vols[0] if vol.GetSpec() == nil { return fmt.Errorf("Internal error. Volume has no specificiation") } } kvp, err := d.kv.Enumerate(backupsKeyPrefix) if err != nil { return err } for _, v := range kvp { elem := &fakeBackups{} if err := json.Unmarshal(v.Value, elem); err != nil { return err } if elem.Status.OpType == api.CloudRestoreOp { continue } if len(input.SrcVolumeID) == 0 && len(input.ClusterID) == 0 { _, err = d.kv.Delete(v.Key) } else if input.SrcVolumeID == elem.Volume.GetId() { _, err = d.kv.Delete(v.Key) } else if input.ClusterID == elem.ClusterId { _, err = d.kv.Delete(v.Key) } if err != nil { return err } } return nil }
[ "func", "(", "d", "*", "driver", ")", "CloudBackupDeleteAll", "(", "input", "*", "api", ".", "CloudBackupDeleteAllRequest", ")", "error", "{", "// Confirm credential id", "if", "err", ":=", "d", ".", "CredsValidate", "(", "input", ".", "CredentialUUID", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// Get volume info", "if", "len", "(", "input", ".", "SrcVolumeID", ")", "!=", "0", "{", "vols", ",", "err", ":=", "d", ".", "Inspect", "(", "[", "]", "string", "{", "input", ".", "SrcVolumeID", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "len", "(", "vols", ")", "<", "1", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "vol", ":=", "vols", "[", "0", "]", "\n", "if", "vol", ".", "GetSpec", "(", ")", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "\n\n", "kvp", ",", "err", ":=", "d", ".", "kv", ".", "Enumerate", "(", "backupsKeyPrefix", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "for", "_", ",", "v", ":=", "range", "kvp", "{", "elem", ":=", "&", "fakeBackups", "{", "}", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "v", ".", "Value", ",", "elem", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "elem", ".", "Status", ".", "OpType", "==", "api", ".", "CloudRestoreOp", "{", "continue", "\n", "}", "\n", "if", "len", "(", "input", ".", "SrcVolumeID", ")", "==", "0", "&&", "len", "(", "input", ".", "ClusterID", ")", "==", "0", "{", "_", ",", "err", "=", "d", ".", "kv", ".", "Delete", "(", "v", ".", "Key", ")", "\n", "}", "else", "if", "input", ".", "SrcVolumeID", "==", "elem", ".", "Volume", ".", "GetId", "(", ")", "{", "_", ",", "err", "=", "d", ".", "kv", ".", "Delete", "(", "v", ".", "Key", ")", "\n", "}", "else", "if", "input", ".", "ClusterID", "==", "elem", ".", "ClusterId", "{", "_", ",", "err", "=", "d", ".", "kv", ".", "Delete", "(", "v", ".", "Key", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// CloudBackupDelete deletes all the backups for a given volume in cloud
[ "CloudBackupDelete", "deletes", "all", "the", "backups", "for", "a", "given", "volume", "in", "cloud" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/volume/drivers/fake/fake.go#L678-L724
train
libopenstorage/openstorage
volume/drivers/fake/fake.go
CloudBackupSchedCreate
func (d *driver) CloudBackupSchedCreate( input *api.CloudBackupSchedCreateRequest, ) (*api.CloudBackupSchedCreateResponse, error) { // Confirm credential id if err := d.CredsValidate(input.CredentialUUID); err != nil { return nil, err } // Check volume vols, err := d.Inspect([]string{input.SrcVolumeID}) if err != nil { return nil, fmt.Errorf("Volume id not found") } if len(vols) < 1 { return nil, fmt.Errorf("Internal error. Volume found but no data returned") } vol := vols[0] if vol.GetSpec() == nil { return nil, fmt.Errorf("Internal error. Volume has no specificiation") } id := uuid.New() _, err = d.kv.Put(schedPrefix+"/"+id, &fakeSchedules{ Id: id, Info: api.CloudBackupScheduleInfo{ SrcVolumeID: input.SrcVolumeID, CredentialUUID: input.CredentialUUID, Schedule: input.Schedule, MaxBackups: input.MaxBackups, }, }, 0) if err != nil { return nil, err } return &api.CloudBackupSchedCreateResponse{ UUID: id, }, nil }
go
func (d *driver) CloudBackupSchedCreate( input *api.CloudBackupSchedCreateRequest, ) (*api.CloudBackupSchedCreateResponse, error) { // Confirm credential id if err := d.CredsValidate(input.CredentialUUID); err != nil { return nil, err } // Check volume vols, err := d.Inspect([]string{input.SrcVolumeID}) if err != nil { return nil, fmt.Errorf("Volume id not found") } if len(vols) < 1 { return nil, fmt.Errorf("Internal error. Volume found but no data returned") } vol := vols[0] if vol.GetSpec() == nil { return nil, fmt.Errorf("Internal error. Volume has no specificiation") } id := uuid.New() _, err = d.kv.Put(schedPrefix+"/"+id, &fakeSchedules{ Id: id, Info: api.CloudBackupScheduleInfo{ SrcVolumeID: input.SrcVolumeID, CredentialUUID: input.CredentialUUID, Schedule: input.Schedule, MaxBackups: input.MaxBackups, }, }, 0) if err != nil { return nil, err } return &api.CloudBackupSchedCreateResponse{ UUID: id, }, nil }
[ "func", "(", "d", "*", "driver", ")", "CloudBackupSchedCreate", "(", "input", "*", "api", ".", "CloudBackupSchedCreateRequest", ",", ")", "(", "*", "api", ".", "CloudBackupSchedCreateResponse", ",", "error", ")", "{", "// Confirm credential id", "if", "err", ":=", "d", ".", "CredsValidate", "(", "input", ".", "CredentialUUID", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// Check volume", "vols", ",", "err", ":=", "d", ".", "Inspect", "(", "[", "]", "string", "{", "input", ".", "SrcVolumeID", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "len", "(", "vols", ")", "<", "1", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "vol", ":=", "vols", "[", "0", "]", "\n", "if", "vol", ".", "GetSpec", "(", ")", "==", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "id", ":=", "uuid", ".", "New", "(", ")", "\n", "_", ",", "err", "=", "d", ".", "kv", ".", "Put", "(", "schedPrefix", "+", "\"", "\"", "+", "id", ",", "&", "fakeSchedules", "{", "Id", ":", "id", ",", "Info", ":", "api", ".", "CloudBackupScheduleInfo", "{", "SrcVolumeID", ":", "input", ".", "SrcVolumeID", ",", "CredentialUUID", ":", "input", ".", "CredentialUUID", ",", "Schedule", ":", "input", ".", "Schedule", ",", "MaxBackups", ":", "input", ".", "MaxBackups", ",", "}", ",", "}", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "api", ".", "CloudBackupSchedCreateResponse", "{", "UUID", ":", "id", ",", "}", ",", "nil", "\n", "}" ]
// CloudBackupSchedCreate creates a schedule backup volume to cloud
[ "CloudBackupSchedCreate", "creates", "a", "schedule", "backup", "volume", "to", "cloud" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/volume/drivers/fake/fake.go#L876-L915
train
libopenstorage/openstorage
volume/drivers/fake/fake.go
CloudBackupSchedDelete
func (d *driver) CloudBackupSchedDelete(input *api.CloudBackupSchedDeleteRequest) error { d.kv.Delete(schedPrefix + "/" + input.UUID) return nil }
go
func (d *driver) CloudBackupSchedDelete(input *api.CloudBackupSchedDeleteRequest) error { d.kv.Delete(schedPrefix + "/" + input.UUID) return nil }
[ "func", "(", "d", "*", "driver", ")", "CloudBackupSchedDelete", "(", "input", "*", "api", ".", "CloudBackupSchedDeleteRequest", ")", "error", "{", "d", ".", "kv", ".", "Delete", "(", "schedPrefix", "+", "\"", "\"", "+", "input", ".", "UUID", ")", "\n", "return", "nil", "\n", "}" ]
// CloudBackupSchedDelete delete a volume backup schedule to cloud
[ "CloudBackupSchedDelete", "delete", "a", "volume", "backup", "schedule", "to", "cloud" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/volume/drivers/fake/fake.go#L918-L921
train
libopenstorage/openstorage
volume/drivers/fake/fake.go
CloudBackupSchedEnumerate
func (d *driver) CloudBackupSchedEnumerate() (*api.CloudBackupSchedEnumerateResponse, error) { kvp, err := d.kv.Enumerate(schedPrefix) if err != nil { return nil, err } schedules := make(map[string]api.CloudBackupScheduleInfo, len(kvp)) for _, v := range kvp { elem := &fakeSchedules{} if err := json.Unmarshal(v.Value, elem); err != nil { return nil, err } schedules[elem.Id] = elem.Info } return &api.CloudBackupSchedEnumerateResponse{ Schedules: schedules, }, nil }
go
func (d *driver) CloudBackupSchedEnumerate() (*api.CloudBackupSchedEnumerateResponse, error) { kvp, err := d.kv.Enumerate(schedPrefix) if err != nil { return nil, err } schedules := make(map[string]api.CloudBackupScheduleInfo, len(kvp)) for _, v := range kvp { elem := &fakeSchedules{} if err := json.Unmarshal(v.Value, elem); err != nil { return nil, err } schedules[elem.Id] = elem.Info } return &api.CloudBackupSchedEnumerateResponse{ Schedules: schedules, }, nil }
[ "func", "(", "d", "*", "driver", ")", "CloudBackupSchedEnumerate", "(", ")", "(", "*", "api", ".", "CloudBackupSchedEnumerateResponse", ",", "error", ")", "{", "kvp", ",", "err", ":=", "d", ".", "kv", ".", "Enumerate", "(", "schedPrefix", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "schedules", ":=", "make", "(", "map", "[", "string", "]", "api", ".", "CloudBackupScheduleInfo", ",", "len", "(", "kvp", ")", ")", "\n", "for", "_", ",", "v", ":=", "range", "kvp", "{", "elem", ":=", "&", "fakeSchedules", "{", "}", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "v", ".", "Value", ",", "elem", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "schedules", "[", "elem", ".", "Id", "]", "=", "elem", ".", "Info", "\n", "}", "\n\n", "return", "&", "api", ".", "CloudBackupSchedEnumerateResponse", "{", "Schedules", ":", "schedules", ",", "}", ",", "nil", "\n", "}" ]
// CloudBackupSchedEnumerate enumerates the configured backup schedules in the cluster
[ "CloudBackupSchedEnumerate", "enumerates", "the", "configured", "backup", "schedules", "in", "the", "cluster" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/volume/drivers/fake/fake.go#L924-L941
train
libopenstorage/openstorage
pkg/storageops/gce/gce.go
IsDevMode
func IsDevMode() bool { var i = new(instance) err := gceInfoFromEnv(i) return err == nil }
go
func IsDevMode() bool { var i = new(instance) err := gceInfoFromEnv(i) return err == nil }
[ "func", "IsDevMode", "(", ")", "bool", "{", "var", "i", "=", "new", "(", "instance", ")", "\n", "err", ":=", "gceInfoFromEnv", "(", "i", ")", "\n", "return", "err", "==", "nil", "\n", "}" ]
// IsDevMode checks if the pkg is invoked in developer mode where GCE credentials // are set as env variables
[ "IsDevMode", "checks", "if", "the", "pkg", "is", "invoked", "in", "developer", "mode", "where", "GCE", "credentials", "are", "set", "as", "env", "variables" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/storageops/gce/gce.go#L50-L54
train
libopenstorage/openstorage
pkg/storageops/gce/gce.go
NewClient
func NewClient() (storageops.Ops, error) { var i = new(instance) var err error if metadata.OnGCE() { err = gceInfo(i) } else if ok := IsDevMode(); ok { err = gceInfoFromEnv(i) } else { return nil, fmt.Errorf("instance is not running on GCE") } if err != nil { return nil, fmt.Errorf("error fetching instance info. Err: %v", err) } c, err := google.DefaultClient(context.Background(), compute.ComputeScope) if err != nil { return nil, fmt.Errorf("failed to authenticate with google api. Err: %v", err) } service, err := compute.New(c) if err != nil { return nil, fmt.Errorf("unable to create Compute service: %v", err) } return &gceOps{ inst: i, service: service, }, nil }
go
func NewClient() (storageops.Ops, error) { var i = new(instance) var err error if metadata.OnGCE() { err = gceInfo(i) } else if ok := IsDevMode(); ok { err = gceInfoFromEnv(i) } else { return nil, fmt.Errorf("instance is not running on GCE") } if err != nil { return nil, fmt.Errorf("error fetching instance info. Err: %v", err) } c, err := google.DefaultClient(context.Background(), compute.ComputeScope) if err != nil { return nil, fmt.Errorf("failed to authenticate with google api. Err: %v", err) } service, err := compute.New(c) if err != nil { return nil, fmt.Errorf("unable to create Compute service: %v", err) } return &gceOps{ inst: i, service: service, }, nil }
[ "func", "NewClient", "(", ")", "(", "storageops", ".", "Ops", ",", "error", ")", "{", "var", "i", "=", "new", "(", "instance", ")", "\n", "var", "err", "error", "\n", "if", "metadata", ".", "OnGCE", "(", ")", "{", "err", "=", "gceInfo", "(", "i", ")", "\n", "}", "else", "if", "ok", ":=", "IsDevMode", "(", ")", ";", "ok", "{", "err", "=", "gceInfoFromEnv", "(", "i", ")", "\n", "}", "else", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "c", ",", "err", ":=", "google", ".", "DefaultClient", "(", "context", ".", "Background", "(", ")", ",", "compute", ".", "ComputeScope", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "service", ",", "err", ":=", "compute", ".", "New", "(", "c", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "return", "&", "gceOps", "{", "inst", ":", "i", ",", "service", ":", "service", ",", "}", ",", "nil", "\n", "}" ]
// NewClient creates a new GCE operations client
[ "NewClient", "creates", "a", "new", "GCE", "operations", "client" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/storageops/gce/gce.go#L57-L86
train
libopenstorage/openstorage
pkg/storageops/gce/gce.go
gceInfo
func gceInfo(inst *instance) error { var err error inst.zone, err = metadata.Zone() if err != nil { return err } inst.name, err = metadata.InstanceName() if err != nil { return err } inst.hostname, err = metadata.Hostname() if err != nil { return err } inst.project, err = metadata.ProjectID() if err != nil { return err } return nil }
go
func gceInfo(inst *instance) error { var err error inst.zone, err = metadata.Zone() if err != nil { return err } inst.name, err = metadata.InstanceName() if err != nil { return err } inst.hostname, err = metadata.Hostname() if err != nil { return err } inst.project, err = metadata.ProjectID() if err != nil { return err } return nil }
[ "func", "gceInfo", "(", "inst", "*", "instance", ")", "error", "{", "var", "err", "error", "\n", "inst", ".", "zone", ",", "err", "=", "metadata", ".", "Zone", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "inst", ".", "name", ",", "err", "=", "metadata", ".", "InstanceName", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "inst", ".", "hostname", ",", "err", "=", "metadata", ".", "Hostname", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "inst", ".", "project", ",", "err", "=", "metadata", ".", "ProjectID", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// gceInfo fetches the GCE instance metadata from the metadata server
[ "gceInfo", "fetches", "the", "GCE", "instance", "metadata", "from", "the", "metadata", "server" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/storageops/gce/gce.go#L531-L554
train
libopenstorage/openstorage
pkg/storageops/gce/gce.go
waitForDetach
func (s *gceOps) waitForDetach( diskURL string, timeout time.Duration, ) error { _, err := task.DoRetryWithTimeout( func() (interface{}, bool, error) { inst, err := s.describeinstance() if err != nil { return nil, true, err } for _, d := range inst.Disks { if d.Source == diskURL { return nil, true, fmt.Errorf("disk: %s is still attached to instance: %s", diskURL, s.inst.name) } } return nil, false, nil }, storageops.ProviderOpsTimeout, storageops.ProviderOpsRetryInterval) return err }
go
func (s *gceOps) waitForDetach( diskURL string, timeout time.Duration, ) error { _, err := task.DoRetryWithTimeout( func() (interface{}, bool, error) { inst, err := s.describeinstance() if err != nil { return nil, true, err } for _, d := range inst.Disks { if d.Source == diskURL { return nil, true, fmt.Errorf("disk: %s is still attached to instance: %s", diskURL, s.inst.name) } } return nil, false, nil }, storageops.ProviderOpsTimeout, storageops.ProviderOpsRetryInterval) return err }
[ "func", "(", "s", "*", "gceOps", ")", "waitForDetach", "(", "diskURL", "string", ",", "timeout", "time", ".", "Duration", ",", ")", "error", "{", "_", ",", "err", ":=", "task", ".", "DoRetryWithTimeout", "(", "func", "(", ")", "(", "interface", "{", "}", ",", "bool", ",", "error", ")", "{", "inst", ",", "err", ":=", "s", ".", "describeinstance", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "true", ",", "err", "\n", "}", "\n\n", "for", "_", ",", "d", ":=", "range", "inst", ".", "Disks", "{", "if", "d", ".", "Source", "==", "diskURL", "{", "return", "nil", ",", "true", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "diskURL", ",", "s", ".", "inst", ".", "name", ")", "\n", "}", "\n", "}", "\n\n", "return", "nil", ",", "false", ",", "nil", "\n\n", "}", ",", "storageops", ".", "ProviderOpsTimeout", ",", "storageops", ".", "ProviderOpsRetryInterval", ")", "\n\n", "return", "err", "\n", "}" ]
// waitForDetach checks if given disk is detached from the local instance
[ "waitForDetach", "checks", "if", "given", "disk", "is", "detached", "from", "the", "local", "instance" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/storageops/gce/gce.go#L586-L613
train
libopenstorage/openstorage
pkg/storageops/gce/gce.go
waitForAttach
func (s *gceOps) waitForAttach( disk *compute.Disk, timeout time.Duration, ) (string, error) { devicePath, err := task.DoRetryWithTimeout( func() (interface{}, bool, error) { devicePath, err := s.DevicePath(disk.Name) if se, ok := err.(*storageops.StorageError); ok && se.Code == storageops.ErrVolAttachedOnRemoteNode { return "", false, err } else if err != nil { return "", true, err } return devicePath, false, nil }, storageops.ProviderOpsTimeout, storageops.ProviderOpsRetryInterval) if err != nil { return "", err } return devicePath.(string), nil }
go
func (s *gceOps) waitForAttach( disk *compute.Disk, timeout time.Duration, ) (string, error) { devicePath, err := task.DoRetryWithTimeout( func() (interface{}, bool, error) { devicePath, err := s.DevicePath(disk.Name) if se, ok := err.(*storageops.StorageError); ok && se.Code == storageops.ErrVolAttachedOnRemoteNode { return "", false, err } else if err != nil { return "", true, err } return devicePath, false, nil }, storageops.ProviderOpsTimeout, storageops.ProviderOpsRetryInterval) if err != nil { return "", err } return devicePath.(string), nil }
[ "func", "(", "s", "*", "gceOps", ")", "waitForAttach", "(", "disk", "*", "compute", ".", "Disk", ",", "timeout", "time", ".", "Duration", ",", ")", "(", "string", ",", "error", ")", "{", "devicePath", ",", "err", ":=", "task", ".", "DoRetryWithTimeout", "(", "func", "(", ")", "(", "interface", "{", "}", ",", "bool", ",", "error", ")", "{", "devicePath", ",", "err", ":=", "s", ".", "DevicePath", "(", "disk", ".", "Name", ")", "\n", "if", "se", ",", "ok", ":=", "err", ".", "(", "*", "storageops", ".", "StorageError", ")", ";", "ok", "&&", "se", ".", "Code", "==", "storageops", ".", "ErrVolAttachedOnRemoteNode", "{", "return", "\"", "\"", ",", "false", ",", "err", "\n", "}", "else", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "true", ",", "err", "\n", "}", "\n\n", "return", "devicePath", ",", "false", ",", "nil", "\n", "}", ",", "storageops", ".", "ProviderOpsTimeout", ",", "storageops", ".", "ProviderOpsRetryInterval", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "return", "devicePath", ".", "(", "string", ")", ",", "nil", "\n", "}" ]
// waitForAttach checks if given disk is attached to the local instance
[ "waitForAttach", "checks", "if", "given", "disk", "is", "attached", "to", "the", "local", "instance" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/storageops/gce/gce.go#L616-L639
train
libopenstorage/openstorage
pkg/grpcserver/grpcserver.go
New
func New(config *GrpcServerConfig) (*GrpcServer, error) { if nil == config { return nil, fmt.Errorf("Configuration must be provided") } if len(config.Name) == 0 { return nil, fmt.Errorf("Name of server must be provided") } if len(config.Address) == 0 { return nil, fmt.Errorf("Address must be provided") } if len(config.Net) == 0 { return nil, fmt.Errorf("Net must be provided") } l, err := net.Listen(config.Net, config.Address) if err != nil { return nil, fmt.Errorf("Unable to setup server: %s", err.Error()) } return &GrpcServer{ name: config.Name, listener: l, }, nil }
go
func New(config *GrpcServerConfig) (*GrpcServer, error) { if nil == config { return nil, fmt.Errorf("Configuration must be provided") } if len(config.Name) == 0 { return nil, fmt.Errorf("Name of server must be provided") } if len(config.Address) == 0 { return nil, fmt.Errorf("Address must be provided") } if len(config.Net) == 0 { return nil, fmt.Errorf("Net must be provided") } l, err := net.Listen(config.Net, config.Address) if err != nil { return nil, fmt.Errorf("Unable to setup server: %s", err.Error()) } return &GrpcServer{ name: config.Name, listener: l, }, nil }
[ "func", "New", "(", "config", "*", "GrpcServerConfig", ")", "(", "*", "GrpcServer", ",", "error", ")", "{", "if", "nil", "==", "config", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "len", "(", "config", ".", "Name", ")", "==", "0", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "len", "(", "config", ".", "Address", ")", "==", "0", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "len", "(", "config", ".", "Net", ")", "==", "0", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "l", ",", "err", ":=", "net", ".", "Listen", "(", "config", ".", "Net", ",", "config", ".", "Address", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n\n", "return", "&", "GrpcServer", "{", "name", ":", "config", ".", "Name", ",", "listener", ":", "l", ",", "}", ",", "nil", "\n", "}" ]
// New creates a gRPC server on the specified port and transport.
[ "New", "creates", "a", "gRPC", "server", "on", "the", "specified", "port", "and", "transport", "." ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/grpcserver/grpcserver.go#L48-L71
train
libopenstorage/openstorage
pkg/grpcserver/grpcserver.go
Start
func (s *GrpcServer) Start(register func(grpcServer *grpc.Server)) error { s.lock.Lock() defer s.lock.Unlock() if s.running { return fmt.Errorf("Server already running") } s.server = grpc.NewServer() register(s.server) // Start listening for requests s.startGrpcService() return nil }
go
func (s *GrpcServer) Start(register func(grpcServer *grpc.Server)) error { s.lock.Lock() defer s.lock.Unlock() if s.running { return fmt.Errorf("Server already running") } s.server = grpc.NewServer() register(s.server) // Start listening for requests s.startGrpcService() return nil }
[ "func", "(", "s", "*", "GrpcServer", ")", "Start", "(", "register", "func", "(", "grpcServer", "*", "grpc", ".", "Server", ")", ")", "error", "{", "s", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "lock", ".", "Unlock", "(", ")", "\n\n", "if", "s", ".", "running", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "s", ".", "server", "=", "grpc", ".", "NewServer", "(", ")", "\n", "register", "(", "s", ".", "server", ")", "\n\n", "// Start listening for requests", "s", ".", "startGrpcService", "(", ")", "\n", "return", "nil", "\n", "}" ]
// Start is used to start the server. // It will return an error if the server is already runnig.
[ "Start", "is", "used", "to", "start", "the", "server", ".", "It", "will", "return", "an", "error", "if", "the", "server", "is", "already", "runnig", "." ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/grpcserver/grpcserver.go#L75-L89
train
libopenstorage/openstorage
pkg/grpcserver/grpcserver.go
StartWithServer
func (s *GrpcServer) StartWithServer(server func() *grpc.Server) error { s.lock.Lock() defer s.lock.Unlock() if server == nil { return fmt.Errorf("Server function has not been defined") } if s.running { return fmt.Errorf("Server already running") } s.server = server() // Start listening for requests s.startGrpcService() return nil }
go
func (s *GrpcServer) StartWithServer(server func() *grpc.Server) error { s.lock.Lock() defer s.lock.Unlock() if server == nil { return fmt.Errorf("Server function has not been defined") } if s.running { return fmt.Errorf("Server already running") } s.server = server() // Start listening for requests s.startGrpcService() return nil }
[ "func", "(", "s", "*", "GrpcServer", ")", "StartWithServer", "(", "server", "func", "(", ")", "*", "grpc", ".", "Server", ")", "error", "{", "s", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "lock", ".", "Unlock", "(", ")", "\n\n", "if", "server", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "s", ".", "running", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "s", ".", "server", "=", "server", "(", ")", "\n\n", "// Start listening for requests", "s", ".", "startGrpcService", "(", ")", "\n", "return", "nil", "\n", "}" ]
// StartWithServer is used to start the server. // It will return an error if the server is already runnig.
[ "StartWithServer", "is", "used", "to", "start", "the", "server", ".", "It", "will", "return", "an", "error", "if", "the", "server", "is", "already", "runnig", "." ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/grpcserver/grpcserver.go#L93-L110
train
libopenstorage/openstorage
pkg/grpcserver/grpcserver.go
startGrpcService
func (s *GrpcServer) startGrpcService() { // Start listening for requests reflection.Register(s.server) logrus.Infof("%s gRPC Server ready on %s", s.name, s.Address()) waitForServer := make(chan bool) s.goServe(waitForServer) <-waitForServer s.running = true }
go
func (s *GrpcServer) startGrpcService() { // Start listening for requests reflection.Register(s.server) logrus.Infof("%s gRPC Server ready on %s", s.name, s.Address()) waitForServer := make(chan bool) s.goServe(waitForServer) <-waitForServer s.running = true }
[ "func", "(", "s", "*", "GrpcServer", ")", "startGrpcService", "(", ")", "{", "// Start listening for requests", "reflection", ".", "Register", "(", "s", ".", "server", ")", "\n", "logrus", ".", "Infof", "(", "\"", "\"", ",", "s", ".", "name", ",", "s", ".", "Address", "(", ")", ")", "\n", "waitForServer", ":=", "make", "(", "chan", "bool", ")", "\n", "s", ".", "goServe", "(", "waitForServer", ")", "\n", "<-", "waitForServer", "\n", "s", ".", "running", "=", "true", "\n", "}" ]
// Lock must have been taken
[ "Lock", "must", "have", "been", "taken" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/grpcserver/grpcserver.go#L113-L121
train
libopenstorage/openstorage
pkg/grpcserver/grpcserver.go
Stop
func (s *GrpcServer) Stop() { s.lock.Lock() defer s.lock.Unlock() if !s.running { return } s.server.Stop() s.wg.Wait() s.running = false }
go
func (s *GrpcServer) Stop() { s.lock.Lock() defer s.lock.Unlock() if !s.running { return } s.server.Stop() s.wg.Wait() s.running = false }
[ "func", "(", "s", "*", "GrpcServer", ")", "Stop", "(", ")", "{", "s", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "lock", ".", "Unlock", "(", ")", "\n\n", "if", "!", "s", ".", "running", "{", "return", "\n", "}", "\n\n", "s", ".", "server", ".", "Stop", "(", ")", "\n", "s", ".", "wg", ".", "Wait", "(", ")", "\n", "s", ".", "running", "=", "false", "\n", "}" ]
// Stop is used to stop the gRPC server. // It can be called multiple times. It does nothing if the server // has already been stopped.
[ "Stop", "is", "used", "to", "stop", "the", "gRPC", "server", ".", "It", "can", "be", "called", "multiple", "times", ".", "It", "does", "nothing", "if", "the", "server", "has", "already", "been", "stopped", "." ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/grpcserver/grpcserver.go#L126-L137
train
libopenstorage/openstorage
pkg/grpcserver/grpcserver.go
IsRunning
func (s *GrpcServer) IsRunning() bool { s.lock.Lock() defer s.lock.Unlock() return s.running }
go
func (s *GrpcServer) IsRunning() bool { s.lock.Lock() defer s.lock.Unlock() return s.running }
[ "func", "(", "s", "*", "GrpcServer", ")", "IsRunning", "(", ")", "bool", "{", "s", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "lock", ".", "Unlock", "(", ")", "\n\n", "return", "s", ".", "running", "\n", "}" ]
// IsRunning returns true if the server is currently running
[ "IsRunning", "returns", "true", "if", "the", "server", "is", "currently", "running" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/grpcserver/grpcserver.go#L146-L151
train
libopenstorage/openstorage
osdconfig/api.go
GetClusterConf
func (manager *configManager) GetClusterConf() (*ClusterConfig, error) { // get json from kvdb and unmarshal into config kvPair, err := manager.kv.Get(filepath.Join(baseKey, clusterKey)) if err != nil { return nil, err } config := new(ClusterConfig) if err := json.Unmarshal(kvPair.Value, config); err != nil { return nil, err } return config, nil }
go
func (manager *configManager) GetClusterConf() (*ClusterConfig, error) { // get json from kvdb and unmarshal into config kvPair, err := manager.kv.Get(filepath.Join(baseKey, clusterKey)) if err != nil { return nil, err } config := new(ClusterConfig) if err := json.Unmarshal(kvPair.Value, config); err != nil { return nil, err } return config, nil }
[ "func", "(", "manager", "*", "configManager", ")", "GetClusterConf", "(", ")", "(", "*", "ClusterConfig", ",", "error", ")", "{", "// get json from kvdb and unmarshal into config", "kvPair", ",", "err", ":=", "manager", ".", "kv", ".", "Get", "(", "filepath", ".", "Join", "(", "baseKey", ",", "clusterKey", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "config", ":=", "new", "(", "ClusterConfig", ")", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "kvPair", ".", "Value", ",", "config", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "config", ",", "nil", "\n", "}" ]
// GetClusterConf retrieves cluster level data from kvdb
[ "GetClusterConf", "retrieves", "cluster", "level", "data", "from", "kvdb" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/osdconfig/api.go#L10-L23
train
libopenstorage/openstorage
osdconfig/api.go
SetClusterConf
func (manager *configManager) SetClusterConf(config *ClusterConfig) error { if config == nil { return fmt.Errorf("input cannot be nil") } manager.Lock() defer manager.Unlock() // push into kvdb if _, err := manager.kv.Put(filepath.Join(baseKey, clusterKey), config, 0); err != nil { return err } return nil }
go
func (manager *configManager) SetClusterConf(config *ClusterConfig) error { if config == nil { return fmt.Errorf("input cannot be nil") } manager.Lock() defer manager.Unlock() // push into kvdb if _, err := manager.kv.Put(filepath.Join(baseKey, clusterKey), config, 0); err != nil { return err } return nil }
[ "func", "(", "manager", "*", "configManager", ")", "SetClusterConf", "(", "config", "*", "ClusterConfig", ")", "error", "{", "if", "config", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "manager", ".", "Lock", "(", ")", "\n", "defer", "manager", ".", "Unlock", "(", ")", "\n\n", "// push into kvdb", "if", "_", ",", "err", ":=", "manager", ".", "kv", ".", "Put", "(", "filepath", ".", "Join", "(", "baseKey", ",", "clusterKey", ")", ",", "config", ",", "0", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// SetClusterConf sets cluster config in kvdb
[ "SetClusterConf", "sets", "cluster", "config", "in", "kvdb" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/osdconfig/api.go#L26-L40
train
libopenstorage/openstorage
osdconfig/api.go
GetNodeConf
func (manager *configManager) GetNodeConf(nodeID string) (*NodeConfig, error) { if len(nodeID) == 0 { return nil, fmt.Errorf("input cannot be nil") } // get json from kvdb and unmarshal into config kvPair, err := manager.kv.Get(getNodeKeyFromNodeID(nodeID)) if err != nil { return nil, err } config := new(NodeConfig) if err = json.Unmarshal(kvPair.Value, config); err != nil { return nil, err } return config, nil }
go
func (manager *configManager) GetNodeConf(nodeID string) (*NodeConfig, error) { if len(nodeID) == 0 { return nil, fmt.Errorf("input cannot be nil") } // get json from kvdb and unmarshal into config kvPair, err := manager.kv.Get(getNodeKeyFromNodeID(nodeID)) if err != nil { return nil, err } config := new(NodeConfig) if err = json.Unmarshal(kvPair.Value, config); err != nil { return nil, err } return config, nil }
[ "func", "(", "manager", "*", "configManager", ")", "GetNodeConf", "(", "nodeID", "string", ")", "(", "*", "NodeConfig", ",", "error", ")", "{", "if", "len", "(", "nodeID", ")", "==", "0", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// get json from kvdb and unmarshal into config", "kvPair", ",", "err", ":=", "manager", ".", "kv", ".", "Get", "(", "getNodeKeyFromNodeID", "(", "nodeID", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "config", ":=", "new", "(", "NodeConfig", ")", "\n", "if", "err", "=", "json", ".", "Unmarshal", "(", "kvPair", ".", "Value", ",", "config", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "config", ",", "nil", "\n", "}" ]
// GetNodeConf retrieves node config data using nodeID
[ "GetNodeConf", "retrieves", "node", "config", "data", "using", "nodeID" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/osdconfig/api.go#L43-L60
train
libopenstorage/openstorage
osdconfig/api.go
SetNodeConf
func (manager *configManager) SetNodeConf(config *NodeConfig) error { if config == nil { return fmt.Errorf("input cannot be nil") } if len(config.NodeId) == 0 { return fmt.Errorf("node id cannot be nil") } manager.Lock() defer manager.Unlock() // push node data into kvdb if _, err := manager.kv.Put(getNodeKeyFromNodeID(config.NodeId), config, 0); err != nil { return err } return nil }
go
func (manager *configManager) SetNodeConf(config *NodeConfig) error { if config == nil { return fmt.Errorf("input cannot be nil") } if len(config.NodeId) == 0 { return fmt.Errorf("node id cannot be nil") } manager.Lock() defer manager.Unlock() // push node data into kvdb if _, err := manager.kv.Put(getNodeKeyFromNodeID(config.NodeId), config, 0); err != nil { return err } return nil }
[ "func", "(", "manager", "*", "configManager", ")", "SetNodeConf", "(", "config", "*", "NodeConfig", ")", "error", "{", "if", "config", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "len", "(", "config", ".", "NodeId", ")", "==", "0", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "manager", ".", "Lock", "(", ")", "\n", "defer", "manager", ".", "Unlock", "(", ")", "\n\n", "// push node data into kvdb", "if", "_", ",", "err", ":=", "manager", ".", "kv", ".", "Put", "(", "getNodeKeyFromNodeID", "(", "config", ".", "NodeId", ")", ",", "config", ",", "0", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// SetNodeConf sets node config data in kvdb
[ "SetNodeConf", "sets", "node", "config", "data", "in", "kvdb" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/osdconfig/api.go#L63-L81
train
libopenstorage/openstorage
osdconfig/api.go
DeleteNodeConf
func (manager *configManager) DeleteNodeConf(nodeID string) error { if len(nodeID) == 0 { return fmt.Errorf("node id cannot be nil") } manager.Lock() defer manager.Unlock() // remove dode data from kvdb if _, err := manager.kv.Delete(getNodeKeyFromNodeID(nodeID)); err != nil { return err } return nil }
go
func (manager *configManager) DeleteNodeConf(nodeID string) error { if len(nodeID) == 0 { return fmt.Errorf("node id cannot be nil") } manager.Lock() defer manager.Unlock() // remove dode data from kvdb if _, err := manager.kv.Delete(getNodeKeyFromNodeID(nodeID)); err != nil { return err } return nil }
[ "func", "(", "manager", "*", "configManager", ")", "DeleteNodeConf", "(", "nodeID", "string", ")", "error", "{", "if", "len", "(", "nodeID", ")", "==", "0", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "manager", ".", "Lock", "(", ")", "\n", "defer", "manager", ".", "Unlock", "(", ")", "\n\n", "// remove dode data from kvdb", "if", "_", ",", "err", ":=", "manager", ".", "kv", ".", "Delete", "(", "getNodeKeyFromNodeID", "(", "nodeID", ")", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// DeleteNodeConf deletes node config data in kvdb
[ "DeleteNodeConf", "deletes", "node", "config", "data", "in", "kvdb" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/osdconfig/api.go#L84-L98
train
libopenstorage/openstorage
osdconfig/api.go
EnumerateNodeConf
func (manager *configManager) EnumerateNodeConf() (*NodesConfig, error) { keys, err := manager.kv.Keys(filepath.Join(baseKey, nodeKey), "/") if err != nil { return nil, fmt.Errorf("kvdb.Keys() returned error: " + err.Error()) } nodesConfig := new(NodesConfig) *nodesConfig = make([]*NodeConfig, len(keys)) for i, key := range keys { key := key nodeConfig, err := manager.GetNodeConf(key) if err != nil { return nil, err } (*nodesConfig)[i] = nodeConfig } return nodesConfig, nil }
go
func (manager *configManager) EnumerateNodeConf() (*NodesConfig, error) { keys, err := manager.kv.Keys(filepath.Join(baseKey, nodeKey), "/") if err != nil { return nil, fmt.Errorf("kvdb.Keys() returned error: " + err.Error()) } nodesConfig := new(NodesConfig) *nodesConfig = make([]*NodeConfig, len(keys)) for i, key := range keys { key := key nodeConfig, err := manager.GetNodeConf(key) if err != nil { return nil, err } (*nodesConfig)[i] = nodeConfig } return nodesConfig, nil }
[ "func", "(", "manager", "*", "configManager", ")", "EnumerateNodeConf", "(", ")", "(", "*", "NodesConfig", ",", "error", ")", "{", "keys", ",", "err", ":=", "manager", ".", "kv", ".", "Keys", "(", "filepath", ".", "Join", "(", "baseKey", ",", "nodeKey", ")", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", "+", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n\n", "nodesConfig", ":=", "new", "(", "NodesConfig", ")", "\n", "*", "nodesConfig", "=", "make", "(", "[", "]", "*", "NodeConfig", ",", "len", "(", "keys", ")", ")", "\n", "for", "i", ",", "key", ":=", "range", "keys", "{", "key", ":=", "key", "\n", "nodeConfig", ",", "err", ":=", "manager", ".", "GetNodeConf", "(", "key", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "(", "*", "nodesConfig", ")", "[", "i", "]", "=", "nodeConfig", "\n", "}", "\n\n", "return", "nodesConfig", ",", "nil", "\n", "}" ]
// EnumerateNodeConf fetches data for all nodes
[ "EnumerateNodeConf", "fetches", "data", "for", "all", "nodes" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/osdconfig/api.go#L101-L119
train
libopenstorage/openstorage
osdconfig/api.go
WatchCluster
func (manager *configManager) WatchCluster(name string, cb func(config *ClusterConfig) error) error { manager.Lock() defer manager.Unlock() if _, present := manager.cbCluster[name]; present { return fmt.Errorf("%s already present", name) } manager.cbCluster[name] = cb return nil }
go
func (manager *configManager) WatchCluster(name string, cb func(config *ClusterConfig) error) error { manager.Lock() defer manager.Unlock() if _, present := manager.cbCluster[name]; present { return fmt.Errorf("%s already present", name) } manager.cbCluster[name] = cb return nil }
[ "func", "(", "manager", "*", "configManager", ")", "WatchCluster", "(", "name", "string", ",", "cb", "func", "(", "config", "*", "ClusterConfig", ")", "error", ")", "error", "{", "manager", ".", "Lock", "(", ")", "\n", "defer", "manager", ".", "Unlock", "(", ")", "\n\n", "if", "_", ",", "present", ":=", "manager", ".", "cbCluster", "[", "name", "]", ";", "present", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "name", ")", "\n", "}", "\n", "manager", ".", "cbCluster", "[", "name", "]", "=", "cb", "\n", "return", "nil", "\n", "}" ]
// WatchCluster registers user defined function as callback and sets a watch for changes // to cluster configuration
[ "WatchCluster", "registers", "user", "defined", "function", "as", "callback", "and", "sets", "a", "watch", "for", "changes", "to", "cluster", "configuration" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/osdconfig/api.go#L123-L132
train
libopenstorage/openstorage
osdconfig/api.go
WatchNode
func (manager *configManager) WatchNode(name string, cb func(config *NodeConfig) error) error { manager.Lock() defer manager.Unlock() if _, present := manager.cbNode[name]; present { return fmt.Errorf("%s already present", name) } manager.cbNode[name] = cb return nil }
go
func (manager *configManager) WatchNode(name string, cb func(config *NodeConfig) error) error { manager.Lock() defer manager.Unlock() if _, present := manager.cbNode[name]; present { return fmt.Errorf("%s already present", name) } manager.cbNode[name] = cb return nil }
[ "func", "(", "manager", "*", "configManager", ")", "WatchNode", "(", "name", "string", ",", "cb", "func", "(", "config", "*", "NodeConfig", ")", "error", ")", "error", "{", "manager", ".", "Lock", "(", ")", "\n", "defer", "manager", ".", "Unlock", "(", ")", "\n\n", "if", "_", ",", "present", ":=", "manager", ".", "cbNode", "[", "name", "]", ";", "present", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "name", ")", "\n", "}", "\n", "manager", ".", "cbNode", "[", "name", "]", "=", "cb", "\n", "return", "nil", "\n", "}" ]
// WatchNode registers user defined function as callback and sets a watch for changes // to node configuration
[ "WatchNode", "registers", "user", "defined", "function", "as", "callback", "and", "sets", "a", "watch", "for", "changes", "to", "node", "configuration" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/osdconfig/api.go#L136-L145
train
libopenstorage/openstorage
pkg/mount/mount.go
Mount
func (m *DefaultMounter) Mount( source string, target string, fstype string, flags uintptr, data string, timeout int, ) error { return syscall.Mount(source, target, fstype, flags, data) }
go
func (m *DefaultMounter) Mount( source string, target string, fstype string, flags uintptr, data string, timeout int, ) error { return syscall.Mount(source, target, fstype, flags, data) }
[ "func", "(", "m", "*", "DefaultMounter", ")", "Mount", "(", "source", "string", ",", "target", "string", ",", "fstype", "string", ",", "flags", "uintptr", ",", "data", "string", ",", "timeout", "int", ",", ")", "error", "{", "return", "syscall", ".", "Mount", "(", "source", ",", "target", ",", "fstype", ",", "flags", ",", "data", ")", "\n", "}" ]
// Mount default mount implementation is syscall.
[ "Mount", "default", "mount", "implementation", "is", "syscall", "." ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/mount/mount.go#L157-L166
train
libopenstorage/openstorage
pkg/mount/mount.go
Unmount
func (m *DefaultMounter) Unmount(target string, flags int, timeout int) error { return syscall.Unmount(target, flags) }
go
func (m *DefaultMounter) Unmount(target string, flags int, timeout int) error { return syscall.Unmount(target, flags) }
[ "func", "(", "m", "*", "DefaultMounter", ")", "Unmount", "(", "target", "string", ",", "flags", "int", ",", "timeout", "int", ")", "error", "{", "return", "syscall", ".", "Unmount", "(", "target", ",", "flags", ")", "\n", "}" ]
// Unmount default unmount implementation is syscall.
[ "Unmount", "default", "unmount", "implementation", "is", "syscall", "." ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/mount/mount.go#L169-L171
train
libopenstorage/openstorage
pkg/mount/mount.go
String
func (m *Mounter) String() string { s := struct { mounts DeviceMap paths PathMap allowedDirs []string trashLocation string }{ mounts: m.mounts, paths: m.paths, allowedDirs: m.allowedDirs, trashLocation: m.trashLocation, } return fmt.Sprintf("%#v", s) }
go
func (m *Mounter) String() string { s := struct { mounts DeviceMap paths PathMap allowedDirs []string trashLocation string }{ mounts: m.mounts, paths: m.paths, allowedDirs: m.allowedDirs, trashLocation: m.trashLocation, } return fmt.Sprintf("%#v", s) }
[ "func", "(", "m", "*", "Mounter", ")", "String", "(", ")", "string", "{", "s", ":=", "struct", "{", "mounts", "DeviceMap", "\n", "paths", "PathMap", "\n", "allowedDirs", "[", "]", "string", "\n", "trashLocation", "string", "\n", "}", "{", "mounts", ":", "m", ".", "mounts", ",", "paths", ":", "m", ".", "paths", ",", "allowedDirs", ":", "m", ".", "allowedDirs", ",", "trashLocation", ":", "m", ".", "trashLocation", ",", "}", "\n\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ")", "\n", "}" ]
// String representation of Mounter
[ "String", "representation", "of", "Mounter" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/mount/mount.go#L174-L188
train
libopenstorage/openstorage
pkg/mount/mount.go
Inspect
func (m *Mounter) Inspect(sourcePath string) []*PathInfo { m.Lock() defer m.Unlock() v, ok := m.mounts[sourcePath] if !ok { return nil } return v.Mountpoint }
go
func (m *Mounter) Inspect(sourcePath string) []*PathInfo { m.Lock() defer m.Unlock() v, ok := m.mounts[sourcePath] if !ok { return nil } return v.Mountpoint }
[ "func", "(", "m", "*", "Mounter", ")", "Inspect", "(", "sourcePath", "string", ")", "[", "]", "*", "PathInfo", "{", "m", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "Unlock", "(", ")", "\n\n", "v", ",", "ok", ":=", "m", ".", "mounts", "[", "sourcePath", "]", "\n", "if", "!", "ok", "{", "return", "nil", "\n", "}", "\n", "return", "v", ".", "Mountpoint", "\n", "}" ]
// Inspect mount table for device
[ "Inspect", "mount", "table", "for", "device" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/mount/mount.go#L191-L200
train
libopenstorage/openstorage
pkg/mount/mount.go
Mounts
func (m *Mounter) Mounts(sourcePath string) []string { m.Lock() defer m.Unlock() v, ok := m.mounts[sourcePath] if !ok { return nil } mounts := make([]string, len(v.Mountpoint)) for i, v := range v.Mountpoint { mounts[i] = v.Path } return mounts }
go
func (m *Mounter) Mounts(sourcePath string) []string { m.Lock() defer m.Unlock() v, ok := m.mounts[sourcePath] if !ok { return nil } mounts := make([]string, len(v.Mountpoint)) for i, v := range v.Mountpoint { mounts[i] = v.Path } return mounts }
[ "func", "(", "m", "*", "Mounter", ")", "Mounts", "(", "sourcePath", "string", ")", "[", "]", "string", "{", "m", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "Unlock", "(", ")", "\n\n", "v", ",", "ok", ":=", "m", ".", "mounts", "[", "sourcePath", "]", "\n", "if", "!", "ok", "{", "return", "nil", "\n", "}", "\n\n", "mounts", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "v", ".", "Mountpoint", ")", ")", "\n", "for", "i", ",", "v", ":=", "range", "v", ".", "Mountpoint", "{", "mounts", "[", "i", "]", "=", "v", ".", "Path", "\n", "}", "\n\n", "return", "mounts", "\n", "}" ]
// Mounts returns mount table for device
[ "Mounts", "returns", "mount", "table", "for", "device" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/mount/mount.go#L203-L218
train
libopenstorage/openstorage
pkg/mount/mount.go
GetSourcePaths
func (m *Mounter) GetSourcePaths() []string { m.Lock() defer m.Unlock() sourcePaths := make([]string, len(m.mounts)) i := 0 for path := range m.mounts { sourcePaths[i] = path i++ } return sourcePaths }
go
func (m *Mounter) GetSourcePaths() []string { m.Lock() defer m.Unlock() sourcePaths := make([]string, len(m.mounts)) i := 0 for path := range m.mounts { sourcePaths[i] = path i++ } return sourcePaths }
[ "func", "(", "m", "*", "Mounter", ")", "GetSourcePaths", "(", ")", "[", "]", "string", "{", "m", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "Unlock", "(", ")", "\n\n", "sourcePaths", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "m", ".", "mounts", ")", ")", "\n", "i", ":=", "0", "\n", "for", "path", ":=", "range", "m", ".", "mounts", "{", "sourcePaths", "[", "i", "]", "=", "path", "\n", "i", "++", "\n", "}", "\n", "return", "sourcePaths", "\n", "}" ]
// GetSourcePaths returns all source paths from the mount table
[ "GetSourcePaths", "returns", "all", "source", "paths", "from", "the", "mount", "table" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/mount/mount.go#L221-L232
train
libopenstorage/openstorage
pkg/mount/mount.go
HasMounts
func (m *Mounter) HasMounts(sourcePath string) int { m.Lock() defer m.Unlock() v, ok := m.mounts[sourcePath] if !ok { return 0 } return len(v.Mountpoint) }
go
func (m *Mounter) HasMounts(sourcePath string) int { m.Lock() defer m.Unlock() v, ok := m.mounts[sourcePath] if !ok { return 0 } return len(v.Mountpoint) }
[ "func", "(", "m", "*", "Mounter", ")", "HasMounts", "(", "sourcePath", "string", ")", "int", "{", "m", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "Unlock", "(", ")", "\n\n", "v", ",", "ok", ":=", "m", ".", "mounts", "[", "sourcePath", "]", "\n", "if", "!", "ok", "{", "return", "0", "\n", "}", "\n", "return", "len", "(", "v", ".", "Mountpoint", ")", "\n", "}" ]
// HasMounts determines returns the number of mounts for the device.
[ "HasMounts", "determines", "returns", "the", "number", "of", "mounts", "for", "the", "device", "." ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/mount/mount.go#L235-L244
train
libopenstorage/openstorage
pkg/mount/mount.go
Exists
func (m *Mounter) Exists(sourcePath string, path string) (bool, error) { m.Lock() defer m.Unlock() v, ok := m.mounts[sourcePath] if !ok { return false, ErrEnoent } for _, p := range v.Mountpoint { if p.Path == path { return true, nil } } return false, nil }
go
func (m *Mounter) Exists(sourcePath string, path string) (bool, error) { m.Lock() defer m.Unlock() v, ok := m.mounts[sourcePath] if !ok { return false, ErrEnoent } for _, p := range v.Mountpoint { if p.Path == path { return true, nil } } return false, nil }
[ "func", "(", "m", "*", "Mounter", ")", "Exists", "(", "sourcePath", "string", ",", "path", "string", ")", "(", "bool", ",", "error", ")", "{", "m", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "Unlock", "(", ")", "\n\n", "v", ",", "ok", ":=", "m", ".", "mounts", "[", "sourcePath", "]", "\n", "if", "!", "ok", "{", "return", "false", ",", "ErrEnoent", "\n", "}", "\n", "for", "_", ",", "p", ":=", "range", "v", ".", "Mountpoint", "{", "if", "p", ".", "Path", "==", "path", "{", "return", "true", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "false", ",", "nil", "\n", "}" ]
// Exists scans mountpaths for specified device and returns true if path is one of the // mountpaths. ErrEnoent may be retuned if the device is not found
[ "Exists", "scans", "mountpaths", "for", "specified", "device", "and", "returns", "true", "if", "path", "is", "one", "of", "the", "mountpaths", ".", "ErrEnoent", "may", "be", "retuned", "if", "the", "device", "is", "not", "found" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/mount/mount.go#L263-L277
train
libopenstorage/openstorage
pkg/mount/mount.go
GetRootPath
func (m *Mounter) GetRootPath(mountPath string) (string, error) { m.Lock() defer m.Unlock() for _, v := range m.mounts { for _, p := range v.Mountpoint { if p.Path == mountPath { return p.Root, nil } } } return "", ErrEnoent }
go
func (m *Mounter) GetRootPath(mountPath string) (string, error) { m.Lock() defer m.Unlock() for _, v := range m.mounts { for _, p := range v.Mountpoint { if p.Path == mountPath { return p.Root, nil } } } return "", ErrEnoent }
[ "func", "(", "m", "*", "Mounter", ")", "GetRootPath", "(", "mountPath", "string", ")", "(", "string", ",", "error", ")", "{", "m", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "Unlock", "(", ")", "\n\n", "for", "_", ",", "v", ":=", "range", "m", ".", "mounts", "{", "for", "_", ",", "p", ":=", "range", "v", ".", "Mountpoint", "{", "if", "p", ".", "Path", "==", "mountPath", "{", "return", "p", ".", "Root", ",", "nil", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "\"", "\"", ",", "ErrEnoent", "\n", "}" ]
// GetRootPath scans mounts for a specified mountPath and return the // rootPath if found or returns an ErrEnoent
[ "GetRootPath", "scans", "mounts", "for", "a", "specified", "mountPath", "and", "return", "the", "rootPath", "if", "found", "or", "returns", "an", "ErrEnoent" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/mount/mount.go#L281-L293
train
libopenstorage/openstorage
pkg/mount/mount.go
GetSourcePath
func (m *Mounter) GetSourcePath(mountPath string) (string, error) { m.Lock() defer m.Unlock() for k, v := range m.mounts { for _, p := range v.Mountpoint { if p.Path == mountPath { return k, nil } } } return "", ErrEnoent }
go
func (m *Mounter) GetSourcePath(mountPath string) (string, error) { m.Lock() defer m.Unlock() for k, v := range m.mounts { for _, p := range v.Mountpoint { if p.Path == mountPath { return k, nil } } } return "", ErrEnoent }
[ "func", "(", "m", "*", "Mounter", ")", "GetSourcePath", "(", "mountPath", "string", ")", "(", "string", ",", "error", ")", "{", "m", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "Unlock", "(", ")", "\n\n", "for", "k", ",", "v", ":=", "range", "m", ".", "mounts", "{", "for", "_", ",", "p", ":=", "range", "v", ".", "Mountpoint", "{", "if", "p", ".", "Path", "==", "mountPath", "{", "return", "k", ",", "nil", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "\"", "\"", ",", "ErrEnoent", "\n", "}" ]
// GetSourcePath scans mount for a specified mountPath and returns the sourcePath // if found or returnes an ErrEnoent
[ "GetSourcePath", "scans", "mount", "for", "a", "specified", "mountPath", "and", "returns", "the", "sourcePath", "if", "found", "or", "returnes", "an", "ErrEnoent" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/mount/mount.go#L297-L309
train
libopenstorage/openstorage
pkg/mount/mount.go
reload
func (m *Mounter) reload(device string, newM *Info) error { m.Lock() defer m.Unlock() // New mountable has no mounts, delete old mounts. if newM == nil { delete(m.mounts, device) return nil } // Old mountable had no mounts, copy over new mounts. oldM, ok := m.mounts[device] if !ok { m.mounts[device] = newM return nil } // Overwrite old mount entries into new mount table, preserving refcnt. for _, oldP := range oldM.Mountpoint { for j, newP := range newM.Mountpoint { if newP.Path == oldP.Path { newM.Mountpoint[j] = oldP break } } } // Purge old mounts. m.mounts[device] = newM return nil }
go
func (m *Mounter) reload(device string, newM *Info) error { m.Lock() defer m.Unlock() // New mountable has no mounts, delete old mounts. if newM == nil { delete(m.mounts, device) return nil } // Old mountable had no mounts, copy over new mounts. oldM, ok := m.mounts[device] if !ok { m.mounts[device] = newM return nil } // Overwrite old mount entries into new mount table, preserving refcnt. for _, oldP := range oldM.Mountpoint { for j, newP := range newM.Mountpoint { if newP.Path == oldP.Path { newM.Mountpoint[j] = oldP break } } } // Purge old mounts. m.mounts[device] = newM return nil }
[ "func", "(", "m", "*", "Mounter", ")", "reload", "(", "device", "string", ",", "newM", "*", "Info", ")", "error", "{", "m", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "Unlock", "(", ")", "\n\n", "// New mountable has no mounts, delete old mounts.", "if", "newM", "==", "nil", "{", "delete", "(", "m", ".", "mounts", ",", "device", ")", "\n", "return", "nil", "\n", "}", "\n\n", "// Old mountable had no mounts, copy over new mounts.", "oldM", ",", "ok", ":=", "m", ".", "mounts", "[", "device", "]", "\n", "if", "!", "ok", "{", "m", ".", "mounts", "[", "device", "]", "=", "newM", "\n", "return", "nil", "\n", "}", "\n\n", "// Overwrite old mount entries into new mount table, preserving refcnt.", "for", "_", ",", "oldP", ":=", "range", "oldM", ".", "Mountpoint", "{", "for", "j", ",", "newP", ":=", "range", "newM", ".", "Mountpoint", "{", "if", "newP", ".", "Path", "==", "oldP", ".", "Path", "{", "newM", ".", "Mountpoint", "[", "j", "]", "=", "oldP", "\n", "break", "\n", "}", "\n", "}", "\n", "}", "\n\n", "// Purge old mounts.", "m", ".", "mounts", "[", "device", "]", "=", "newM", "\n", "return", "nil", "\n", "}" ]
// reload from newM
[ "reload", "from", "newM" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/mount/mount.go#L330-L360
train
libopenstorage/openstorage
pkg/mount/mount.go
Unmount
func (m *Mounter) Unmount( devPath string, path string, flags int, timeout int, opts map[string]string, ) error { m.Lock() // device gets overwritten if opts specifies fuse mount with // options.OptionsDeviceFuseMount. device := devPath path = normalizeMountPath(path) if value, ok := opts[options.OptionsDeviceFuseMount]; ok { // fuse mounts show-up with this key as device. device = value } info, ok := m.mounts[device] if !ok { m.Unlock() logrus.Warnf("Unable to unmount device %q path %q: %v", devPath, path, ErrEnoent.Error()) return ErrEnoent } m.Unlock() info.Lock() defer info.Unlock() for i, p := range info.Mountpoint { if p.Path != path { continue } err := m.mountImpl.Unmount(path, flags, timeout) if err != nil { return err } // Blow away this mountpoint. info.Mountpoint[i] = info.Mountpoint[len(info.Mountpoint)-1] info.Mountpoint = info.Mountpoint[0 : len(info.Mountpoint)-1] m.maybeRemoveDevice(device) if options.IsBoolOptionSet(opts, options.OptionsDeleteAfterUnmount) { m.RemoveMountPath(path, opts) } return nil } logrus.Warnf("Device %q is not mounted at path %q", device, path) return nil }
go
func (m *Mounter) Unmount( devPath string, path string, flags int, timeout int, opts map[string]string, ) error { m.Lock() // device gets overwritten if opts specifies fuse mount with // options.OptionsDeviceFuseMount. device := devPath path = normalizeMountPath(path) if value, ok := opts[options.OptionsDeviceFuseMount]; ok { // fuse mounts show-up with this key as device. device = value } info, ok := m.mounts[device] if !ok { m.Unlock() logrus.Warnf("Unable to unmount device %q path %q: %v", devPath, path, ErrEnoent.Error()) return ErrEnoent } m.Unlock() info.Lock() defer info.Unlock() for i, p := range info.Mountpoint { if p.Path != path { continue } err := m.mountImpl.Unmount(path, flags, timeout) if err != nil { return err } // Blow away this mountpoint. info.Mountpoint[i] = info.Mountpoint[len(info.Mountpoint)-1] info.Mountpoint = info.Mountpoint[0 : len(info.Mountpoint)-1] m.maybeRemoveDevice(device) if options.IsBoolOptionSet(opts, options.OptionsDeleteAfterUnmount) { m.RemoveMountPath(path, opts) } return nil } logrus.Warnf("Device %q is not mounted at path %q", device, path) return nil }
[ "func", "(", "m", "*", "Mounter", ")", "Unmount", "(", "devPath", "string", ",", "path", "string", ",", "flags", "int", ",", "timeout", "int", ",", "opts", "map", "[", "string", "]", "string", ",", ")", "error", "{", "m", ".", "Lock", "(", ")", "\n", "// device gets overwritten if opts specifies fuse mount with", "// options.OptionsDeviceFuseMount.", "device", ":=", "devPath", "\n", "path", "=", "normalizeMountPath", "(", "path", ")", "\n", "if", "value", ",", "ok", ":=", "opts", "[", "options", ".", "OptionsDeviceFuseMount", "]", ";", "ok", "{", "// fuse mounts show-up with this key as device.", "device", "=", "value", "\n", "}", "\n", "info", ",", "ok", ":=", "m", ".", "mounts", "[", "device", "]", "\n", "if", "!", "ok", "{", "m", ".", "Unlock", "(", ")", "\n", "logrus", ".", "Warnf", "(", "\"", "\"", ",", "devPath", ",", "path", ",", "ErrEnoent", ".", "Error", "(", ")", ")", "\n", "return", "ErrEnoent", "\n", "}", "\n", "m", ".", "Unlock", "(", ")", "\n", "info", ".", "Lock", "(", ")", "\n", "defer", "info", ".", "Unlock", "(", ")", "\n", "for", "i", ",", "p", ":=", "range", "info", ".", "Mountpoint", "{", "if", "p", ".", "Path", "!=", "path", "{", "continue", "\n", "}", "\n", "err", ":=", "m", ".", "mountImpl", ".", "Unmount", "(", "path", ",", "flags", ",", "timeout", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "// Blow away this mountpoint.", "info", ".", "Mountpoint", "[", "i", "]", "=", "info", ".", "Mountpoint", "[", "len", "(", "info", ".", "Mountpoint", ")", "-", "1", "]", "\n", "info", ".", "Mountpoint", "=", "info", ".", "Mountpoint", "[", "0", ":", "len", "(", "info", ".", "Mountpoint", ")", "-", "1", "]", "\n", "m", ".", "maybeRemoveDevice", "(", "device", ")", "\n", "if", "options", ".", "IsBoolOptionSet", "(", "opts", ",", "options", ".", "OptionsDeleteAfterUnmount", ")", "{", "m", ".", "RemoveMountPath", "(", "path", ",", "opts", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}", "\n", "logrus", ".", "Warnf", "(", "\"", "\"", ",", "device", ",", "path", ")", "\n", "return", "nil", "\n", "}" ]
// Unmount device at mountpoint and from the matrix. // ErrEnoent is returned if the device or mountpoint for the device is not found.
[ "Unmount", "device", "at", "mountpoint", "and", "from", "the", "matrix", ".", "ErrEnoent", "is", "returned", "if", "the", "device", "or", "mountpoint", "for", "the", "device", "is", "not", "found", "." ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/mount/mount.go#L589-L635
train
libopenstorage/openstorage
pkg/mount/mount.go
RemoveMountPath
func (m *Mounter) RemoveMountPath(mountPath string, opts map[string]string) error { if _, err := os.Stat(mountPath); err == nil { if options.IsBoolOptionSet(opts, options.OptionsWaitBeforeDelete) { hasher := md5.New() hasher.Write([]byte(mountPath)) symlinkName := hex.EncodeToString(hasher.Sum(nil)) symlinkPath := path.Join(m.trashLocation, symlinkName) if err = os.Symlink(mountPath, symlinkPath); err != nil { if !os.IsExist(err) { logrus.Errorf("Error creating sym link %s => %s. Err: %v", symlinkPath, mountPath, err) } } if _, err = sched.Instance().Schedule( func(sched.Interval) { if err = m.removeMountPath(mountPath); err != nil { return } if err = os.Remove(symlinkPath); err != nil { return } }, sched.Periodic(time.Second), time.Now().Add(mountPathRemoveDelay), true /* run only once */); err != nil { logrus.Errorf("Failed to schedule task to remove path:%v. Err: %v", mountPath, err) return err } } else { return m.removeMountPath(mountPath) } } return nil }
go
func (m *Mounter) RemoveMountPath(mountPath string, opts map[string]string) error { if _, err := os.Stat(mountPath); err == nil { if options.IsBoolOptionSet(opts, options.OptionsWaitBeforeDelete) { hasher := md5.New() hasher.Write([]byte(mountPath)) symlinkName := hex.EncodeToString(hasher.Sum(nil)) symlinkPath := path.Join(m.trashLocation, symlinkName) if err = os.Symlink(mountPath, symlinkPath); err != nil { if !os.IsExist(err) { logrus.Errorf("Error creating sym link %s => %s. Err: %v", symlinkPath, mountPath, err) } } if _, err = sched.Instance().Schedule( func(sched.Interval) { if err = m.removeMountPath(mountPath); err != nil { return } if err = os.Remove(symlinkPath); err != nil { return } }, sched.Periodic(time.Second), time.Now().Add(mountPathRemoveDelay), true /* run only once */); err != nil { logrus.Errorf("Failed to schedule task to remove path:%v. Err: %v", mountPath, err) return err } } else { return m.removeMountPath(mountPath) } } return nil }
[ "func", "(", "m", "*", "Mounter", ")", "RemoveMountPath", "(", "mountPath", "string", ",", "opts", "map", "[", "string", "]", "string", ")", "error", "{", "if", "_", ",", "err", ":=", "os", ".", "Stat", "(", "mountPath", ")", ";", "err", "==", "nil", "{", "if", "options", ".", "IsBoolOptionSet", "(", "opts", ",", "options", ".", "OptionsWaitBeforeDelete", ")", "{", "hasher", ":=", "md5", ".", "New", "(", ")", "\n", "hasher", ".", "Write", "(", "[", "]", "byte", "(", "mountPath", ")", ")", "\n", "symlinkName", ":=", "hex", ".", "EncodeToString", "(", "hasher", ".", "Sum", "(", "nil", ")", ")", "\n", "symlinkPath", ":=", "path", ".", "Join", "(", "m", ".", "trashLocation", ",", "symlinkName", ")", "\n\n", "if", "err", "=", "os", ".", "Symlink", "(", "mountPath", ",", "symlinkPath", ")", ";", "err", "!=", "nil", "{", "if", "!", "os", ".", "IsExist", "(", "err", ")", "{", "logrus", ".", "Errorf", "(", "\"", "\"", ",", "symlinkPath", ",", "mountPath", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "if", "_", ",", "err", "=", "sched", ".", "Instance", "(", ")", ".", "Schedule", "(", "func", "(", "sched", ".", "Interval", ")", "{", "if", "err", "=", "m", ".", "removeMountPath", "(", "mountPath", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "if", "err", "=", "os", ".", "Remove", "(", "symlinkPath", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "}", ",", "sched", ".", "Periodic", "(", "time", ".", "Second", ")", ",", "time", ".", "Now", "(", ")", ".", "Add", "(", "mountPathRemoveDelay", ")", ",", "true", "/* run only once */", ")", ";", "err", "!=", "nil", "{", "logrus", ".", "Errorf", "(", "\"", "\"", ",", "mountPath", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n", "}", "else", "{", "return", "m", ".", "removeMountPath", "(", "mountPath", ")", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// RemoveMountPath makes the path writeable and removes it after a fixed delay
[ "RemoveMountPath", "makes", "the", "path", "writeable", "and", "removes", "it", "after", "a", "fixed", "delay" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/mount/mount.go#L685-L721
train
libopenstorage/openstorage
pkg/mount/mount.go
New
func New( mounterType MountType, mountImpl MountImpl, identifiers []string, customMounter CustomMounter, allowedDirs []string, trashLocation string, ) (Manager, error) { if mountImpl == nil { mountImpl = &DefaultMounter{} } switch mounterType { case DeviceMount: return NewDeviceMounter(identifiers, mountImpl, allowedDirs, trashLocation) case NFSMount: return NewNFSMounter(identifiers, mountImpl, allowedDirs) case BindMount: return NewBindMounter(identifiers, mountImpl, allowedDirs, trashLocation) case CustomMount: return NewCustomMounter(identifiers, mountImpl, customMounter, allowedDirs) } return nil, ErrUnsupported }
go
func New( mounterType MountType, mountImpl MountImpl, identifiers []string, customMounter CustomMounter, allowedDirs []string, trashLocation string, ) (Manager, error) { if mountImpl == nil { mountImpl = &DefaultMounter{} } switch mounterType { case DeviceMount: return NewDeviceMounter(identifiers, mountImpl, allowedDirs, trashLocation) case NFSMount: return NewNFSMounter(identifiers, mountImpl, allowedDirs) case BindMount: return NewBindMounter(identifiers, mountImpl, allowedDirs, trashLocation) case CustomMount: return NewCustomMounter(identifiers, mountImpl, customMounter, allowedDirs) } return nil, ErrUnsupported }
[ "func", "New", "(", "mounterType", "MountType", ",", "mountImpl", "MountImpl", ",", "identifiers", "[", "]", "string", ",", "customMounter", "CustomMounter", ",", "allowedDirs", "[", "]", "string", ",", "trashLocation", "string", ",", ")", "(", "Manager", ",", "error", ")", "{", "if", "mountImpl", "==", "nil", "{", "mountImpl", "=", "&", "DefaultMounter", "{", "}", "\n", "}", "\n\n", "switch", "mounterType", "{", "case", "DeviceMount", ":", "return", "NewDeviceMounter", "(", "identifiers", ",", "mountImpl", ",", "allowedDirs", ",", "trashLocation", ")", "\n", "case", "NFSMount", ":", "return", "NewNFSMounter", "(", "identifiers", ",", "mountImpl", ",", "allowedDirs", ")", "\n", "case", "BindMount", ":", "return", "NewBindMounter", "(", "identifiers", ",", "mountImpl", ",", "allowedDirs", ",", "trashLocation", ")", "\n", "case", "CustomMount", ":", "return", "NewCustomMounter", "(", "identifiers", ",", "mountImpl", ",", "customMounter", ",", "allowedDirs", ")", "\n", "}", "\n", "return", "nil", ",", "ErrUnsupported", "\n", "}" ]
// New returns a new Mount Manager
[ "New", "returns", "a", "new", "Mount", "Manager" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/mount/mount.go#L785-L809
train
libopenstorage/openstorage
graph/drivers/chainfs/unsupported.go
Init
func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) { return nil, errUnsupported }
go
func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) { return nil, errUnsupported }
[ "func", "Init", "(", "home", "string", ",", "options", "[", "]", "string", ",", "uidMaps", ",", "gidMaps", "[", "]", "idtools", ".", "IDMap", ")", "(", "graphdriver", ".", "Driver", ",", "error", ")", "{", "return", "nil", ",", "errUnsupported", "\n", "}" ]
// Init initializes the graphdriver
[ "Init", "initializes", "the", "graphdriver" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/graph/drivers/chainfs/unsupported.go#L25-L27
train
libopenstorage/openstorage
api/status.go
StatusSimpleValueOf
func StatusSimpleValueOf(s string) (Status, error) { obj, err := simpleValueOf("status", Status_value, s) return Status(obj), err }
go
func StatusSimpleValueOf(s string) (Status, error) { obj, err := simpleValueOf("status", Status_value, s) return Status(obj), err }
[ "func", "StatusSimpleValueOf", "(", "s", "string", ")", "(", "Status", ",", "error", ")", "{", "obj", ",", "err", ":=", "simpleValueOf", "(", "\"", "\"", ",", "Status_value", ",", "s", ")", "\n", "return", "Status", "(", "obj", ")", ",", "err", "\n", "}" ]
// StatusSimpleValueOf returns the string format of Status
[ "StatusSimpleValueOf", "returns", "the", "string", "format", "of", "Status" ]
71b7f37f99c70e697aa31ca57fa8fb1404629329
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/status.go#L35-L38
train
gorilla/rpc
json/server.go
Method
func (c *CodecRequest) Method() (string, error) { if c.err == nil { return c.request.Method, nil } return "", c.err }
go
func (c *CodecRequest) Method() (string, error) { if c.err == nil { return c.request.Method, nil } return "", c.err }
[ "func", "(", "c", "*", "CodecRequest", ")", "Method", "(", ")", "(", "string", ",", "error", ")", "{", "if", "c", ".", "err", "==", "nil", "{", "return", "c", ".", "request", ".", "Method", ",", "nil", "\n", "}", "\n", "return", "\"", "\"", ",", "c", ".", "err", "\n", "}" ]
// Method returns the RPC method for the current request. // // The method uses a dotted notation as in "Service.Method".
[ "Method", "returns", "the", "RPC", "method", "for", "the", "current", "request", ".", "The", "method", "uses", "a", "dotted", "notation", "as", "in", "Service", ".", "Method", "." ]
bffcfa752ad4e523cc8f720afeb5b985ed41ae16
https://github.com/gorilla/rpc/blob/bffcfa752ad4e523cc8f720afeb5b985ed41ae16/json/server.go#L85-L90
train
gorilla/rpc
json/server.go
WriteResponse
func (c *CodecRequest) WriteResponse(w http.ResponseWriter, reply interface{}, methodErr error) error { if c.err != nil { return c.err } res := &serverResponse{ Result: reply, Error: &null, Id: c.request.Id, } if methodErr != nil { // Propagate error message as string. res.Error = methodErr.Error() // Result must be null if there was an error invoking the method. // http://json-rpc.org/wiki/specification#a1.2Response res.Result = &null } if c.request.Id == nil { // Id is null for notifications and they don't have a response. res.Id = &null } else { w.Header().Set("Content-Type", "application/json; charset=utf-8") encoder := json.NewEncoder(w) c.err = encoder.Encode(res) } return c.err }
go
func (c *CodecRequest) WriteResponse(w http.ResponseWriter, reply interface{}, methodErr error) error { if c.err != nil { return c.err } res := &serverResponse{ Result: reply, Error: &null, Id: c.request.Id, } if methodErr != nil { // Propagate error message as string. res.Error = methodErr.Error() // Result must be null if there was an error invoking the method. // http://json-rpc.org/wiki/specification#a1.2Response res.Result = &null } if c.request.Id == nil { // Id is null for notifications and they don't have a response. res.Id = &null } else { w.Header().Set("Content-Type", "application/json; charset=utf-8") encoder := json.NewEncoder(w) c.err = encoder.Encode(res) } return c.err }
[ "func", "(", "c", "*", "CodecRequest", ")", "WriteResponse", "(", "w", "http", ".", "ResponseWriter", ",", "reply", "interface", "{", "}", ",", "methodErr", "error", ")", "error", "{", "if", "c", ".", "err", "!=", "nil", "{", "return", "c", ".", "err", "\n", "}", "\n", "res", ":=", "&", "serverResponse", "{", "Result", ":", "reply", ",", "Error", ":", "&", "null", ",", "Id", ":", "c", ".", "request", ".", "Id", ",", "}", "\n", "if", "methodErr", "!=", "nil", "{", "// Propagate error message as string.", "res", ".", "Error", "=", "methodErr", ".", "Error", "(", ")", "\n", "// Result must be null if there was an error invoking the method.", "// http://json-rpc.org/wiki/specification#a1.2Response", "res", ".", "Result", "=", "&", "null", "\n", "}", "\n", "if", "c", ".", "request", ".", "Id", "==", "nil", "{", "// Id is null for notifications and they don't have a response.", "res", ".", "Id", "=", "&", "null", "\n", "}", "else", "{", "w", ".", "Header", "(", ")", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "encoder", ":=", "json", ".", "NewEncoder", "(", "w", ")", "\n", "c", ".", "err", "=", "encoder", ".", "Encode", "(", "res", ")", "\n", "}", "\n", "return", "c", ".", "err", "\n", "}" ]
// WriteResponse encodes the response and writes it to the ResponseWriter. // // The err parameter is the error resulted from calling the RPC method, // or nil if there was no error.
[ "WriteResponse", "encodes", "the", "response", "and", "writes", "it", "to", "the", "ResponseWriter", ".", "The", "err", "parameter", "is", "the", "error", "resulted", "from", "calling", "the", "RPC", "method", "or", "nil", "if", "there", "was", "no", "error", "." ]
bffcfa752ad4e523cc8f720afeb5b985ed41ae16
https://github.com/gorilla/rpc/blob/bffcfa752ad4e523cc8f720afeb5b985ed41ae16/json/server.go#L111-L136
train
gorilla/rpc
v2/server.go
HasMethod
func (s *Server) HasMethod(method string) bool { if _, _, err := s.services.get(method); err == nil { return true } return false }
go
func (s *Server) HasMethod(method string) bool { if _, _, err := s.services.get(method); err == nil { return true } return false }
[ "func", "(", "s", "*", "Server", ")", "HasMethod", "(", "method", "string", ")", "bool", "{", "if", "_", ",", "_", ",", "err", ":=", "s", ".", "services", ".", "get", "(", "method", ")", ";", "err", "==", "nil", "{", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
// HasMethod returns true if the given method is registered. // // The method uses a dotted notation as in "Service.Method".
[ "HasMethod", "returns", "true", "if", "the", "given", "method", "is", "registered", ".", "The", "method", "uses", "a", "dotted", "notation", "as", "in", "Service", ".", "Method", "." ]
bffcfa752ad4e523cc8f720afeb5b985ed41ae16
https://github.com/gorilla/rpc/blob/bffcfa752ad4e523cc8f720afeb5b985ed41ae16/v2/server.go#L139-L144
train
gorilla/rpc
map.go
register
func (m *serviceMap) register(rcvr interface{}, name string, passReq bool) error { // Setup service. s := &service{ name: name, rcvr: reflect.ValueOf(rcvr), rcvrType: reflect.TypeOf(rcvr), methods: make(map[string]*serviceMethod), passReq: passReq, } if name == "" { s.name = reflect.Indirect(s.rcvr).Type().Name() if !isExported(s.name) { return fmt.Errorf("rpc: type %q is not exported", s.name) } } if s.name == "" { return fmt.Errorf("rpc: no service name for type %q", s.rcvrType.String()) } // Setup methods. for i := 0; i < s.rcvrType.NumMethod(); i++ { method := s.rcvrType.Method(i) mtype := method.Type // offset the parameter indexes by one if the // service methods accept an HTTP request pointer var paramOffset int if passReq { paramOffset = 1 } else { paramOffset = 0 } // Method must be exported. if method.PkgPath != "" { continue } // Method needs four ins: receiver, *http.Request, *args, *reply. if mtype.NumIn() != 3+paramOffset { continue } // If the service methods accept an HTTP request pointer if passReq { // First argument must be a pointer and must be http.Request. reqType := mtype.In(1) if reqType.Kind() != reflect.Ptr || reqType.Elem() != typeOfRequest { continue } } // Next argument must be a pointer and must be exported. args := mtype.In(1 + paramOffset) if args.Kind() != reflect.Ptr || !isExportedOrBuiltin(args) { continue } // Next argument must be a pointer and must be exported. reply := mtype.In(2 + paramOffset) if reply.Kind() != reflect.Ptr || !isExportedOrBuiltin(reply) { continue } // Method needs one out: error. if mtype.NumOut() != 1 { continue } if returnType := mtype.Out(0); returnType != typeOfError { continue } s.methods[method.Name] = &serviceMethod{ method: method, argsType: args.Elem(), replyType: reply.Elem(), } } if len(s.methods) == 0 { return fmt.Errorf("rpc: %q has no exported methods of suitable type", s.name) } // Add to the map. m.mutex.Lock() defer m.mutex.Unlock() if m.services == nil { m.services = make(map[string]*service) } else if _, ok := m.services[s.name]; ok { return fmt.Errorf("rpc: service already defined: %q", s.name) } m.services[s.name] = s return nil }
go
func (m *serviceMap) register(rcvr interface{}, name string, passReq bool) error { // Setup service. s := &service{ name: name, rcvr: reflect.ValueOf(rcvr), rcvrType: reflect.TypeOf(rcvr), methods: make(map[string]*serviceMethod), passReq: passReq, } if name == "" { s.name = reflect.Indirect(s.rcvr).Type().Name() if !isExported(s.name) { return fmt.Errorf("rpc: type %q is not exported", s.name) } } if s.name == "" { return fmt.Errorf("rpc: no service name for type %q", s.rcvrType.String()) } // Setup methods. for i := 0; i < s.rcvrType.NumMethod(); i++ { method := s.rcvrType.Method(i) mtype := method.Type // offset the parameter indexes by one if the // service methods accept an HTTP request pointer var paramOffset int if passReq { paramOffset = 1 } else { paramOffset = 0 } // Method must be exported. if method.PkgPath != "" { continue } // Method needs four ins: receiver, *http.Request, *args, *reply. if mtype.NumIn() != 3+paramOffset { continue } // If the service methods accept an HTTP request pointer if passReq { // First argument must be a pointer and must be http.Request. reqType := mtype.In(1) if reqType.Kind() != reflect.Ptr || reqType.Elem() != typeOfRequest { continue } } // Next argument must be a pointer and must be exported. args := mtype.In(1 + paramOffset) if args.Kind() != reflect.Ptr || !isExportedOrBuiltin(args) { continue } // Next argument must be a pointer and must be exported. reply := mtype.In(2 + paramOffset) if reply.Kind() != reflect.Ptr || !isExportedOrBuiltin(reply) { continue } // Method needs one out: error. if mtype.NumOut() != 1 { continue } if returnType := mtype.Out(0); returnType != typeOfError { continue } s.methods[method.Name] = &serviceMethod{ method: method, argsType: args.Elem(), replyType: reply.Elem(), } } if len(s.methods) == 0 { return fmt.Errorf("rpc: %q has no exported methods of suitable type", s.name) } // Add to the map. m.mutex.Lock() defer m.mutex.Unlock() if m.services == nil { m.services = make(map[string]*service) } else if _, ok := m.services[s.name]; ok { return fmt.Errorf("rpc: service already defined: %q", s.name) } m.services[s.name] = s return nil }
[ "func", "(", "m", "*", "serviceMap", ")", "register", "(", "rcvr", "interface", "{", "}", ",", "name", "string", ",", "passReq", "bool", ")", "error", "{", "// Setup service.", "s", ":=", "&", "service", "{", "name", ":", "name", ",", "rcvr", ":", "reflect", ".", "ValueOf", "(", "rcvr", ")", ",", "rcvrType", ":", "reflect", ".", "TypeOf", "(", "rcvr", ")", ",", "methods", ":", "make", "(", "map", "[", "string", "]", "*", "serviceMethod", ")", ",", "passReq", ":", "passReq", ",", "}", "\n", "if", "name", "==", "\"", "\"", "{", "s", ".", "name", "=", "reflect", ".", "Indirect", "(", "s", ".", "rcvr", ")", ".", "Type", "(", ")", ".", "Name", "(", ")", "\n", "if", "!", "isExported", "(", "s", ".", "name", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "s", ".", "name", ")", "\n", "}", "\n", "}", "\n", "if", "s", ".", "name", "==", "\"", "\"", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "s", ".", "rcvrType", ".", "String", "(", ")", ")", "\n", "}", "\n", "// Setup methods.", "for", "i", ":=", "0", ";", "i", "<", "s", ".", "rcvrType", ".", "NumMethod", "(", ")", ";", "i", "++", "{", "method", ":=", "s", ".", "rcvrType", ".", "Method", "(", "i", ")", "\n", "mtype", ":=", "method", ".", "Type", "\n\n", "// offset the parameter indexes by one if the", "// service methods accept an HTTP request pointer", "var", "paramOffset", "int", "\n", "if", "passReq", "{", "paramOffset", "=", "1", "\n", "}", "else", "{", "paramOffset", "=", "0", "\n", "}", "\n\n", "// Method must be exported.", "if", "method", ".", "PkgPath", "!=", "\"", "\"", "{", "continue", "\n", "}", "\n", "// Method needs four ins: receiver, *http.Request, *args, *reply.", "if", "mtype", ".", "NumIn", "(", ")", "!=", "3", "+", "paramOffset", "{", "continue", "\n", "}", "\n\n", "// If the service methods accept an HTTP request pointer", "if", "passReq", "{", "// First argument must be a pointer and must be http.Request.", "reqType", ":=", "mtype", ".", "In", "(", "1", ")", "\n", "if", "reqType", ".", "Kind", "(", ")", "!=", "reflect", ".", "Ptr", "||", "reqType", ".", "Elem", "(", ")", "!=", "typeOfRequest", "{", "continue", "\n", "}", "\n", "}", "\n", "// Next argument must be a pointer and must be exported.", "args", ":=", "mtype", ".", "In", "(", "1", "+", "paramOffset", ")", "\n", "if", "args", ".", "Kind", "(", ")", "!=", "reflect", ".", "Ptr", "||", "!", "isExportedOrBuiltin", "(", "args", ")", "{", "continue", "\n", "}", "\n", "// Next argument must be a pointer and must be exported.", "reply", ":=", "mtype", ".", "In", "(", "2", "+", "paramOffset", ")", "\n", "if", "reply", ".", "Kind", "(", ")", "!=", "reflect", ".", "Ptr", "||", "!", "isExportedOrBuiltin", "(", "reply", ")", "{", "continue", "\n", "}", "\n", "// Method needs one out: error.", "if", "mtype", ".", "NumOut", "(", ")", "!=", "1", "{", "continue", "\n", "}", "\n", "if", "returnType", ":=", "mtype", ".", "Out", "(", "0", ")", ";", "returnType", "!=", "typeOfError", "{", "continue", "\n", "}", "\n", "s", ".", "methods", "[", "method", ".", "Name", "]", "=", "&", "serviceMethod", "{", "method", ":", "method", ",", "argsType", ":", "args", ".", "Elem", "(", ")", ",", "replyType", ":", "reply", ".", "Elem", "(", ")", ",", "}", "\n", "}", "\n", "if", "len", "(", "s", ".", "methods", ")", "==", "0", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "s", ".", "name", ")", "\n", "}", "\n", "// Add to the map.", "m", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "mutex", ".", "Unlock", "(", ")", "\n", "if", "m", ".", "services", "==", "nil", "{", "m", ".", "services", "=", "make", "(", "map", "[", "string", "]", "*", "service", ")", "\n", "}", "else", "if", "_", ",", "ok", ":=", "m", ".", "services", "[", "s", ".", "name", "]", ";", "ok", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "s", ".", "name", ")", "\n", "}", "\n", "m", ".", "services", "[", "s", ".", "name", "]", "=", "s", "\n", "return", "nil", "\n", "}" ]
// register adds a new service using reflection to extract its methods.
[ "register", "adds", "a", "new", "service", "using", "reflection", "to", "extract", "its", "methods", "." ]
bffcfa752ad4e523cc8f720afeb5b985ed41ae16
https://github.com/gorilla/rpc/blob/bffcfa752ad4e523cc8f720afeb5b985ed41ae16/map.go#L53-L140
train
gorilla/rpc
map.go
get
func (m *serviceMap) get(method string) (*service, *serviceMethod, error) { parts := strings.Split(method, ".") if len(parts) != 2 { err := fmt.Errorf("rpc: service/method request ill-formed: %q", method) return nil, nil, err } m.mutex.Lock() service := m.services[parts[0]] m.mutex.Unlock() if service == nil { err := fmt.Errorf("rpc: can't find service %q", method) return nil, nil, err } serviceMethod := service.methods[parts[1]] if serviceMethod == nil { err := fmt.Errorf("rpc: can't find method %q", method) return nil, nil, err } return service, serviceMethod, nil }
go
func (m *serviceMap) get(method string) (*service, *serviceMethod, error) { parts := strings.Split(method, ".") if len(parts) != 2 { err := fmt.Errorf("rpc: service/method request ill-formed: %q", method) return nil, nil, err } m.mutex.Lock() service := m.services[parts[0]] m.mutex.Unlock() if service == nil { err := fmt.Errorf("rpc: can't find service %q", method) return nil, nil, err } serviceMethod := service.methods[parts[1]] if serviceMethod == nil { err := fmt.Errorf("rpc: can't find method %q", method) return nil, nil, err } return service, serviceMethod, nil }
[ "func", "(", "m", "*", "serviceMap", ")", "get", "(", "method", "string", ")", "(", "*", "service", ",", "*", "serviceMethod", ",", "error", ")", "{", "parts", ":=", "strings", ".", "Split", "(", "method", ",", "\"", "\"", ")", "\n", "if", "len", "(", "parts", ")", "!=", "2", "{", "err", ":=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "method", ")", "\n", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n", "m", ".", "mutex", ".", "Lock", "(", ")", "\n", "service", ":=", "m", ".", "services", "[", "parts", "[", "0", "]", "]", "\n", "m", ".", "mutex", ".", "Unlock", "(", ")", "\n", "if", "service", "==", "nil", "{", "err", ":=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "method", ")", "\n", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n", "serviceMethod", ":=", "service", ".", "methods", "[", "parts", "[", "1", "]", "]", "\n", "if", "serviceMethod", "==", "nil", "{", "err", ":=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "method", ")", "\n", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n", "return", "service", ",", "serviceMethod", ",", "nil", "\n", "}" ]
// get returns a registered service given a method name. // // The method name uses a dotted notation as in "Service.Method".
[ "get", "returns", "a", "registered", "service", "given", "a", "method", "name", ".", "The", "method", "name", "uses", "a", "dotted", "notation", "as", "in", "Service", ".", "Method", "." ]
bffcfa752ad4e523cc8f720afeb5b985ed41ae16
https://github.com/gorilla/rpc/blob/bffcfa752ad4e523cc8f720afeb5b985ed41ae16/map.go#L145-L164
train
gorilla/rpc
map.go
isExportedOrBuiltin
func isExportedOrBuiltin(t reflect.Type) bool { for t.Kind() == reflect.Ptr { t = t.Elem() } // PkgPath will be non-empty even for an exported type, // so we need to check the type name as well. return isExported(t.Name()) || t.PkgPath() == "" }
go
func isExportedOrBuiltin(t reflect.Type) bool { for t.Kind() == reflect.Ptr { t = t.Elem() } // PkgPath will be non-empty even for an exported type, // so we need to check the type name as well. return isExported(t.Name()) || t.PkgPath() == "" }
[ "func", "isExportedOrBuiltin", "(", "t", "reflect", ".", "Type", ")", "bool", "{", "for", "t", ".", "Kind", "(", ")", "==", "reflect", ".", "Ptr", "{", "t", "=", "t", ".", "Elem", "(", ")", "\n", "}", "\n", "// PkgPath will be non-empty even for an exported type,", "// so we need to check the type name as well.", "return", "isExported", "(", "t", ".", "Name", "(", ")", ")", "||", "t", ".", "PkgPath", "(", ")", "==", "\"", "\"", "\n", "}" ]
// isExportedOrBuiltin returns true if a type is exported or a builtin.
[ "isExportedOrBuiltin", "returns", "true", "if", "a", "type", "is", "exported", "or", "a", "builtin", "." ]
bffcfa752ad4e523cc8f720afeb5b985ed41ae16
https://github.com/gorilla/rpc/blob/bffcfa752ad4e523cc8f720afeb5b985ed41ae16/map.go#L173-L180
train
gorilla/rpc
v2/compression_selector.go
Select
func (*CompressionSelector) Select(r *http.Request) Encoder { encHeader := r.Header.Get("Accept-Encoding") encTypes := strings.FieldsFunc(encHeader, func(r rune) bool { return unicode.IsSpace(r) || r == ',' }) for _, enc := range encTypes { switch enc { case "gzip": return &gzipEncoder{} case "deflate": return &flateEncoder{} } } return DefaultEncoder }
go
func (*CompressionSelector) Select(r *http.Request) Encoder { encHeader := r.Header.Get("Accept-Encoding") encTypes := strings.FieldsFunc(encHeader, func(r rune) bool { return unicode.IsSpace(r) || r == ',' }) for _, enc := range encTypes { switch enc { case "gzip": return &gzipEncoder{} case "deflate": return &flateEncoder{} } } return DefaultEncoder }
[ "func", "(", "*", "CompressionSelector", ")", "Select", "(", "r", "*", "http", ".", "Request", ")", "Encoder", "{", "encHeader", ":=", "r", ".", "Header", ".", "Get", "(", "\"", "\"", ")", "\n", "encTypes", ":=", "strings", ".", "FieldsFunc", "(", "encHeader", ",", "func", "(", "r", "rune", ")", "bool", "{", "return", "unicode", ".", "IsSpace", "(", "r", ")", "||", "r", "==", "','", "\n", "}", ")", "\n\n", "for", "_", ",", "enc", ":=", "range", "encTypes", "{", "switch", "enc", "{", "case", "\"", "\"", ":", "return", "&", "gzipEncoder", "{", "}", "\n", "case", "\"", "\"", ":", "return", "&", "flateEncoder", "{", "}", "\n", "}", "\n", "}", "\n\n", "return", "DefaultEncoder", "\n", "}" ]
// Select method selects the correct compression encoder based on http HEADER.
[ "Select", "method", "selects", "the", "correct", "compression", "encoder", "based", "on", "http", "HEADER", "." ]
bffcfa752ad4e523cc8f720afeb5b985ed41ae16
https://github.com/gorilla/rpc/blob/bffcfa752ad4e523cc8f720afeb5b985ed41ae16/v2/compression_selector.go#L64-L80
train
gorilla/rpc
v2/json2/client.go
EncodeClientRequest
func EncodeClientRequest(method string, args interface{}) ([]byte, error) { c := &clientRequest{ Version: "2.0", Method: method, Params: args, Id: uint64(rand.Int63()), } return json.Marshal(c) }
go
func EncodeClientRequest(method string, args interface{}) ([]byte, error) { c := &clientRequest{ Version: "2.0", Method: method, Params: args, Id: uint64(rand.Int63()), } return json.Marshal(c) }
[ "func", "EncodeClientRequest", "(", "method", "string", ",", "args", "interface", "{", "}", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "c", ":=", "&", "clientRequest", "{", "Version", ":", "\"", "\"", ",", "Method", ":", "method", ",", "Params", ":", "args", ",", "Id", ":", "uint64", "(", "rand", ".", "Int63", "(", ")", ")", ",", "}", "\n", "return", "json", ".", "Marshal", "(", "c", ")", "\n", "}" ]
// EncodeClientRequest encodes parameters for a JSON-RPC client request.
[ "EncodeClientRequest", "encodes", "parameters", "for", "a", "JSON", "-", "RPC", "client", "request", "." ]
bffcfa752ad4e523cc8f720afeb5b985ed41ae16
https://github.com/gorilla/rpc/blob/bffcfa752ad4e523cc8f720afeb5b985ed41ae16/v2/json2/client.go#L42-L50
train
gorilla/rpc
v2/protorpc/server.go
ReadRequest
func (c *CodecRequest) ReadRequest(args interface{}) error { if c.err == nil { if c.request.Params != nil { c.err = json.Unmarshal(*c.request.Params, args) } else { c.err = errors.New("rpc: method request ill-formed: missing params field") } } return c.err }
go
func (c *CodecRequest) ReadRequest(args interface{}) error { if c.err == nil { if c.request.Params != nil { c.err = json.Unmarshal(*c.request.Params, args) } else { c.err = errors.New("rpc: method request ill-formed: missing params field") } } return c.err }
[ "func", "(", "c", "*", "CodecRequest", ")", "ReadRequest", "(", "args", "interface", "{", "}", ")", "error", "{", "if", "c", ".", "err", "==", "nil", "{", "if", "c", ".", "request", ".", "Params", "!=", "nil", "{", "c", ".", "err", "=", "json", ".", "Unmarshal", "(", "*", "c", ".", "request", ".", "Params", ",", "args", ")", "\n", "}", "else", "{", "c", ".", "err", "=", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "return", "c", ".", "err", "\n", "}" ]
// ReadRequest fills the request object for the RPC method.
[ "ReadRequest", "fills", "the", "request", "object", "for", "the", "RPC", "method", "." ]
bffcfa752ad4e523cc8f720afeb5b985ed41ae16
https://github.com/gorilla/rpc/blob/bffcfa752ad4e523cc8f720afeb5b985ed41ae16/v2/protorpc/server.go#L106-L115
train
gorilla/rpc
v2/protorpc/server.go
WriteResponse
func (c *CodecRequest) WriteResponse(w http.ResponseWriter, reply interface{}) { res := &serverResponse{ Result: reply, Error: &null, Id: c.request.Id, } c.writeServerResponse(w, 200, res) }
go
func (c *CodecRequest) WriteResponse(w http.ResponseWriter, reply interface{}) { res := &serverResponse{ Result: reply, Error: &null, Id: c.request.Id, } c.writeServerResponse(w, 200, res) }
[ "func", "(", "c", "*", "CodecRequest", ")", "WriteResponse", "(", "w", "http", ".", "ResponseWriter", ",", "reply", "interface", "{", "}", ")", "{", "res", ":=", "&", "serverResponse", "{", "Result", ":", "reply", ",", "Error", ":", "&", "null", ",", "Id", ":", "c", ".", "request", ".", "Id", ",", "}", "\n", "c", ".", "writeServerResponse", "(", "w", ",", "200", ",", "res", ")", "\n", "}" ]
// WriteResponse encodes the response and writes it to the ResponseWriter.
[ "WriteResponse", "encodes", "the", "response", "and", "writes", "it", "to", "the", "ResponseWriter", "." ]
bffcfa752ad4e523cc8f720afeb5b985ed41ae16
https://github.com/gorilla/rpc/blob/bffcfa752ad4e523cc8f720afeb5b985ed41ae16/v2/protorpc/server.go#L118-L125
train
gorilla/rpc
v2/json2/server.go
NewCustomCodecWithErrorMapper
func NewCustomCodecWithErrorMapper(encSel rpc.EncoderSelector, errorMapper func(error) error) *Codec { return &Codec{ encSel: encSel, errorMapper: errorMapper, } }
go
func NewCustomCodecWithErrorMapper(encSel rpc.EncoderSelector, errorMapper func(error) error) *Codec { return &Codec{ encSel: encSel, errorMapper: errorMapper, } }
[ "func", "NewCustomCodecWithErrorMapper", "(", "encSel", "rpc", ".", "EncoderSelector", ",", "errorMapper", "func", "(", "error", ")", "error", ")", "*", "Codec", "{", "return", "&", "Codec", "{", "encSel", ":", "encSel", ",", "errorMapper", ":", "errorMapper", ",", "}", "\n", "}" ]
// NewCustomCodecWithErrorMapper returns a new JSON Codec based on the passed encoder selector // and also accepts an errorMapper function. // The errorMapper function will be called if the Service implementation returns an error, with that // error as a param, replacing it by the value returned by this function. This function is intended // to decouple your service implementation from the codec itself, making possible to return abstract // errors in your service, and then mapping them here to the JSON-RPC error codes.
[ "NewCustomCodecWithErrorMapper", "returns", "a", "new", "JSON", "Codec", "based", "on", "the", "passed", "encoder", "selector", "and", "also", "accepts", "an", "errorMapper", "function", ".", "The", "errorMapper", "function", "will", "be", "called", "if", "the", "Service", "implementation", "returns", "an", "error", "with", "that", "error", "as", "a", "param", "replacing", "it", "by", "the", "value", "returned", "by", "this", "function", ".", "This", "function", "is", "intended", "to", "decouple", "your", "service", "implementation", "from", "the", "codec", "itself", "making", "possible", "to", "return", "abstract", "errors", "in", "your", "service", "and", "then", "mapping", "them", "here", "to", "the", "JSON", "-", "RPC", "error", "codes", "." ]
bffcfa752ad4e523cc8f720afeb5b985ed41ae16
https://github.com/gorilla/rpc/blob/bffcfa752ad4e523cc8f720afeb5b985ed41ae16/v2/json2/server.go#L73-L78
train
brocaar/lorawan
phypayload.go
MarshalBinary
func (k AES128Key) MarshalBinary() ([]byte, error) { b := make([]byte, len(k)) for i, v := range k { // little endian b[len(k)-i-1] = v } return b, nil }
go
func (k AES128Key) MarshalBinary() ([]byte, error) { b := make([]byte, len(k)) for i, v := range k { // little endian b[len(k)-i-1] = v } return b, nil }
[ "func", "(", "k", "AES128Key", ")", "MarshalBinary", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "b", ":=", "make", "(", "[", "]", "byte", ",", "len", "(", "k", ")", ")", "\n", "for", "i", ",", "v", ":=", "range", "k", "{", "// little endian", "b", "[", "len", "(", "k", ")", "-", "i", "-", "1", "]", "=", "v", "\n", "}", "\n", "return", "b", ",", "nil", "\n", "}" ]
// MarshalBinary encodes the key to a slice of bytes.
[ "MarshalBinary", "encodes", "the", "key", "to", "a", "slice", "of", "bytes", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/phypayload.go#L107-L114
train
brocaar/lorawan
phypayload.go
UnmarshalBinary
func (k *AES128Key) UnmarshalBinary(data []byte) error { if len(data) != len(k) { return fmt.Errorf("lorawan: %d bytes of data are expected", len(k)) } for i, v := range data { // little endian k[len(k)-i-1] = v } return nil }
go
func (k *AES128Key) UnmarshalBinary(data []byte) error { if len(data) != len(k) { return fmt.Errorf("lorawan: %d bytes of data are expected", len(k)) } for i, v := range data { // little endian k[len(k)-i-1] = v } return nil }
[ "func", "(", "k", "*", "AES128Key", ")", "UnmarshalBinary", "(", "data", "[", "]", "byte", ")", "error", "{", "if", "len", "(", "data", ")", "!=", "len", "(", "k", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "len", "(", "k", ")", ")", "\n", "}", "\n\n", "for", "i", ",", "v", ":=", "range", "data", "{", "// little endian", "k", "[", "len", "(", "k", ")", "-", "i", "-", "1", "]", "=", "v", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// UnmarshalBinary decodes the key from a slice of bytes.
[ "UnmarshalBinary", "decodes", "the", "key", "from", "a", "slice", "of", "bytes", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/phypayload.go#L117-L128
train
brocaar/lorawan
phypayload.go
SetUplinkDataMIC
func (p *PHYPayload) SetUplinkDataMIC(macVersion MACVersion, confFCnt uint32, txDR, txCh uint8, fNwkSIntKey, sNwkSIntKey AES128Key) error { mic, err := p.calculateUplinkDataMIC(macVersion, confFCnt, txDR, txCh, fNwkSIntKey, sNwkSIntKey) if err != nil { return err } p.MIC = mic return nil }
go
func (p *PHYPayload) SetUplinkDataMIC(macVersion MACVersion, confFCnt uint32, txDR, txCh uint8, fNwkSIntKey, sNwkSIntKey AES128Key) error { mic, err := p.calculateUplinkDataMIC(macVersion, confFCnt, txDR, txCh, fNwkSIntKey, sNwkSIntKey) if err != nil { return err } p.MIC = mic return nil }
[ "func", "(", "p", "*", "PHYPayload", ")", "SetUplinkDataMIC", "(", "macVersion", "MACVersion", ",", "confFCnt", "uint32", ",", "txDR", ",", "txCh", "uint8", ",", "fNwkSIntKey", ",", "sNwkSIntKey", "AES128Key", ")", "error", "{", "mic", ",", "err", ":=", "p", ".", "calculateUplinkDataMIC", "(", "macVersion", ",", "confFCnt", ",", "txDR", ",", "txCh", ",", "fNwkSIntKey", ",", "sNwkSIntKey", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "p", ".", "MIC", "=", "mic", "\n", "return", "nil", "\n", "}" ]
// SetUplinkDataMIC calculates and sets the MIC field for uplink data frames. // The confirmed frame-counter, TX data-rate TX channel index and SNwkSIntKey // are only required for LoRaWAN 1.1 and can be left blank otherwise.
[ "SetUplinkDataMIC", "calculates", "and", "sets", "the", "MIC", "field", "for", "uplink", "data", "frames", ".", "The", "confirmed", "frame", "-", "counter", "TX", "data", "-", "rate", "TX", "channel", "index", "and", "SNwkSIntKey", "are", "only", "required", "for", "LoRaWAN", "1", ".", "1", "and", "can", "be", "left", "blank", "otherwise", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/phypayload.go#L174-L181
train
brocaar/lorawan
phypayload.go
SetDownlinkDataMIC
func (p *PHYPayload) SetDownlinkDataMIC(macVersion MACVersion, confFCnt uint32, sNwkSIntKey AES128Key) error { mic, err := p.calculateDownlinkDataMIC(macVersion, confFCnt, sNwkSIntKey) if err != nil { return err } p.MIC = mic return nil }
go
func (p *PHYPayload) SetDownlinkDataMIC(macVersion MACVersion, confFCnt uint32, sNwkSIntKey AES128Key) error { mic, err := p.calculateDownlinkDataMIC(macVersion, confFCnt, sNwkSIntKey) if err != nil { return err } p.MIC = mic return nil }
[ "func", "(", "p", "*", "PHYPayload", ")", "SetDownlinkDataMIC", "(", "macVersion", "MACVersion", ",", "confFCnt", "uint32", ",", "sNwkSIntKey", "AES128Key", ")", "error", "{", "mic", ",", "err", ":=", "p", ".", "calculateDownlinkDataMIC", "(", "macVersion", ",", "confFCnt", ",", "sNwkSIntKey", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "p", ".", "MIC", "=", "mic", "\n", "return", "nil", "\n", "}" ]
// SetDownlinkDataMIC calculates and sets the MIC field for downlink data frames. // The confirmed frame-counter and is only required for LoRaWAN 1.1 and can be // left blank otherwise.
[ "SetDownlinkDataMIC", "calculates", "and", "sets", "the", "MIC", "field", "for", "downlink", "data", "frames", ".", "The", "confirmed", "frame", "-", "counter", "and", "is", "only", "required", "for", "LoRaWAN", "1", ".", "1", "and", "can", "be", "left", "blank", "otherwise", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/phypayload.go#L200-L207
train
brocaar/lorawan
phypayload.go
ValidateDownlinkDataMIC
func (p PHYPayload) ValidateDownlinkDataMIC(macVersion MACVersion, confFCnt uint32, sNwkSIntKey AES128Key) (bool, error) { mic, err := p.calculateDownlinkDataMIC(macVersion, confFCnt, sNwkSIntKey) if err != nil { return false, err } return p.MIC == mic, nil }
go
func (p PHYPayload) ValidateDownlinkDataMIC(macVersion MACVersion, confFCnt uint32, sNwkSIntKey AES128Key) (bool, error) { mic, err := p.calculateDownlinkDataMIC(macVersion, confFCnt, sNwkSIntKey) if err != nil { return false, err } return p.MIC == mic, nil }
[ "func", "(", "p", "PHYPayload", ")", "ValidateDownlinkDataMIC", "(", "macVersion", "MACVersion", ",", "confFCnt", "uint32", ",", "sNwkSIntKey", "AES128Key", ")", "(", "bool", ",", "error", ")", "{", "mic", ",", "err", ":=", "p", ".", "calculateDownlinkDataMIC", "(", "macVersion", ",", "confFCnt", ",", "sNwkSIntKey", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "return", "p", ".", "MIC", "==", "mic", ",", "nil", "\n", "}" ]
// ValidateDownlinkDataMIC validates the MIC of a downlink data frame. // In order to validate the MIC, the FCnt value must first be set to the // full 32 bit frame-counter value, as only the 16 least-significant bits // are transmitted. // The confirmed frame-counter and is only required for LoRaWAN 1.1 and can be // left blank otherwise.
[ "ValidateDownlinkDataMIC", "validates", "the", "MIC", "of", "a", "downlink", "data", "frame", ".", "In", "order", "to", "validate", "the", "MIC", "the", "FCnt", "value", "must", "first", "be", "set", "to", "the", "full", "32", "bit", "frame", "-", "counter", "value", "as", "only", "the", "16", "least", "-", "significant", "bits", "are", "transmitted", ".", "The", "confirmed", "frame", "-", "counter", "and", "is", "only", "required", "for", "LoRaWAN", "1", ".", "1", "and", "can", "be", "left", "blank", "otherwise", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/phypayload.go#L215-L221
train
brocaar/lorawan
phypayload.go
SetUplinkJoinMIC
func (p *PHYPayload) SetUplinkJoinMIC(key AES128Key) error { mic, err := p.calculateUplinkJoinMIC(key) if err != nil { return err } p.MIC = mic return nil }
go
func (p *PHYPayload) SetUplinkJoinMIC(key AES128Key) error { mic, err := p.calculateUplinkJoinMIC(key) if err != nil { return err } p.MIC = mic return nil }
[ "func", "(", "p", "*", "PHYPayload", ")", "SetUplinkJoinMIC", "(", "key", "AES128Key", ")", "error", "{", "mic", ",", "err", ":=", "p", ".", "calculateUplinkJoinMIC", "(", "key", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "p", ".", "MIC", "=", "mic", "\n", "return", "nil", "\n", "}" ]
// SetUplinkJoinMIC calculates and sets the MIC field for uplink join requests.
[ "SetUplinkJoinMIC", "calculates", "and", "sets", "the", "MIC", "field", "for", "uplink", "join", "requests", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/phypayload.go#L224-L231
train
brocaar/lorawan
phypayload.go
ValidateUplinkJoinMIC
func (p PHYPayload) ValidateUplinkJoinMIC(key AES128Key) (bool, error) { mic, err := p.calculateUplinkJoinMIC(key) if err != nil { return false, err } return p.MIC == mic, nil }
go
func (p PHYPayload) ValidateUplinkJoinMIC(key AES128Key) (bool, error) { mic, err := p.calculateUplinkJoinMIC(key) if err != nil { return false, err } return p.MIC == mic, nil }
[ "func", "(", "p", "PHYPayload", ")", "ValidateUplinkJoinMIC", "(", "key", "AES128Key", ")", "(", "bool", ",", "error", ")", "{", "mic", ",", "err", ":=", "p", ".", "calculateUplinkJoinMIC", "(", "key", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "return", "p", ".", "MIC", "==", "mic", ",", "nil", "\n", "}" ]
// ValidateUplinkJoinMIC validates the MIC of an uplink join request.
[ "ValidateUplinkJoinMIC", "validates", "the", "MIC", "of", "an", "uplink", "join", "request", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/phypayload.go#L234-L240
train
brocaar/lorawan
phypayload.go
SetDownlinkJoinMIC
func (p *PHYPayload) SetDownlinkJoinMIC(joinReqType JoinType, joinEUI EUI64, devNonce DevNonce, key AES128Key) error { mic, err := p.calculateDownlinkJoinMIC(joinReqType, joinEUI, devNonce, key) if err != nil { return err } p.MIC = mic return nil }
go
func (p *PHYPayload) SetDownlinkJoinMIC(joinReqType JoinType, joinEUI EUI64, devNonce DevNonce, key AES128Key) error { mic, err := p.calculateDownlinkJoinMIC(joinReqType, joinEUI, devNonce, key) if err != nil { return err } p.MIC = mic return nil }
[ "func", "(", "p", "*", "PHYPayload", ")", "SetDownlinkJoinMIC", "(", "joinReqType", "JoinType", ",", "joinEUI", "EUI64", ",", "devNonce", "DevNonce", ",", "key", "AES128Key", ")", "error", "{", "mic", ",", "err", ":=", "p", ".", "calculateDownlinkJoinMIC", "(", "joinReqType", ",", "joinEUI", ",", "devNonce", ",", "key", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "p", ".", "MIC", "=", "mic", "\n", "return", "nil", "\n", "}" ]
// SetDownlinkJoinMIC calculates and sets the MIC field for downlink join requests.
[ "SetDownlinkJoinMIC", "calculates", "and", "sets", "the", "MIC", "field", "for", "downlink", "join", "requests", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/phypayload.go#L243-L250
train
brocaar/lorawan
phypayload.go
EncryptFOpts
func (p *PHYPayload) EncryptFOpts(nwkSEncKey AES128Key) error { macPL, ok := p.MACPayload.(*MACPayload) if !ok { return errors.New("lorawan: MACPayload must be of type *MACPayload") } // nothing to encrypt if len(macPL.FHDR.FOpts) == 0 { return nil } var macB []byte for _, mac := range macPL.FHDR.FOpts { b, err := mac.MarshalBinary() if err != nil { return err } macB = append(macB, b...) } // aFCntDown is used on downlink when FPort > 1 var aFCntDown bool if !p.isUplink() && macPL.FPort != nil && *macPL.FPort > 0 { aFCntDown = true } data, err := EncryptFOpts(nwkSEncKey, aFCntDown, p.isUplink(), macPL.FHDR.DevAddr, macPL.FHDR.FCnt, macB) if err != nil { return err } macPL.FHDR.FOpts = []Payload{ &DataPayload{Bytes: data}, } return nil }
go
func (p *PHYPayload) EncryptFOpts(nwkSEncKey AES128Key) error { macPL, ok := p.MACPayload.(*MACPayload) if !ok { return errors.New("lorawan: MACPayload must be of type *MACPayload") } // nothing to encrypt if len(macPL.FHDR.FOpts) == 0 { return nil } var macB []byte for _, mac := range macPL.FHDR.FOpts { b, err := mac.MarshalBinary() if err != nil { return err } macB = append(macB, b...) } // aFCntDown is used on downlink when FPort > 1 var aFCntDown bool if !p.isUplink() && macPL.FPort != nil && *macPL.FPort > 0 { aFCntDown = true } data, err := EncryptFOpts(nwkSEncKey, aFCntDown, p.isUplink(), macPL.FHDR.DevAddr, macPL.FHDR.FCnt, macB) if err != nil { return err } macPL.FHDR.FOpts = []Payload{ &DataPayload{Bytes: data}, } return nil }
[ "func", "(", "p", "*", "PHYPayload", ")", "EncryptFOpts", "(", "nwkSEncKey", "AES128Key", ")", "error", "{", "macPL", ",", "ok", ":=", "p", ".", "MACPayload", ".", "(", "*", "MACPayload", ")", "\n", "if", "!", "ok", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// nothing to encrypt", "if", "len", "(", "macPL", ".", "FHDR", ".", "FOpts", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n\n", "var", "macB", "[", "]", "byte", "\n", "for", "_", ",", "mac", ":=", "range", "macPL", ".", "FHDR", ".", "FOpts", "{", "b", ",", "err", ":=", "mac", ".", "MarshalBinary", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "macB", "=", "append", "(", "macB", ",", "b", "...", ")", "\n", "}", "\n\n", "// aFCntDown is used on downlink when FPort > 1", "var", "aFCntDown", "bool", "\n", "if", "!", "p", ".", "isUplink", "(", ")", "&&", "macPL", ".", "FPort", "!=", "nil", "&&", "*", "macPL", ".", "FPort", ">", "0", "{", "aFCntDown", "=", "true", "\n", "}", "\n\n", "data", ",", "err", ":=", "EncryptFOpts", "(", "nwkSEncKey", ",", "aFCntDown", ",", "p", ".", "isUplink", "(", ")", ",", "macPL", ".", "FHDR", ".", "DevAddr", ",", "macPL", ".", "FHDR", ".", "FCnt", ",", "macB", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "macPL", ".", "FHDR", ".", "FOpts", "=", "[", "]", "Payload", "{", "&", "DataPayload", "{", "Bytes", ":", "data", "}", ",", "}", "\n\n", "return", "nil", "\n", "}" ]
// EncryptFOpts encrypts the FOpts with the given key.
[ "EncryptFOpts", "encrypts", "the", "FOpts", "with", "the", "given", "key", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/phypayload.go#L340-L376
train
brocaar/lorawan
phypayload.go
DecryptFOpts
func (p *PHYPayload) DecryptFOpts(nwkSEncKey AES128Key) error { if err := p.EncryptFOpts(nwkSEncKey); err != nil { return nil } return p.DecodeFOptsToMACCommands() }
go
func (p *PHYPayload) DecryptFOpts(nwkSEncKey AES128Key) error { if err := p.EncryptFOpts(nwkSEncKey); err != nil { return nil } return p.DecodeFOptsToMACCommands() }
[ "func", "(", "p", "*", "PHYPayload", ")", "DecryptFOpts", "(", "nwkSEncKey", "AES128Key", ")", "error", "{", "if", "err", ":=", "p", ".", "EncryptFOpts", "(", "nwkSEncKey", ")", ";", "err", "!=", "nil", "{", "return", "nil", "\n", "}", "\n\n", "return", "p", ".", "DecodeFOptsToMACCommands", "(", ")", "\n", "}" ]
// DecryptFOpts decrypts the FOpts payload and decodes it into mac-command // structures.
[ "DecryptFOpts", "decrypts", "the", "FOpts", "payload", "and", "decodes", "it", "into", "mac", "-", "command", "structures", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/phypayload.go#L380-L386
train
brocaar/lorawan
phypayload.go
EncryptFRMPayload
func (p *PHYPayload) EncryptFRMPayload(key AES128Key) error { macPL, ok := p.MACPayload.(*MACPayload) if !ok { return errors.New("lorawan: MACPayload must be of type *MACPayload") } // nothing to encrypt if len(macPL.FRMPayload) == 0 { return nil } data, err := macPL.marshalPayload() if err != nil { return err } data, err = EncryptFRMPayload(key, p.isUplink(), macPL.FHDR.DevAddr, macPL.FHDR.FCnt, data) if err != nil { return err } // store the encrypted data in a DataPayload macPL.FRMPayload = []Payload{&DataPayload{Bytes: data}} return nil }
go
func (p *PHYPayload) EncryptFRMPayload(key AES128Key) error { macPL, ok := p.MACPayload.(*MACPayload) if !ok { return errors.New("lorawan: MACPayload must be of type *MACPayload") } // nothing to encrypt if len(macPL.FRMPayload) == 0 { return nil } data, err := macPL.marshalPayload() if err != nil { return err } data, err = EncryptFRMPayload(key, p.isUplink(), macPL.FHDR.DevAddr, macPL.FHDR.FCnt, data) if err != nil { return err } // store the encrypted data in a DataPayload macPL.FRMPayload = []Payload{&DataPayload{Bytes: data}} return nil }
[ "func", "(", "p", "*", "PHYPayload", ")", "EncryptFRMPayload", "(", "key", "AES128Key", ")", "error", "{", "macPL", ",", "ok", ":=", "p", ".", "MACPayload", ".", "(", "*", "MACPayload", ")", "\n", "if", "!", "ok", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// nothing to encrypt", "if", "len", "(", "macPL", ".", "FRMPayload", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n\n", "data", ",", "err", ":=", "macPL", ".", "marshalPayload", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "data", ",", "err", "=", "EncryptFRMPayload", "(", "key", ",", "p", ".", "isUplink", "(", ")", ",", "macPL", ".", "FHDR", ".", "DevAddr", ",", "macPL", ".", "FHDR", ".", "FCnt", ",", "data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// store the encrypted data in a DataPayload", "macPL", ".", "FRMPayload", "=", "[", "]", "Payload", "{", "&", "DataPayload", "{", "Bytes", ":", "data", "}", "}", "\n\n", "return", "nil", "\n", "}" ]
// EncryptFRMPayload encrypts the FRMPayload with the given key.
[ "EncryptFRMPayload", "encrypts", "the", "FRMPayload", "with", "the", "given", "key", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/phypayload.go#L389-L414
train
brocaar/lorawan
phypayload.go
DecryptFRMPayload
func (p *PHYPayload) DecryptFRMPayload(key AES128Key) error { if err := p.EncryptFRMPayload(key); err != nil { return err } macPL, ok := p.MACPayload.(*MACPayload) if !ok { return errors.New("lorawan: MACPayload must be of type *MACPayload") } // the FRMPayload contains MAC commands, which we need to unmarshal var err error if macPL.FPort != nil && *macPL.FPort == 0 { macPL.FRMPayload, err = decodeDataPayloadToMACCommands(p.isUplink(), macPL.FRMPayload) } return err }
go
func (p *PHYPayload) DecryptFRMPayload(key AES128Key) error { if err := p.EncryptFRMPayload(key); err != nil { return err } macPL, ok := p.MACPayload.(*MACPayload) if !ok { return errors.New("lorawan: MACPayload must be of type *MACPayload") } // the FRMPayload contains MAC commands, which we need to unmarshal var err error if macPL.FPort != nil && *macPL.FPort == 0 { macPL.FRMPayload, err = decodeDataPayloadToMACCommands(p.isUplink(), macPL.FRMPayload) } return err }
[ "func", "(", "p", "*", "PHYPayload", ")", "DecryptFRMPayload", "(", "key", "AES128Key", ")", "error", "{", "if", "err", ":=", "p", ".", "EncryptFRMPayload", "(", "key", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "macPL", ",", "ok", ":=", "p", ".", "MACPayload", ".", "(", "*", "MACPayload", ")", "\n", "if", "!", "ok", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// the FRMPayload contains MAC commands, which we need to unmarshal", "var", "err", "error", "\n", "if", "macPL", ".", "FPort", "!=", "nil", "&&", "*", "macPL", ".", "FPort", "==", "0", "{", "macPL", ".", "FRMPayload", ",", "err", "=", "decodeDataPayloadToMACCommands", "(", "p", ".", "isUplink", "(", ")", ",", "macPL", ".", "FRMPayload", ")", "\n", "}", "\n\n", "return", "err", "\n", "}" ]
// DecryptFRMPayload decrypts the FRMPayload with the given key.
[ "DecryptFRMPayload", "decrypts", "the", "FRMPayload", "with", "the", "given", "key", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/phypayload.go#L417-L434
train
brocaar/lorawan
phypayload.go
MarshalText
func (p PHYPayload) MarshalText() ([]byte, error) { b, err := p.MarshalBinary() if err != nil { return nil, err } return []byte(base64.StdEncoding.EncodeToString(b)), nil }
go
func (p PHYPayload) MarshalText() ([]byte, error) { b, err := p.MarshalBinary() if err != nil { return nil, err } return []byte(base64.StdEncoding.EncodeToString(b)), nil }
[ "func", "(", "p", "PHYPayload", ")", "MarshalText", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "b", ",", "err", ":=", "p", ".", "MarshalBinary", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "[", "]", "byte", "(", "base64", ".", "StdEncoding", ".", "EncodeToString", "(", "b", ")", ")", ",", "nil", "\n", "}" ]
// MarshalText encodes the PHYPayload into base64.
[ "MarshalText", "encodes", "the", "PHYPayload", "into", "base64", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/phypayload.go#L535-L541
train
brocaar/lorawan
phypayload.go
UnmarshalText
func (p *PHYPayload) UnmarshalText(text []byte) error { b, err := base64.StdEncoding.DecodeString(string(text)) if err != nil { return err } return p.UnmarshalBinary(b) }
go
func (p *PHYPayload) UnmarshalText(text []byte) error { b, err := base64.StdEncoding.DecodeString(string(text)) if err != nil { return err } return p.UnmarshalBinary(b) }
[ "func", "(", "p", "*", "PHYPayload", ")", "UnmarshalText", "(", "text", "[", "]", "byte", ")", "error", "{", "b", ",", "err", ":=", "base64", ".", "StdEncoding", ".", "DecodeString", "(", "string", "(", "text", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "p", ".", "UnmarshalBinary", "(", "b", ")", "\n", "}" ]
// UnmarshalText decodes the PHYPayload from base64.
[ "UnmarshalText", "decodes", "the", "PHYPayload", "from", "base64", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/phypayload.go#L544-L550
train
brocaar/lorawan
phypayload.go
MarshalJSON
func (p PHYPayload) MarshalJSON() ([]byte, error) { type phyAlias PHYPayload return json.Marshal(phyAlias(p)) }
go
func (p PHYPayload) MarshalJSON() ([]byte, error) { type phyAlias PHYPayload return json.Marshal(phyAlias(p)) }
[ "func", "(", "p", "PHYPayload", ")", "MarshalJSON", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "type", "phyAlias", "PHYPayload", "\n", "return", "json", ".", "Marshal", "(", "phyAlias", "(", "p", ")", ")", "\n", "}" ]
// MarshalJSON encodes the PHYPayload into JSON.
[ "MarshalJSON", "encodes", "the", "PHYPayload", "into", "JSON", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/phypayload.go#L553-L556
train
brocaar/lorawan
applayer/multicastsetup/multicastsetup.go
GetCommandPayload
func GetCommandPayload(uplink bool, c CID) (CommandPayload, error) { v, ok := commandPayloadRegistry[uplink][c] if !ok { return nil, ErrNoPayloadForCID } return v(), nil }
go
func GetCommandPayload(uplink bool, c CID) (CommandPayload, error) { v, ok := commandPayloadRegistry[uplink][c] if !ok { return nil, ErrNoPayloadForCID } return v(), nil }
[ "func", "GetCommandPayload", "(", "uplink", "bool", ",", "c", "CID", ")", "(", "CommandPayload", ",", "error", ")", "{", "v", ",", "ok", ":=", "commandPayloadRegistry", "[", "uplink", "]", "[", "c", "]", "\n", "if", "!", "ok", "{", "return", "nil", ",", "ErrNoPayloadForCID", "\n", "}", "\n\n", "return", "v", "(", ")", ",", "nil", "\n", "}" ]
// GetCommandPayload returns a new CommandPayload for the given CID.
[ "GetCommandPayload", "returns", "a", "new", "CommandPayload", "for", "the", "given", "CID", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/applayer/multicastsetup/multicastsetup.go#L61-L68
train
brocaar/lorawan
applayer/multicastsetup/multicastsetup.go
MarshalBinary
func (c Command) MarshalBinary() ([]byte, error) { b := []byte{byte(c.CID)} if c.Payload != nil { p, err := c.Payload.MarshalBinary() if err != nil { return nil, err } b = append(b, p...) } return b, nil }
go
func (c Command) MarshalBinary() ([]byte, error) { b := []byte{byte(c.CID)} if c.Payload != nil { p, err := c.Payload.MarshalBinary() if err != nil { return nil, err } b = append(b, p...) } return b, nil }
[ "func", "(", "c", "Command", ")", "MarshalBinary", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "b", ":=", "[", "]", "byte", "{", "byte", "(", "c", ".", "CID", ")", "}", "\n\n", "if", "c", ".", "Payload", "!=", "nil", "{", "p", ",", "err", ":=", "c", ".", "Payload", ".", "MarshalBinary", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "b", "=", "append", "(", "b", ",", "p", "...", ")", "\n", "}", "\n\n", "return", "b", ",", "nil", "\n", "}" ]
// MarshalBinary encodes the command to a slice of bytes.
[ "MarshalBinary", "encodes", "the", "command", "to", "a", "slice", "of", "bytes", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/applayer/multicastsetup/multicastsetup.go#L84-L96
train
brocaar/lorawan
applayer/multicastsetup/multicastsetup.go
UnmarshalBinary
func (c *Command) UnmarshalBinary(uplink bool, data []byte) error { if len(data) == 0 { return errors.New("lorawan/applayer/multicastsetup: at least 1 byte is expected") } c.CID = CID(data[0]) p, err := GetCommandPayload(uplink, c.CID) if err != nil { if err == ErrNoPayloadForCID { return nil } return err } c.Payload = p if err := c.Payload.UnmarshalBinary(data[1:]); err != nil { return err } return nil }
go
func (c *Command) UnmarshalBinary(uplink bool, data []byte) error { if len(data) == 0 { return errors.New("lorawan/applayer/multicastsetup: at least 1 byte is expected") } c.CID = CID(data[0]) p, err := GetCommandPayload(uplink, c.CID) if err != nil { if err == ErrNoPayloadForCID { return nil } return err } c.Payload = p if err := c.Payload.UnmarshalBinary(data[1:]); err != nil { return err } return nil }
[ "func", "(", "c", "*", "Command", ")", "UnmarshalBinary", "(", "uplink", "bool", ",", "data", "[", "]", "byte", ")", "error", "{", "if", "len", "(", "data", ")", "==", "0", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "c", ".", "CID", "=", "CID", "(", "data", "[", "0", "]", ")", "\n\n", "p", ",", "err", ":=", "GetCommandPayload", "(", "uplink", ",", "c", ".", "CID", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "==", "ErrNoPayloadForCID", "{", "return", "nil", "\n", "}", "\n", "return", "err", "\n", "}", "\n\n", "c", ".", "Payload", "=", "p", "\n", "if", "err", ":=", "c", ".", "Payload", ".", "UnmarshalBinary", "(", "data", "[", "1", ":", "]", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// UnmarshalBinary decodes a slice of bytes into a command.
[ "UnmarshalBinary", "decodes", "a", "slice", "of", "bytes", "into", "a", "command", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/applayer/multicastsetup/multicastsetup.go#L99-L120
train
brocaar/lorawan
applayer/multicastsetup/multicastsetup.go
Size
func (c Command) Size() int { if c.Payload != nil { return c.Payload.Size() + 1 } return 1 }
go
func (c Command) Size() int { if c.Payload != nil { return c.Payload.Size() + 1 } return 1 }
[ "func", "(", "c", "Command", ")", "Size", "(", ")", "int", "{", "if", "c", ".", "Payload", "!=", "nil", "{", "return", "c", ".", "Payload", ".", "Size", "(", ")", "+", "1", "\n", "}", "\n", "return", "1", "\n", "}" ]
// Size returns the size of the command in bytes.
[ "Size", "returns", "the", "size", "of", "the", "command", "in", "bytes", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/applayer/multicastsetup/multicastsetup.go#L123-L128
train
brocaar/lorawan
applayer/multicastsetup/multicastsetup.go
MarshalBinary
func (c Commands) MarshalBinary() ([]byte, error) { var out []byte for _, cmd := range c { b, err := cmd.MarshalBinary() if err != nil { return nil, err } out = append(out, b...) } return out, nil }
go
func (c Commands) MarshalBinary() ([]byte, error) { var out []byte for _, cmd := range c { b, err := cmd.MarshalBinary() if err != nil { return nil, err } out = append(out, b...) } return out, nil }
[ "func", "(", "c", "Commands", ")", "MarshalBinary", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "var", "out", "[", "]", "byte", "\n\n", "for", "_", ",", "cmd", ":=", "range", "c", "{", "b", ",", "err", ":=", "cmd", ".", "MarshalBinary", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "out", "=", "append", "(", "out", ",", "b", "...", ")", "\n", "}", "\n", "return", "out", ",", "nil", "\n", "}" ]
// MarshalBinary encodes the commands to a slice of bytes.
[ "MarshalBinary", "encodes", "the", "commands", "to", "a", "slice", "of", "bytes", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/applayer/multicastsetup/multicastsetup.go#L134-L145
train
brocaar/lorawan
applayer/multicastsetup/multicastsetup.go
UnmarshalBinary
func (c *Commands) UnmarshalBinary(uplink bool, data []byte) error { var i int for i < len(data) { var cmd Command if err := cmd.UnmarshalBinary(uplink, data[i:]); err != nil { return err } i += cmd.Size() *c = append(*c, cmd) } return nil }
go
func (c *Commands) UnmarshalBinary(uplink bool, data []byte) error { var i int for i < len(data) { var cmd Command if err := cmd.UnmarshalBinary(uplink, data[i:]); err != nil { return err } i += cmd.Size() *c = append(*c, cmd) } return nil }
[ "func", "(", "c", "*", "Commands", ")", "UnmarshalBinary", "(", "uplink", "bool", ",", "data", "[", "]", "byte", ")", "error", "{", "var", "i", "int", "\n\n", "for", "i", "<", "len", "(", "data", ")", "{", "var", "cmd", "Command", "\n", "if", "err", ":=", "cmd", ".", "UnmarshalBinary", "(", "uplink", ",", "data", "[", "i", ":", "]", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "i", "+=", "cmd", ".", "Size", "(", ")", "\n", "*", "c", "=", "append", "(", "*", "c", ",", "cmd", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// UnmarshalBinary decodes a slice of bytes into a slice of commands.
[ "UnmarshalBinary", "decodes", "a", "slice", "of", "bytes", "into", "a", "slice", "of", "commands", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/applayer/multicastsetup/multicastsetup.go#L148-L161
train
brocaar/lorawan
applayer/multicastsetup/multicastsetup.go
Size
func (p McGroupStatusAnsPayload) Size() int { var ansGroupMaskCount int for _, mask := range p.Status.AnsGroupMask { if mask { ansGroupMaskCount++ } } return 1 + (5 * ansGroupMaskCount) }
go
func (p McGroupStatusAnsPayload) Size() int { var ansGroupMaskCount int for _, mask := range p.Status.AnsGroupMask { if mask { ansGroupMaskCount++ } } return 1 + (5 * ansGroupMaskCount) }
[ "func", "(", "p", "McGroupStatusAnsPayload", ")", "Size", "(", ")", "int", "{", "var", "ansGroupMaskCount", "int", "\n", "for", "_", ",", "mask", ":=", "range", "p", ".", "Status", ".", "AnsGroupMask", "{", "if", "mask", "{", "ansGroupMaskCount", "++", "\n", "}", "\n", "}", "\n\n", "return", "1", "+", "(", "5", "*", "ansGroupMaskCount", ")", "\n", "}" ]
// Size returns the payload size in number of bytes.
[ "Size", "returns", "the", "payload", "size", "in", "number", "of", "bytes", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/applayer/multicastsetup/multicastsetup.go#L251-L260
train
brocaar/lorawan
applayer/multicastsetup/keys.go
GetMcKEKey
func GetMcKEKey(mcRootKey lorawan.AES128Key) (lorawan.AES128Key, error) { return getKey(mcRootKey, [16]byte{}) }
go
func GetMcKEKey(mcRootKey lorawan.AES128Key) (lorawan.AES128Key, error) { return getKey(mcRootKey, [16]byte{}) }
[ "func", "GetMcKEKey", "(", "mcRootKey", "lorawan", ".", "AES128Key", ")", "(", "lorawan", ".", "AES128Key", ",", "error", ")", "{", "return", "getKey", "(", "mcRootKey", ",", "[", "16", "]", "byte", "{", "}", ")", "\n", "}" ]
// GetMcKEKey returns the McKEKey given the McRootKey.
[ "GetMcKEKey", "returns", "the", "McKEKey", "given", "the", "McRootKey", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/applayer/multicastsetup/keys.go#L23-L25
train
brocaar/lorawan
applayer/multicastsetup/keys.go
GetMcAppSKey
func GetMcAppSKey(mcKey lorawan.AES128Key, mcAddr lorawan.DevAddr) (lorawan.AES128Key, error) { b := [16]byte{0x01} mcAddrB, err := mcAddr.MarshalBinary() if err != nil { return lorawan.AES128Key{}, err } copy(b[1:5], mcAddrB) return getKey(mcKey, b) }
go
func GetMcAppSKey(mcKey lorawan.AES128Key, mcAddr lorawan.DevAddr) (lorawan.AES128Key, error) { b := [16]byte{0x01} mcAddrB, err := mcAddr.MarshalBinary() if err != nil { return lorawan.AES128Key{}, err } copy(b[1:5], mcAddrB) return getKey(mcKey, b) }
[ "func", "GetMcAppSKey", "(", "mcKey", "lorawan", ".", "AES128Key", ",", "mcAddr", "lorawan", ".", "DevAddr", ")", "(", "lorawan", ".", "AES128Key", ",", "error", ")", "{", "b", ":=", "[", "16", "]", "byte", "{", "0x01", "}", "\n\n", "mcAddrB", ",", "err", ":=", "mcAddr", ".", "MarshalBinary", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "lorawan", ".", "AES128Key", "{", "}", ",", "err", "\n", "}", "\n", "copy", "(", "b", "[", "1", ":", "5", "]", ",", "mcAddrB", ")", "\n\n", "return", "getKey", "(", "mcKey", ",", "b", ")", "\n", "}" ]
// GetMcAppSKey returns the McAppSKey given the McKey and McAddr.
[ "GetMcAppSKey", "returns", "the", "McAppSKey", "given", "the", "McKey", "and", "McAddr", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/applayer/multicastsetup/keys.go#L28-L38
train
brocaar/lorawan
backend/joinserver/joinserver.go
NewHandler
func NewHandler(config HandlerConfig) (http.Handler, error) { if config.GetDeviceKeysByDevEUIFunc == nil { return nil, errors.New("backend/joinserver: GetDeviceKeysFunc must not be nil") } h := handler{ config: config, log: config.Logger, } if h.log == nil { h.log = &log.Logger{ Out: ioutil.Discard, } } if h.config.GetKEKByLabelFunc == nil { h.log.Warning("backend/joinserver: get kek by label function is not set") h.config.GetKEKByLabelFunc = func(label string) ([]byte, error) { return nil, nil } } if h.config.GetASKEKLabelByDevEUIFunc == nil { h.log.Warning("backend/joinserver: get application-server kek by deveui function is not set") h.config.GetASKEKLabelByDevEUIFunc = func(devEUI lorawan.EUI64) (string, error) { return "", nil } } return &h, nil }
go
func NewHandler(config HandlerConfig) (http.Handler, error) { if config.GetDeviceKeysByDevEUIFunc == nil { return nil, errors.New("backend/joinserver: GetDeviceKeysFunc must not be nil") } h := handler{ config: config, log: config.Logger, } if h.log == nil { h.log = &log.Logger{ Out: ioutil.Discard, } } if h.config.GetKEKByLabelFunc == nil { h.log.Warning("backend/joinserver: get kek by label function is not set") h.config.GetKEKByLabelFunc = func(label string) ([]byte, error) { return nil, nil } } if h.config.GetASKEKLabelByDevEUIFunc == nil { h.log.Warning("backend/joinserver: get application-server kek by deveui function is not set") h.config.GetASKEKLabelByDevEUIFunc = func(devEUI lorawan.EUI64) (string, error) { return "", nil } } return &h, nil }
[ "func", "NewHandler", "(", "config", "HandlerConfig", ")", "(", "http", ".", "Handler", ",", "error", ")", "{", "if", "config", ".", "GetDeviceKeysByDevEUIFunc", "==", "nil", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "h", ":=", "handler", "{", "config", ":", "config", ",", "log", ":", "config", ".", "Logger", ",", "}", "\n\n", "if", "h", ".", "log", "==", "nil", "{", "h", ".", "log", "=", "&", "log", ".", "Logger", "{", "Out", ":", "ioutil", ".", "Discard", ",", "}", "\n", "}", "\n\n", "if", "h", ".", "config", ".", "GetKEKByLabelFunc", "==", "nil", "{", "h", ".", "log", ".", "Warning", "(", "\"", "\"", ")", "\n\n", "h", ".", "config", ".", "GetKEKByLabelFunc", "=", "func", "(", "label", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "}", "\n\n", "if", "h", ".", "config", ".", "GetASKEKLabelByDevEUIFunc", "==", "nil", "{", "h", ".", "log", ".", "Warning", "(", "\"", "\"", ")", "\n\n", "h", ".", "config", ".", "GetASKEKLabelByDevEUIFunc", "=", "func", "(", "devEUI", "lorawan", ".", "EUI64", ")", "(", "string", ",", "error", ")", "{", "return", "\"", "\"", ",", "nil", "\n", "}", "\n", "}", "\n\n", "return", "&", "h", ",", "nil", "\n", "}" ]
// NewHandler creates a new join-sever handler.
[ "NewHandler", "creates", "a", "new", "join", "-", "sever", "handler", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/backend/joinserver/joinserver.go#L42-L75
train
brocaar/lorawan
fhdr.go
NetIDType
func (a DevAddr) NetIDType() int { for i := 0; i < 8; i++ { if a[0]&(0xff<<(byte(7-i))) == 0xff&(0xff<<(byte(8-i))) { return i } } panic("NetIDType bug!") }
go
func (a DevAddr) NetIDType() int { for i := 0; i < 8; i++ { if a[0]&(0xff<<(byte(7-i))) == 0xff&(0xff<<(byte(8-i))) { return i } } panic("NetIDType bug!") }
[ "func", "(", "a", "DevAddr", ")", "NetIDType", "(", ")", "int", "{", "for", "i", ":=", "0", ";", "i", "<", "8", ";", "i", "++", "{", "if", "a", "[", "0", "]", "&", "(", "0xff", "<<", "(", "byte", "(", "7", "-", "i", ")", ")", ")", "==", "0xff", "&", "(", "0xff", "<<", "(", "byte", "(", "8", "-", "i", ")", ")", ")", "{", "return", "i", "\n", "}", "\n", "}", "\n", "panic", "(", "\"", "\"", ")", "\n", "}" ]
// NetIDType returns the NetID type of the DevAddr.
[ "NetIDType", "returns", "the", "NetID", "type", "of", "the", "DevAddr", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/fhdr.go#L14-L21
train
brocaar/lorawan
fhdr.go
NwkID
func (a DevAddr) NwkID() []byte { switch a.NetIDType() { case 0: return a.getNwkID(1, 6) case 1: return a.getNwkID(2, 6) case 2: return a.getNwkID(3, 9) case 3: return a.getNwkID(4, 10) case 4: return a.getNwkID(5, 11) case 5: return a.getNwkID(6, 13) case 6: return a.getNwkID(7, 15) case 7: return a.getNwkID(8, 17) default: return nil } }
go
func (a DevAddr) NwkID() []byte { switch a.NetIDType() { case 0: return a.getNwkID(1, 6) case 1: return a.getNwkID(2, 6) case 2: return a.getNwkID(3, 9) case 3: return a.getNwkID(4, 10) case 4: return a.getNwkID(5, 11) case 5: return a.getNwkID(6, 13) case 6: return a.getNwkID(7, 15) case 7: return a.getNwkID(8, 17) default: return nil } }
[ "func", "(", "a", "DevAddr", ")", "NwkID", "(", ")", "[", "]", "byte", "{", "switch", "a", ".", "NetIDType", "(", ")", "{", "case", "0", ":", "return", "a", ".", "getNwkID", "(", "1", ",", "6", ")", "\n", "case", "1", ":", "return", "a", ".", "getNwkID", "(", "2", ",", "6", ")", "\n", "case", "2", ":", "return", "a", ".", "getNwkID", "(", "3", ",", "9", ")", "\n", "case", "3", ":", "return", "a", ".", "getNwkID", "(", "4", ",", "10", ")", "\n", "case", "4", ":", "return", "a", ".", "getNwkID", "(", "5", ",", "11", ")", "\n", "case", "5", ":", "return", "a", ".", "getNwkID", "(", "6", ",", "13", ")", "\n", "case", "6", ":", "return", "a", ".", "getNwkID", "(", "7", ",", "15", ")", "\n", "case", "7", ":", "return", "a", ".", "getNwkID", "(", "8", ",", "17", ")", "\n", "default", ":", "return", "nil", "\n", "}", "\n", "}" ]
// NwkID returns the NwkID bits of the DevAddr.
[ "NwkID", "returns", "the", "NwkID", "bits", "of", "the", "DevAddr", "." ]
5bca41b178e93c384fb6442f55a2d692da890830
https://github.com/brocaar/lorawan/blob/5bca41b178e93c384fb6442f55a2d692da890830/fhdr.go#L24-L45
train