/
api.go
1390 lines (1230 loc) · 44.6 KB
/
api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package api
import (
"context"
"fmt"
"math"
"strconv"
"strings"
"time"
"github.com/golang/protobuf/ptypes"
"github.com/libopenstorage/openstorage/pkg/auth"
"github.com/mohae/deepcopy"
)
// Strings for VolumeSpec
const (
Name = "name"
Token = "token"
TokenSecret = "token_secret"
TokenSecretNamespace = "token_secret_namespace"
SpecNodes = "nodes"
SpecParent = "parent"
SpecEphemeral = "ephemeral"
SpecShared = "shared"
SpecJournal = "journal"
SpecSharedv4 = "sharedv4"
SpecCascaded = "cascaded"
SpecSticky = "sticky"
SpecSecure = "secure"
SpecCompressed = "compressed"
SpecSize = "size"
SpecScale = "scale"
SpecFilesystem = "fs"
SpecBlockSize = "block_size"
SpecQueueDepth = "queue_depth"
SpecHaLevel = "repl"
SpecPriority = "io_priority"
SpecSnapshotInterval = "snap_interval"
SpecSnapshotSchedule = "snap_schedule"
SpecAggregationLevel = "aggregation_level"
SpecDedupe = "dedupe"
SpecPassphrase = "secret_key"
SpecAutoAggregationValue = "auto"
SpecGroup = "group"
SpecGroupEnforce = "fg"
SpecZones = "zones"
SpecRacks = "racks"
SpecRack = "rack"
SpecRegions = "regions"
SpecLabels = "labels"
SpecPriorityAlias = "priority_io"
SpecIoProfile = "io_profile"
SpecAsyncIo = "async_io"
SpecEarlyAck = "early_ack"
SpecExportProtocol = "export"
SpecExportProtocolISCSI = "iscsi"
SpecExportProtocolPXD = "pxd"
SpecExportProtocolNFS = "nfs"
SpecExportProtocolCustom = "custom"
SpecExportOptions = "export_options"
SpecExportOptionsEmpty = "empty_export_options"
SpecMountOptions = "mount_options"
// spec key cannot change due to parity with existing PSO storageclasses
SpecFaCreateOptions = "createoptions"
SpecCSIMountOptions = "csi_mount_options"
SpecSharedv4MountOptions = "sharedv4_mount_options"
SpecProxyProtocolS3 = "s3"
SpecProxyProtocolPXD = "pxd"
SpecProxyProtocolNFS = "nfs"
SpecProxyEndpoint = "proxy_endpoint"
SpecProxyNFSSubPath = "proxy_nfs_subpath"
SpecProxyNFSExportPath = "proxy_nfs_exportpath"
SpecProxyS3Bucket = "proxy_s3_bucket"
// SpecBestEffortLocationProvisioning default is false. If set provisioning request will succeed
// even if specified data location parameters could not be satisfied.
SpecBestEffortLocationProvisioning = "best_effort_location_provisioning"
// SpecForceUnsuppportedFsType is of type boolean and if true it sets
// the VolumeSpec.force_unsupported_fs_type. When set to true it asks
// the driver to use an unsupported value of VolumeSpec.format if possible
SpecForceUnsupportedFsType = "force_unsupported_fs_type"
// SpecMatchSrcVolProvision defaults to false. Applicable to cloudbackup restores only.
// If set to "true", cloudbackup restore volume gets provisioned on same pools as
// backup, allowing for inplace restore after.
SpecMatchSrcVolProvision = "match_src_vol_provision"
SpecNodiscard = "nodiscard"
StoragePolicy = "storagepolicy"
SpecCowOnDemand = "cow_ondemand"
SpecDirectIo = "direct_io"
SpecScanPolicyTrigger = "scan_policy_trigger"
SpecScanPolicyAction = "scan_policy_action"
SpecProxyWrite = "proxy_write"
SpecFastpath = "fastpath"
SpecSharedv4ServiceType = "sharedv4_svc_type"
SpecSharedv4ServiceName = "sharedv4_svc_name"
SpecSharedv4FailoverStrategy = "sharedv4_failover_strategy"
SpecSharedv4FailoverStrategyNormal = "normal"
SpecSharedv4FailoverStrategyAggressive = "aggressive"
SpecSharedv4FailoverStrategyUnspecified = ""
SpecSharedv4ExternalAccess = "sharedv4_external_access"
SpecAutoFstrim = "auto_fstrim"
SpecBackendVolName = "pure_vol_name"
SpecBackendType = "backend"
SpecBackendPureBlock = "pure_block"
SpecBackendPureFile = "pure_file"
SpecPureFileExportRules = "pure_export_rules"
SpecIoThrottleRdIOPS = "io_throttle_rd_iops"
SpecIoThrottleWrIOPS = "io_throttle_wr_iops"
SpecIoThrottleRdBW = "io_throttle_rd_bw"
SpecIoThrottleWrBW = "io_throttle_wr_bw"
)
// OptionKey specifies a set of recognized query params.
const (
// OptName query parameter used to lookup volume by name.
OptName = "Name"
// OptVolumeID query parameter used to lookup volume by ID.
OptVolumeID = "VolumeID"
// OptSnapID query parameter used to lookup snapshot by ID.
OptSnapID = "SnapID"
// OptLabel query parameter used to lookup volume by set of labels.
OptLabel = "Label"
// OptConfigLabel query parameter used to lookup volume by set of labels.
OptConfigLabel = "ConfigLabel"
// OptCumulative query parameter used to request cumulative stats.
OptCumulative = "Cumulative"
// OptTimeout query parameter used to indicate timeout seconds
OptTimeoutSec = "TimeoutSec"
// OptQuiesceID query parameter use for quiesce
OptQuiesceID = "QuiesceID"
// OptCredUUID is the UUID of the credential
OptCredUUID = "CredUUID"
// OptCredName indicates unique name of credential
OptCredName = "CredName"
// OptCredType indicates type of credential
OptCredType = "CredType"
// OptCredEncrKey is the key used to encrypt data
OptCredEncrKey = "CredEncrypt"
// OptCredRegion indicates the region for s3
OptCredRegion = "CredRegion"
// OptCredDisableSSL indicated if SSL should be disabled
OptCredDisableSSL = "CredDisableSSL"
// OptCredDisablePathStyle does not enforce path style for s3
OptCredDisablePathStyle = "CredDisablePathStyle"
// OptCredStorageClass indicates the storage class to be used for puts
// allowed values are STANDARD, STANDARD_IA,ONEZONE_IA, REDUCED_REDUNDANCY
OptCredStorageClass = "CredStorageClass"
// OptCredEndpoint indicate the cloud endpoint
OptCredEndpoint = "CredEndpoint"
// OptCredAccKey for s3
OptCredAccessKey = "CredAccessKey"
// OptCredSecretKey for s3
OptCredSecretKey = "CredSecretKey"
// OptCredBucket is the optional bucket name
OptCredBucket = "CredBucket"
// OptCredGoogleProjectID projectID for google cloud
OptCredGoogleProjectID = "CredProjectID"
// OptCredGoogleJsonKey for google cloud
OptCredGoogleJsonKey = "CredJsonKey"
// OptCredAzureAccountName is the account name for
// azure as the cloud provider
OptCredAzureAccountName = "CredAccountName"
// OptOptCredAzureAccountKey is the accountkey for
// azure as the cloud provider
OptCredAzureAccountKey = "CredAccountKey"
// Credential ownership key in params
OptCredOwnership = "CredOwnership"
// OptCredProxy proxy key in params
OptCredProxy = "CredProxy"
// OptCredNFSServer is the server address for NFS access
OptCredNFSServer = "CredNFSServer"
// OptCredNFSSubPath is the sub-path for objects
OptCredNFSSubPath = "CredNFSSubPath"
// OptCredNFSMountOpts is the optional mount options
OptCredNFSMountOpts = "CredNFSMountOpts"
// OptCredNFSTimeout is the optional timeout value
OptCredNFSTimeoutSeconds = "CredNFSTimeout"
// OptCredIAMPolicy if "true", indicates IAM creds to be used
OptCredIAMPolicy = "CredIAMPolicy"
// OptRemoteCredUUID is the UUID of the remote cluster credential
OptRemoteCredUUID = "RemoteCredUUID"
// OptCloudBackupID is the backID in the cloud
OptCloudBackupID = "CloudBackID"
// OptCloudBackupIgnoreCreds ignores credentials for incr backups
OptCloudBackupIgnoreCreds = "CloudBackupIgnoreCreds"
// OptSrcVolID is the source volume ID of the backup
OptSrcVolID = "SrcVolID"
// OptBkupOpState is the desired operational state
// (stop/pause/resume) of backup/restore
OptBkupOpState = "OpState"
// OptBackupSchedUUID is the UUID of the backup-schedule
OptBackupSchedUUID = "BkupSchedUUID"
// OptVolumeSubFolder query parameter used to catalog a particular path inside a volume
OptCatalogSubFolder = "subfolder"
// OptCatalogMaxDepth query parameter used to limit the depth we return
OptCatalogMaxDepth = "depth"
// OptVolumeService query parameter used to request background volume services
OptVolService = "volservice"
)
// Api clientserver Constants
const (
OsdVolumePath = "osd-volumes"
OsdSnapshotPath = "osd-snapshot"
OsdCredsPath = "osd-creds"
OsdBackupPath = "osd-backup"
OsdMigratePath = "osd-migrate"
OsdMigrateStartPath = OsdMigratePath + "/start"
OsdMigrateCancelPath = OsdMigratePath + "/cancel"
OsdMigrateStatusPath = OsdMigratePath + "/status"
TimeLayout = "Jan 2 15:04:05 UTC 2006"
)
const (
// AutoAggregation value indicates driver to select aggregation level.
AutoAggregation = math.MaxUint32
)
const (
// gRPC root path used to extract service and API information
SdkRootPath = "openstorage.api.OpenStorage"
)
// Node describes the state of a node.
// It includes the current physical state (CPU, memory, storage, network usage) as
// well as the containers running on the system.
//
// swagger:model
type Node struct {
// Id of the node.
Id string
// SchedulerNodeName is name of the node in scheduler context. It can be
// empty if unable to get the name from the scheduler.
SchedulerNodeName string
// Cpu usage of the node.
Cpu float64 // percentage.
// Total Memory of the node
MemTotal uint64
// Used Memory of the node
MemUsed uint64
// Free Memory of the node
MemFree uint64
// Average load (percentage)
Avgload int
// Node Status see (Status object)
Status Status
// GenNumber of the node
GenNumber uint64
// List of disks on this node.
Disks map[string]StorageResource
// List of storage pools this node supports
Pools []StoragePool
// Management IP
MgmtIp string
// Data IP
DataIp string
// Timestamp
Timestamp time.Time
// Start time of this node
StartTime time.Time
// Hostname of this node
Hostname string
// Node data for this node (EX: Public IP, Provider, City..)
NodeData map[string]interface{}
// User defined labels for node. Key Value pairs
NodeLabels map[string]string
// GossipPort is the port used by the gossip protocol
GossipPort string
// HWType is the type of the underlying hardware used by the node
HWType HardwareType
// Determine if the node is secure with authentication and authorization
SecurityStatus StorageNode_SecurityStatus
// SchedulerTopology topology information of the node in scheduler context
SchedulerTopology *SchedulerTopology
}
// FluentDConfig describes ip and port of a fluentdhost.
// DEPRECATED
//
// swagger:model
type FluentDConfig struct {
IP string `json:"ip"`
Port string `json:"port"`
}
// Cluster represents the state of the cluster.
//
// swagger:model
type Cluster struct {
Status Status
// Id of the cluster.
//
// required: true
Id string
// Id of the node on which this cluster object is initialized
NodeId string
// array of all the nodes in the cluster.
Nodes []*Node
// Management url for the cluster
ManagementURL string
// FluentD Host for the cluster
FluentDConfig FluentDConfig
}
// CredCreateRequest is the input for CredCreate command
type CredCreateRequest struct {
// InputParams is map describing cloud provide
InputParams map[string]string
}
// CredCreateResponse is returned for CredCreate command
type CredCreateResponse struct {
// UUID of the credential that was just created
UUID string
}
// CredUpdateRequest is the input for CredsUpdate command
type CredUpdateRequest struct {
// Name or the UUID of the credential being updated
Name string
// InputParams is map describing cloud provide
InputParams map[string]string
}
// StatPoint represents the basic structure of a single Stat reported
// TODO: This is the first step to introduce stats in openstorage.
// Follow up task is to introduce an API for logging stats
type StatPoint struct {
// Name of the Stat
Name string
// Tags for the Stat
Tags map[string]string
// Fields and values of the stat
Fields map[string]interface{}
// Timestamp in Unix format
Timestamp int64
}
type CloudBackupCreateRequest struct {
// VolumeID of the volume for which cloudbackup is requested
VolumeID string
// CredentialUUID is cloud credential to be used for backup
CredentialUUID string
// Full indicates if full backup is desired even though incremental is possible
Full bool
// Name is optional unique id to be used for this backup
// If not specified backup creates this by default
Name string
// Labels are list of key value pairs to tag the cloud backup. These labels
// are stored in the metadata associated with the backup.
Labels map[string]string
// FullBackupFrequency indicates number of incremental backup after whcih
// a fullbackup must be created. This is to override the default value for
// manual/user triggerred backups and not applicable for scheduled backups.
// Value of 0 retains the default behavior.
FullBackupFrequency uint32
// DeleteLocal indicates if local snap must be deleted after the
// backup is complete
DeleteLocal bool
}
type CloudBackupCreateResponse struct {
// Name of the task performing this backup
Name string
}
type CloudBackupGroupCreateRequest struct {
// GroupID indicates backup request for a volumegroup with this group id
GroupID string
// Labels indicates backup request for a volume group with these labels
Labels map[string]string
// VolumeIDs are a list of volume IDs to use for the backup request
// If multiple of GroupID, Labels or VolumeIDs are specified, volumes matching all of
// them are backed up to cloud
VolumeIDs []string
// CredentialUUID is cloud credential to be used for backup
CredentialUUID string
// Full indicates if full backup is desired even though incremental is possible
Full bool
// DeleteLocal indicates if local snap must be deleted after the
// backup is complete
DeleteLocal bool
}
type CloudBackupRestoreRequest struct {
// ID is the backup ID being restored
ID string
// RestoreVolumeName is optional volume Name of the new volume to be created
// in the cluster for restoring the cloudbackup
RestoreVolumeName string
// CredentialUUID is the credential to be used for restore operation
CredentialUUID string
// NodeID is the optional NodeID for provisioning restore
// volume (ResoreVolumeName should not be specified)
NodeID string
// Name is optional unique id to be used for this restore op
// restore creates this by default
Name string
// Optional RestoreVolumeSpec allows some of the restoreVolume fields to be modified.
// These fields default to the volume spec stored with cloudbackup.
// The request fails if both RestoreVolSpec and NodeID are specified.
Spec *RestoreVolumeSpec
// Optional Locator for restoreVolume. Request fails if both Name and
// locator are specified
Locator *VolumeLocator
}
type CloudBackupGroupCreateResponse struct {
// ID for this group of backups
GroupCloudBackupID string
// Names of the tasks performing this group backup
Names []string
}
type CloudBackupRestoreResponse struct {
// RestoreVolumeID is the volumeID to which the backup is being restored
RestoreVolumeID string
// Name of the task performing this restore
Name string
}
type CloudBackupGenericRequest struct {
// SrcVolumeID is optional Source VolumeID for the request
SrcVolumeID string
// ClusterID is the optional clusterID for the request
ClusterID string
// CredentialUUID is the credential for cloud to be used for the request
CredentialUUID string
// All if set to true, backups for all clusters in the cloud are processed
All bool
// StatusFilter indicates backups based on status
StatusFilter CloudBackupStatusType
// MetadataFilter indicates backups whose metadata has these kv pairs
MetadataFilter map[string]string
// CloudBackupID must be specified if one needs to enumerate known single
// backup (format is clusteruuidORBucketName/srcVolId-SnapId(-incr). If
// this is specified, everything else in the command is ignored
CloudBackupID string
// MissingSrcVol set to true enumerates cloudbackups for which srcVol is not
// present in the cluster. Either the source volume is deleted or the
// cloudbackup belongs to other cluster.( with older version this
// information may be missing, and in such a case these will list as
// missing cluster info field in enumeration). Specifying SrcVolumeID and
// this flag at the same time is an error
MissingSrcVolumes bool
}
type CloudBackupInfo struct {
// ID is the ID of the cloud backup
ID string
// SrcVolumeID is Source volumeID of the backup
SrcVolumeID string
// SrcvolumeName is name of the sourceVolume of the backup
SrcVolumeName string
// Timestamp is the timestamp at which the source volume
// was backed up to cloud
Timestamp time.Time
// Metadata associated with the backup
Metadata map[string]string
// Status indicates the status of the backup
Status string
// ClusterType indicates if the cloudbackup was uploaded by this
// cluster. Could be unknown with older version cloudbackups
ClusterType SdkCloudBackupClusterType_Value
// Namespace to which this cloudbackup belongs to
Namespace string
}
type CloudBackupEnumerateRequest struct {
CloudBackupGenericRequest
// MaxBackups indicates maxBackups to return in this enumerate list
MaxBackups uint64
// ContinuationToken returned in the enumerate response if all of the
// requested backups could not be returned in one response
ContinuationToken string
}
type CloudBackupEnumerateResponse struct {
// Backups is list of backups in cloud for given volume/cluster/s
Backups []CloudBackupInfo
ContinuationToken string
}
type CloudBackupDeleteRequest struct {
// ID is the ID of the cloud backup
ID string
// CredentialUUID is the credential for cloud to be used for the request
CredentialUUID string
// Force Delete cloudbackup even if there are dependencies
Force bool
}
type CloudBackupDeleteAllRequest struct {
CloudBackupGenericRequest
}
type CloudBackupStatusRequest struct {
// SrcVolumeID optional volumeID to list status of backup/restore
SrcVolumeID string
// Local indicates if only those backups/restores that are
// active on current node must be returned
Local bool
// ID of the backup/restore task. If this is specified, SrcVolumeID is
// ignored. This could be GroupCloudBackupId too, and in that case multiple
// statuses belonging to the groupCloudBackupID is returned.
ID string
}
type CloudBackupStatusRequestOld struct {
// Old field for task ID
Name string
// New structure
CloudBackupStatusRequest
}
type CloudBackupOpType string
const (
CloudBackupOp = CloudBackupOpType("Backup")
CloudRestoreOp = CloudBackupOpType("Restore")
)
// Allowed storage classes s3
const (
S3StorageClassStandard = "STANDARD"
S3StorageClassStandardIa = "STANDARD_IA"
)
type CloudBackupStatusType string
const (
CloudBackupStatusNotStarted = CloudBackupStatusType("NotStarted")
CloudBackupStatusDone = CloudBackupStatusType("Done")
CloudBackupStatusAborted = CloudBackupStatusType("Aborted")
CloudBackupStatusPaused = CloudBackupStatusType("Paused")
CloudBackupStatusStopped = CloudBackupStatusType("Stopped")
CloudBackupStatusActive = CloudBackupStatusType("Active")
CloudBackupStatusQueued = CloudBackupStatusType("Queued")
CloudBackupStatusFailed = CloudBackupStatusType("Failed")
// Invalid includes Failed, Stopped, and Aborted used as filter to enumerate
// cloud backups
CloudBackupStatusInvalid = CloudBackupStatusType("Invalid")
)
const (
CloudBackupRequestedStatePause = "pause"
CloudBackupRequestedStateResume = "resume"
CloudBackupRequestedStateStop = "stop"
)
type CloudBackupStatus struct {
// ID is the ID for the operation
ID string
// OpType indicates if this is a backup or restore
OpType CloudBackupOpType
// State indicates if the op is currently active/done/failed
Status CloudBackupStatusType
// BytesDone indicates Bytes uploaded/downloaded so far
BytesDone uint64
// BytesTotal is the total number of bytes being transferred
BytesTotal uint64
// EtaSeconds estimated time in seconds for backup/restore completion
EtaSeconds int64
// StartTime indicates Op's start time
StartTime time.Time
// CompletedTime indicates Op's completed time
CompletedTime time.Time
// NodeID is the ID of the node where this Op is active
NodeID string
// SrcVolumeID is either the volume being backed-up or target volume to
// which a cloud backup is being restored
SrcVolumeID string
// Info currently indicates only failure cause in case of failed backup/restore
Info []string
// CredentialUUID used for this backup/restore op
CredentialUUID string
// GroupCloudBackupID is valid for backups that were started as part of group
// cloudbackup request
GroupCloudBackupID string
}
type CloudBackupStatusResponse struct {
// statuses is list of currently active/failed/done backup/restores
// map key is the id of the task
Statuses map[string]CloudBackupStatus
}
type CloudBackupCatalogRequest struct {
// ID is Backup ID in the cloud
ID string
// CredentialUUID is the credential for cloud
CredentialUUID string
}
type CloudBackupCatalogResponse struct {
// Contents is listing of backup contents
Contents []string
}
type CloudBackupHistoryRequest struct {
// SrcVolumeID is volumeID for which history of backup/restore
// is being requested
SrcVolumeID string
}
type CloudBackupHistoryItem struct {
// SrcVolumeID is volume ID which was backedup
SrcVolumeID string
// TimeStamp is the time at which either backup completed/failed
Timestamp time.Time
// Status indicates whether backup was completed/failed
Status string
}
type CloudBackupHistoryResponse struct {
// HistoryList is list of past backup/restores in the cluster
HistoryList []CloudBackupHistoryItem
}
type CloudBackupStateChangeRequest struct {
// Name of the backup/restore task for which state change
// is being requested
Name string
// RequestedState is desired state of the op
// can be pause/resume/stop
RequestedState string
}
type CloudBackupScheduleInfo struct {
// SrcVolumeID is the schedule's source volume
SrcVolumeID string
// CredentialUUID is the cloud credential used with this schedule
CredentialUUID string
// Schedule is the frequence of backup
Schedule string
// MaxBackups are the maximum number of backups retained
// in cloud.Older backups are deleted
MaxBackups uint
// GroupID indicates the group of volumes for this cloudbackup schedule
GroupID string
// Labels indicates a volume group for this cloudsnap schedule
Labels map[string]string
// Full indicates if scheduled backups must be full always
Full bool
// RetentionDays is the number of days that the scheduled backups will be kept
// and after these number of days it will be deleted
RetentionDays uint32
}
type CloudBackupSchedCreateRequest struct {
CloudBackupScheduleInfo
}
// Callers must read the existing schedule and modify
// required fields
type CloudBackupSchedUpdateRequest struct {
CloudBackupScheduleInfo
// SchedUUID for which the schedule is being updated
SchedUUID string
}
type CloudBackupGroupSchedCreateRequest struct {
// GroupID indicates the group of volumes for which cloudbackup schedule is
// being created
GroupID string
// Labels indicates a volume group for which this group cloudsnap schedule is
// being created. If this is provided GroupId is not needed and vice-versa.
Labels map[string]string
// VolumeIDs are a list of volume IDs to use for the backup request
// If multiple of GroupID, Labels or VolumeIDs are specified, volumes matching all of
// them are backed up to cloud
VolumeIDs []string
// CredentialUUID is cloud credential to be used with this schedule
CredentialUUID string
// Schedule is the frequency of backup
Schedule string
// MaxBackups are the maximum number of backups retained
// in cloud.Older backups are deleted
MaxBackups uint
// Full indicates if scheduled backups must be full always
Full bool
// RetentionDays is the number of days that the scheduled backups will be kept
// and after these number of days it will be deleted
RetentionDays uint32
}
type CloudBackupGroupSchedUpdateRequest struct {
// Any parameters in this can be updated
CloudBackupGroupSchedCreateRequest
// UUID of the group schedule being upated
SchedUUID string
}
type CloudBackupSchedCreateResponse struct {
// UUID is the UUID of the newly created schedule
UUID string
}
type CloudBackupSchedDeleteRequest struct {
// UUID is UUID of the schedule to be deleted
UUID string
}
type CloudBackupSchedEnumerateResponse struct {
// Schedule is map of schedule uuid to scheduleInfo
Schedules map[string]CloudBackupScheduleInfo
}
// Defines the response for CapacityUsage request
type CapacityUsageResponse struct {
CapacityUsageInfo *CapacityUsageInfo
// Describes the err if all of the usage details could not be obtained
Error error
}
//
// DriverTypeSimpleValueOf returns the string format of DriverType
func DriverTypeSimpleValueOf(s string) (DriverType, error) {
obj, err := simpleValueOf("driver_type", DriverType_value, s)
return DriverType(obj), err
}
// SimpleString returns the string format of DriverType
func (x DriverType) SimpleString() string {
return simpleString("driver_type", DriverType_name, int32(x))
}
// FSTypeSimpleValueOf returns the string format of FSType
func FSTypeSimpleValueOf(s string) (FSType, error) {
obj, err := simpleValueOf("fs_type", FSType_value, s)
return FSType(obj), err
}
// SimpleString returns the string format of DriverType
func (x FSType) SimpleString() string {
return simpleString("fs_type", FSType_name, int32(x))
}
// CosTypeSimpleValueOf returns the string format of CosType
func CosTypeSimpleValueOf(s string) (CosType, error) {
obj, exists := CosType_value[strings.ToUpper(s)]
if !exists {
return -1, fmt.Errorf("Invalid cos value: %s", s)
}
return CosType(obj), nil
}
// SimpleString returns the string format of CosType
func (x CosType) SimpleString() string {
return simpleString("cos_type", CosType_name, int32(x))
}
// GraphDriverChangeTypeSimpleValueOf returns the string format of GraphDriverChangeType
func GraphDriverChangeTypeSimpleValueOf(s string) (GraphDriverChangeType, error) {
obj, err := simpleValueOf("graph_driver_change_type", GraphDriverChangeType_value, s)
return GraphDriverChangeType(obj), err
}
// SimpleString returns the string format of GraphDriverChangeType
func (x GraphDriverChangeType) SimpleString() string {
return simpleString("graph_driver_change_type", GraphDriverChangeType_name, int32(x))
}
// VolumeActionParamSimpleValueOf returns the string format of VolumeAction
func VolumeActionParamSimpleValueOf(s string) (VolumeActionParam, error) {
obj, err := simpleValueOf("volume_action_param", VolumeActionParam_value, s)
return VolumeActionParam(obj), err
}
// SimpleString returns the string format of VolumeAction
func (x VolumeActionParam) SimpleString() string {
return simpleString("volume_action_param", VolumeActionParam_name, int32(x))
}
// VolumeStateSimpleValueOf returns the string format of VolumeState
func VolumeStateSimpleValueOf(s string) (VolumeState, error) {
obj, err := simpleValueOf("volume_state", VolumeState_value, s)
return VolumeState(obj), err
}
// SimpleString returns the string format of VolumeState
func (x VolumeState) SimpleString() string {
return simpleString("volume_state", VolumeState_name, int32(x))
}
// VolumeStatusSimpleValueOf returns the string format of VolumeStatus
func VolumeStatusSimpleValueOf(s string) (VolumeStatus, error) {
obj, err := simpleValueOf("volume_status", VolumeStatus_value, s)
return VolumeStatus(obj), err
}
// SimpleString returns the string format of VolumeStatus
func (x VolumeStatus) SimpleString() string {
return simpleString("volume_status", VolumeStatus_name, int32(x))
}
// IoProfileSimpleValueOf returns the string format of IoProfile
func IoProfileSimpleValueOf(s string) (IoProfile, error) {
obj, err := simpleValueOf("io_profile", IoProfile_value, s)
return IoProfile(obj), err
}
// SimpleString returns the string format of IoProfile
func (x IoProfile) SimpleString() string {
return simpleString("io_profile", IoProfile_name, int32(x))
}
// ProxyProtocolSimpleValueOf returns the string format of ProxyProtocol
func ProxyProtocolSimpleValueOf(s string) (ProxyProtocol, error) {
obj, err := simpleValueOf("proxy_protocol", ProxyProtocol_value, s)
return ProxyProtocol(obj), err
}
// SimpleString returns the string format of ProxyProtocol
func (x ProxyProtocol) SimpleString() string {
return simpleString("proxy_protocol", ProxyProtocol_name, int32(x))
}
func simpleValueOf(typeString string, valueMap map[string]int32, s string) (int32, error) {
obj, ok := valueMap[strings.ToUpper(fmt.Sprintf("%s_%s", typeString, s))]
if !ok {
return 0, fmt.Errorf("no openstorage.%s for %s", strings.ToUpper(typeString), s)
}
return obj, nil
}
func simpleString(typeString string, nameMap map[int32]string, v int32) string {
s, ok := nameMap[v]
if !ok {
return strconv.Itoa(int(v))
}
return strings.TrimPrefix(strings.ToLower(s), fmt.Sprintf("%s_", strings.ToLower(typeString)))
}
// ScanPolicyTriggerValueof returns value of string
func ScanPolicy_ScanTriggerSimpleValueOf(s string) (ScanPolicy_ScanTrigger, error) {
obj, err := simpleValueOf("scan_trigger", ScanPolicy_ScanTrigger_value, s)
return ScanPolicy_ScanTrigger(obj), err
}
// SimpleString returns the string format of ScanPolicy_ScanTrigger
func (x ScanPolicy_ScanTrigger) SimpleString() string {
return simpleString("scan_trigger", ScanPolicy_ScanTrigger_name, int32(x))
}
// ScanPolicyActioinValueof returns value of string
func ScanPolicy_ScanActionSimpleValueOf(s string) (ScanPolicy_ScanAction, error) {
obj, err := simpleValueOf("scan_action", ScanPolicy_ScanAction_value, s)
return ScanPolicy_ScanAction(obj), err
}
// SimpleString returns the string format of ScanPolicy_ScanAction
func (x ScanPolicy_ScanAction) SimpleString() string {
return simpleString("scan_action", ScanPolicy_ScanAction_name, int32(x))
}
func toSec(ms uint64) uint64 {
return ms / 1000
}
// WriteThroughput returns the write throughput
func (v *Stats) WriteThroughput() uint64 {
intv := toSec(v.IntervalMs)
if intv == 0 {
return 0
}
return (v.WriteBytes) / intv
}
// ReadThroughput returns the read throughput
func (v *Stats) ReadThroughput() uint64 {
intv := toSec(v.IntervalMs)
if intv == 0 {
return 0
}
return (v.ReadBytes) / intv
}
// Latency returns latency
func (v *Stats) Latency() uint64 {
ops := v.Writes + v.Reads
if ops == 0 {
return 0
}
return (uint64)((v.IoMs * 1000) / ops)
}
// Read latency returns avg. time required for read operation to complete
func (v *Stats) ReadLatency() uint64 {
if v.Reads == 0 {
return 0
}
return (uint64)((v.ReadMs * 1000) / v.Reads)
}
// Write latency returns avg. time required for write operation to complete
func (v *Stats) WriteLatency() uint64 {
if v.Writes == 0 {
return 0
}
return (uint64)((v.WriteMs * 1000) / v.Writes)
}
// Iops returns iops
func (v *Stats) Iops() uint64 {
intv := toSec(v.IntervalMs)
if intv == 0 {
return 0
}
return (v.Writes + v.Reads) / intv
}
// Scaled returns true if the volume is scaled.
func (v *Volume) Scaled() bool {
return v.Spec.Scale > 1
}
// Contains returns true if locationConstraint is a member of volume's replication set.
func (m *Volume) Contains(locationConstraint string) bool {
rsets := m.GetReplicaSets()
for _, rset := range rsets {
for _, node := range rset.Nodes {
if node == locationConstraint {
return true
}
}
}
// also check storage pool UUIDs
for _, replSet := range m.ReplicaSets {
for _, uid := range replSet.PoolUuids {
if uid == locationConstraint {
return true
}
}
}
return false
}
// Copy makes a deep copy of VolumeSpec
func (s *VolumeSpec) Copy() *VolumeSpec {
spec := *s
if s.ReplicaSet != nil {
spec.ReplicaSet = &ReplicaSet{Nodes: make([]string, len(s.ReplicaSet.Nodes))}
copy(spec.ReplicaSet.Nodes, s.ReplicaSet.Nodes)
}
return &spec
}
// Copy makes a deep copy of Node
func (s *Node) Copy() *Node {
localCopy := deepcopy.Copy(*s)
nodeCopy := localCopy.(Node)
return &nodeCopy
}
func (v Volume) IsClone() bool {
return v.Source != nil && len(v.Source.Parent) != 0 && !v.Readonly
}
func (v Volume) IsSnapshot() bool {
return v.Source != nil && len(v.Source.Parent) != 0 && v.Readonly
}
func (v Volume) DisplayId() string {
if v.Locator != nil {
return fmt.Sprintf("%s (%s)", v.Locator.Name, v.Id)
} else {
return v.Id
}
}
// ToStorageNode converts a Node structure to an exported gRPC StorageNode struct
func (s *Node) ToStorageNode() *StorageNode {
node := &StorageNode{
Id: s.Id,
SchedulerNodeName: s.SchedulerNodeName,
Cpu: s.Cpu,
MemTotal: s.MemTotal,
MemUsed: s.MemUsed,
MemFree: s.MemFree,
AvgLoad: int64(s.Avgload),
Status: s.Status,
MgmtIp: s.MgmtIp,
DataIp: s.DataIp,
Hostname: s.Hostname,
HWType: s.HWType,
SecurityStatus: s.SecurityStatus,
SchedulerTopology: s.SchedulerTopology,
}
node.Disks = make(map[string]*StorageResource)
for k, v := range s.Disks {
// need to take the address of a local variable and not of v