@@ -11,6 +11,8 @@ import (
11
11
"github.com/spf13/cobra"
12
12
)
13
13
14
+ var podLink string
15
+
14
16
//podModifyCmd is a command to modify app
15
17
var podModifyCmd = & cobra.Command {
16
18
Use : "modify <app>" ,
@@ -52,9 +54,18 @@ var podModifyCmd = &cobra.Command{
52
54
}
53
55
opts = append (opts , expect .WithACL (acl ))
54
56
opts = append (opts , expect .WithOldApp (appName ))
55
- expectation := expect .AppExpectationFromURL (ctrl , dev , defaults .DefaultDummyExpect , appName , opts ... )
56
- appInstanceConfig := expectation .Application ()
57
+ opts = append (opts , expect .WithHTTPDirectLoad (directLoad ))
58
+ link := defaults .DefaultDummyExpect
59
+ newLink := false
57
60
needPurge := false
61
+ if podLink != "" {
62
+ needPurge = true
63
+ newLink = true
64
+ link = podLink
65
+ }
66
+ volumes := dev .GetVolumes ()
67
+ expectation := expect .AppExpectationFromURL (ctrl , dev , link , appName , opts ... )
68
+ appInstanceConfig := expectation .Application ()
58
69
if len (app .Interfaces ) != len (appInstanceConfig .Interfaces ) {
59
70
needPurge = true
60
71
} else {
@@ -65,14 +76,64 @@ var podModifyCmd = &cobra.Command{
65
76
}
66
77
}
67
78
}
79
+ app .Interfaces = appInstanceConfig .Interfaces
80
+ if newLink {
81
+ diffInDrives := true
82
+ if len (app .Drives ) == len (appInstanceConfig .Drives ) {
83
+ diffInDrives = false
84
+ for i , d := range app .Drives {
85
+ // check if we have difference in volumes and its images
86
+ if appInstanceConfig .Drives [i ].Image .Name != d .Image .Name || appInstanceConfig .Drives [i ].Image .Sha256 != d .Image .Sha256 {
87
+ diffInDrives = true
88
+ }
89
+ }
90
+ }
91
+ if diffInDrives {
92
+ // user provides different link, so we need to purge all volumes
93
+ volumeIDs := dev .GetVolumes ()
94
+ utils .DelEleInSliceByFunction (& volumeIDs , func (i interface {}) bool {
95
+ vol , err := ctrl .GetVolume (i .(string ))
96
+ if err != nil {
97
+ log .Fatalf ("no volume in cloud %s: %s" , i .(string ), err )
98
+ }
99
+ for _ , volRef := range app .VolumeRefList {
100
+ if vol .Uuid == volRef .Uuid {
101
+ return true
102
+ }
103
+ }
104
+ return false
105
+ })
106
+ dev .SetVolumeConfigs (volumeIDs )
107
+ app .VolumeRefList = appInstanceConfig .VolumeRefList
108
+ app .Drives = appInstanceConfig .Drives
109
+ } else {
110
+ // we will increase generation number if user provide the same link
111
+ // to run image update
112
+ dev .SetVolumeConfigs (volumes )
113
+ for _ , ctID := range dev .GetContentTrees () {
114
+ ct , err := ctrl .GetContentTree (ctID )
115
+ if err != nil {
116
+ log .Fatalf ("no ContentTree in cloud %s: %s" , ctID , err )
117
+ }
118
+ for _ , v := range app .VolumeRefList {
119
+ volumeConfig , err := ctrl .GetVolume (v .Uuid )
120
+ if err != nil {
121
+ log .Fatalf ("no volume in cloud %s: %s" , v .Uuid , err )
122
+ }
123
+ volumeConfig .GenerationCount ++
124
+ if ct .GetUuid () == volumeConfig .Origin .DownloadContentTreeID {
125
+ ct .GenerationCount ++
126
+ }
127
+ }
128
+ }
129
+ }
130
+ }
68
131
if needPurge {
69
132
if app .Purge == nil {
70
133
app .Purge = & config.InstanceOpsCmd {Counter : 0 }
71
134
}
72
135
app .Purge .Counter ++
73
136
}
74
- //now we only change networks
75
- app .Interfaces = appInstanceConfig .Interfaces
76
137
if err = changer .setControllerAndDev (ctrl , dev ); err != nil {
77
138
log .Fatalf ("setControllerAndDev: %s" , err )
78
139
}
@@ -89,5 +150,7 @@ func podModifyInit() {
89
150
podModifyCmd .Flags ().StringSliceVarP (& portPublish , "publish" , "p" , nil , "Ports to publish in format EXTERNAL_PORT:INTERNAL_PORT" )
90
151
podModifyCmd .Flags ().BoolVar (& aclOnlyHost , "only-host" , false , "Allow access only to host and external networks" )
91
152
podModifyCmd .Flags ().StringSliceVar (& podNetworks , "networks" , nil , "Networks to connect to app (ports will be mapped to first network)" )
153
+ podModifyCmd .Flags ().StringVar (& podLink , "link" , "" , "Set new app link for pod" )
154
+ podModifyCmd .Flags ().BoolVar (& directLoad , "direct" , true , "Use direct download for image instead of eserver" )
92
155
podModifyCmd .Flags ().StringSliceVar (& acl , "acl" , nil , "Allow access only to defined hosts/ips/subnets" )
93
156
}
0 commit comments