Skip to content
Snippets Groups Projects
Select Git revision
  • 7e41041b931c9d76850e92f361ba6d23c924f519
  • live_exam_os_ubuntu default protected
2 results

templateCreate.go

Blame
  • templateCreate.go 1.05 KiB
    package cmdTemplate
    
    import (
    	u "nexus-client/utils"
    	g "nexus-client/globals"
    )
    
    type Create struct {
        Name string
    }
    
    func (cmd *Create)GetName() string {
    	return cmd.Name
    }
     
    func (cmd *Create)GetDesc() string {
    	return "Create a template."
    }
    
    func (cmd *Create)PrintUsage() {
    	u.PrintlnErr(cmd.GetDesc())
    	u.PrintlnErr("Usage: "+cmd.Name+" vmID name access")
    	u.PrintlnErr("Notes: access is either \"public\" or \"private\"")
    }
    
    func (cmd *Create)Run(args []string) int {
    	client := g.GetInstance().Client
    	host := g.GetInstance().Host
    
    	argc := len(args)
    	if argc != 3 {
    		cmd.PrintUsage()
    		return 1
    	}
    
    	vmID := args[0]
    	name := args[1]
    	access := args[2]
    
    	type TemplateArgs struct {
    		VMID string
    		Name string
    		Access string
    	}
    			
    	templateArgs := &TemplateArgs { vmID, name, access }
    	
    	resp, err := client.R().SetBody(templateArgs).Post(host+"/templates")
    	if err != nil {
    		u.PrintlnErr("Error: "+err.Error())
    		return 1
    	}
    
    	if resp.IsSuccess() {
    		u.Println(resp)
    		return 0
    	} else {
    		u.PrintlnErr("Error: "+resp.Status()+": "+resp.String())
    		return 1
    	}
    }