-
Notifications
You must be signed in to change notification settings - Fork 0
/
driveimpl.go
58 lines (45 loc) · 1.12 KB
/
driveimpl.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
// Copyright 2014 ALTOROS
// Licensed under the AGPLv3, see LICENSE file for details.
package gosigma
import (
"errors"
"github.com/Altoros/gosigma/data"
)
func (d drive) clone(params CloneParams, avoid []string) (*data.Drive, error) {
obj, err := d.client.cloneDrive(d.UUID(), d.Library(), params, avoid)
if err != nil {
return nil, err
}
if d.Library() == LibraryMedia {
obj.LibraryDrive = d.obj.LibraryDrive
}
return obj, nil
}
func (d *drive) resize(newSize uint64) error {
// if drive object contains only UUID, we need to refresh it
if d.Status() == "" {
if err := d.Refresh(); err != nil {
return err
}
}
// check the current drive size
if uint64(d.Size()) == newSize {
return nil
}
// check the library
if d.Library() == LibraryMedia {
return errors.New("can not resize drive from media library")
}
// check the drive status
if d.Status() != DriveUnmounted {
return errors.New("drive size can be changed only for unmounted drives")
}
// do the resize
obj, err := d.client.resizeDrive(*d.obj, newSize)
if err != nil {
return err
}
// update drive data
d.obj = obj
return nil
}