MCPcopy Index your code
hub / github.com/deepflowio/deepflow / updateDomain

Function updateDomain

cli/ctl/domain.go:201–248  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string, filename string)

Source from the content-addressed store, hash-verified

199}
200
201func updateDomain(cmd *cobra.Command, args []string, filename string) {
202 if len(args) == 0 {
203 fmt.Fprintf(os.Stderr, "must specify name.\nExample: %s\n", cmd.Example)
204 return
205 }
206
207 server := common.GetServerInfo(cmd)
208 url := fmt.Sprintf("http://%s:%d/v2/domains/?name=%s", server.IP, server.Port, args[0])
209 // curl domain API,list lcuuid
210 response, err := common.CURLPerform("GET", url, nil, "", []common.HTTPOption{common.WithTimeout(common.GetTimeout(cmd))}...)
211 if err != nil {
212 fmt.Fprintln(os.Stderr, err)
213 return
214 }
215
216 if len(response.Get("DATA").MustArray()) > 0 {
217 lcuuid := response.Get("DATA").GetIndex(0).Get("LCUUID").MustString()
218 domainTypeInt := response.Get("DATA").GetIndex(9).Get("TYPE").MustInt()
219 url := fmt.Sprintf("http://%s:%d/v1/domains/%s/", server.IP, server.Port, lcuuid)
220
221 body, err := formatBody(filename)
222 if err != nil {
223 fmt.Fprintln(os.Stderr, err)
224 return
225 }
226 if !validateBody(body) {
227 return
228 }
229
230 body["TYPE"] = domainTypeInt
231 resp, err := common.CURLPerform("PATCH", url, body, "", []common.HTTPOption{common.WithTimeout(common.GetTimeout(cmd))}...)
232 if err != nil {
233 fmt.Fprintln(os.Stderr, err)
234 return
235 }
236 respByte, err := resp.MarshalJSON()
237 if err != nil {
238 fmt.Fprintln(os.Stderr, err)
239 return
240 }
241 formatStr, err := common.JsonFormat(respByte)
242 if err != nil {
243 fmt.Println("format json str faild: " + err.Error())
244 return
245 }
246 fmt.Println(formatStr)
247 }
248}
249
250func deleteDomain(cmd *cobra.Command, args []string) {
251 if len(args) == 0 {

Callers 1

RegisterDomainCommandFunction · 0.70

Calls 5

formatBodyFunction · 0.85
validateBodyFunction · 0.85
GetMethod · 0.65
ErrorMethod · 0.65
MarshalJSONMethod · 0.45

Tested by

no test coverage detected