MCPcopy Create free account
hub / github.com/Thunder-Compute/thunder-cli / UpdatePorts

Method UpdatePorts

api/client.go:288–305  ·  view source on GitHub ↗

UpdatePorts atomically adds and removes forwarded HTTP ports on an instance.

(instanceID string, addPorts, removePorts []int)

Source from the content-addressed store, hash-verified

286
287// UpdatePorts atomically adds and removes forwarded HTTP ports on an instance.
288func (c *Client) UpdatePorts(instanceID string, addPorts, removePorts []int) (*PortAddResponse, error) {
289 if len(addPorts) == 0 && len(removePorts) == 0 {
290 return nil, fmt.Errorf("no ports specified")
291 }
292 var resp PortAddResponse
293 err := c.doRequest(context.Background(), "PATCH", fmt.Sprintf("/v1/instances/%s/ports", instanceID), PortUpdateRequest{
294 AddPorts: addPorts,
295 RemovePorts: removePorts,
296 }, &resp)
297 if err != nil {
298 var apiErr *APIError
299 if errors.As(err, &apiErr) && apiErr.StatusCode == 404 {
300 return nil, fmt.Errorf("instance not found")
301 }
302 return nil, err
303 }
304 return &resp, nil
305}
306
307// RemovePorts removes one or more forwarded HTTP ports from an instance in a single call.
308func (c *Client) RemovePorts(instanceID string, ports []int) error {

Callers 4

RemovePortsMethod · 0.95
portsForwardApiCmdFunction · 0.80
runPortsForwardFunction · 0.80
portsForwardApiCallFunction · 0.80

Calls 1

doRequestMethod · 0.95

Tested by

no test coverage detected