Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new built-in function for AssignTask #1626

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/core/mcis/remoteCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,14 @@ func RemoteCommandToMcis(nsId string, mcisId string, subGroupId string, vmId str

// Preprocess commands for each VM
vmCommands := make(map[string][]string)
for _, vmId := range vmList {
for i, vmId := range vmList {
processedCommands := make([]string, len(req.Command))
for i, cmd := range req.Command {
processedCmd, err := processCommand(cmd, nsId, mcisId, vmId)
for j, cmd := range req.Command {
processedCmd, err := processCommand(cmd, nsId, mcisId, vmId, i)
if err != nil {
return nil, err
}
processedCommands[i] = processedCmd
processedCommands[j] = processedCmd
}
vmCommands[vmId] = processedCommands
}
Expand Down Expand Up @@ -809,7 +809,7 @@ func findMatchingParenthesis(command string, start int) int {
}

// processCommand is function to replace the keywords with actual values
func processCommand(command, nsId, mcisId, vmId string) (string, error) {
func processCommand(command, nsId, mcisId, vmId string, vmIndex int) (string, error) {
start := 0
for {
start = strings.Index(command[start:], "$$Func(")
Expand Down Expand Up @@ -885,6 +885,13 @@ func processCommand(command, nsId, mcisId, vmId string) (string, error) {
return "", fmt.Errorf("Built-in function getPublicIPs error: %s", err.Error())
}

} else if strings.EqualFold(funcName, "AssignTask") {
taskListParam, ok := params["task"]
if !ok {
return "", fmt.Errorf("Built-in function AssignTask error: no task list provided")
}
tasks := splitParams(taskListParam)
replacement = tasks[vmIndex%len(tasks)]
} else {
return "", fmt.Errorf("Built-in function error in command: Unknown function: %s", funcName)
}
Expand Down