MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / buildBatchInstallAgentName

Function buildBatchInstallAgentName

agent/app/service/agents.go:632–648  ·  view source on GitHub ↗
(agentType string)

Source from the content-addressed store, hash-verified

630}
631
632func buildBatchInstallAgentName(agentType string) (string, error) {
633 prefix := strings.ToLower(strings.TrimSpace(agentType))
634 if prefix == "" {
635 prefix = "agent"
636 }
637 for i := 1; i <= 10000; i++ {
638 name := fmt.Sprintf("%s-%d", prefix, i)
639 exists, err := agentNameExists(name)
640 if err != nil {
641 return "", err
642 }
643 if !exists {
644 return name, nil
645 }
646 }
647 return "", fmt.Errorf("no available agent name")
648}
649
650func agentNameExists(name string) (bool, error) {
651 if exist, err := agentRepo.GetFirst(repo.WithByLowerName(name)); err == nil && exist != nil && exist.ID > 0 {

Callers 1

BatchInstallMethod · 0.85

Calls 1

agentNameExistsFunction · 0.85

Tested by

no test coverage detected