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

Function createRepoAgent

cli/ctl/agent_repo.go:133–188  ·  view source on GitHub ↗
(cmd *cobra.Command, arch, image, versionImage, k8sImage string)

Source from the content-addressed store, hash-verified

131}
132
133func createRepoAgent(cmd *cobra.Command, arch, image, versionImage, k8sImage string) error {
134 execImage := image
135 if versionImage != "" || len(k8sImage) != 0 {
136 execImage = versionImage
137 }
138 agentOutput, err := getAgentOutput(execImage)
139 if err != nil {
140 return err
141 }
142 branch, revCount, commitID := getAgentInfo(agentOutput)
143
144 bodyBuf := &bytes.Buffer{}
145 bodyWriter := multipart.NewWriter(bodyBuf)
146 if len(k8sImage) != 0 {
147 bodyWriter.WriteField("NAME", k8sImage)
148 } else {
149 bodyWriter.WriteField("NAME", path.Base(image))
150 }
151 bodyWriter.WriteField("ARCH", arch)
152 bodyWriter.WriteField("BRANCH", branch)
153 bodyWriter.WriteField("REV_COUNT", revCount)
154 bodyWriter.WriteField("COMMIT_ID", commitID)
155 bodyWriter.WriteField("K8S_IMAGE", k8sImage)
156 osStr := "Linux"
157 if strings.HasSuffix(image, ".exe") {
158 osStr = "Windows"
159 }
160 bodyWriter.WriteField("OS", osStr)
161
162 contentType := bodyWriter.FormDataContentType()
163 if len(image) > 0 {
164 fileWriter, err := bodyWriter.CreateFormFile("IMAGE", path.Base(image))
165 f, err := os.Open(image)
166 if err != nil {
167 return err
168 }
169 defer f.Close()
170 if _, err = io.Copy(fileWriter, f); err != nil {
171 return err
172 }
173 }
174 bodyWriter.Close()
175
176 server := common.GetServerInfo(cmd)
177 url := fmt.Sprintf("http://%s:%d/v1/vtap-repo/", server.IP, server.Port)
178 orgID := common.GetORGID(cmd)
179 resp, err := common.CURLPostFormData(url, contentType, bodyBuf, []common.HTTPOption{common.WithTimeout(common.GetTimeout(cmd)), common.WithORGID(orgID)}...)
180 if err != nil {
181 return err
182 }
183 data := resp.Get("DATA")
184 fmt.Printf("ORGID-%d: created successfully, os: %s, branch: %s, rev_count: %s, commit_id: %s\n",
185 orgID, data.Get("OS").MustString(), data.Get("BRANCH").MustString(),
186 data.Get("REV_COUNT").MustString(), data.Get("COMMIT_ID").MustString())
187 return nil
188}
189
190func getAgentOutput(image string) (string, error) {

Callers 1

registerAgentCommandFunction · 0.85

Calls 6

getAgentOutputFunction · 0.85
getAgentInfoFunction · 0.85
CloseMethod · 0.65
GetMethod · 0.65
CopyMethod · 0.45
GetORGIDMethod · 0.45

Tested by

no test coverage detected