func RunReserveNodeWorkflow(c config.Cpi, nodeID string, workflowName string) error { options := reserveNodeWorkflowOptions{} isAMTService, err := rackhdapi.IsAMTService(c, nodeID) if err != nil { return err } if isAMTService { obmName := rackhdapi.OBMSettingAMTServiceName options.OBMServiceName = &obmName } req := rackhdapi.RunWorkflowRequestBody{ Name: workflowName, Options: map[string]interface{}{"defaults": options}, } return rackhdapi.RunWorkflow(rackhdapi.WorkflowPoster, rackhdapi.WorkflowFetcher, c, nodeID, req) }
func buildProvisionWorkflowOptions(c config.Cpi, nodeID string, workflowName string, vmCID string, stemcellCID string, wipeDisk bool) (ProvisionNodeWorkflowOptions, error) { envPath := rackhdapi.RackHDEnvPath options := ProvisionNodeWorkflowOptions{ AgentSettingsFile: &nodeID, AgentSettingsPath: &envPath, CID: &vmCID, StemcellFile: &stemcellCID, WipeDisk: strconv.FormatBool(wipeDisk), } isAMTService, err := rackhdapi.IsAMTService(c, nodeID) if err != nil { return ProvisionNodeWorkflowOptions{}, fmt.Errorf("error retrieving obm settings from node: %s", nodeID) } if isAMTService { obmName := rackhdapi.OBMSettingAMTServiceName options.OBMServiceName = &obmName } return options, nil }
func RunDeprovisionNodeWorkflow(c config.Cpi, nodeID string, workflowName string) error { options := deprovisionNodeWorkflowOptions{} isAMTService, err := rackhdapi.IsAMTService(c, nodeID) if err != nil { return err } if isAMTService { obmName := rackhdapi.OBMSettingAMTServiceName options.OBMServiceName = &obmName } req := rackhdapi.RunWorkflowRequestBody{ Name: workflowName, Options: map[string]interface{}{"defaults": options}, } err = rackhdapi.RunWorkflow(rackhdapi.WorkflowPoster, rackhdapi.WorkflowFetcher, c, nodeID, req) if err != nil { return fmt.Errorf("Failed to complete delete VM workflow--its resource may not have been deprovisioned! Details: %s", err) } return nil }
}) Describe("IsAMTService", func() { It("returns true if the node's obm settings is amt", func() { dummy_response_path := "../spec_assets/dummy_one_node_response.json" httpResponse := helpers.LoadJSON(dummy_response_path) nodeID := "nodeID" server.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("GET", fmt.Sprintf("/api/common/nodes/%s", nodeID)), ghttp.RespondWith(http.StatusOK, httpResponse), ), ) amtService, err := rackhdapi.IsAMTService(cpiConfig, nodeID) Expect(err).ToNot(HaveOccurred()) Expect(server.ReceivedRequests()).To(HaveLen(1)) Expect(amtService).To(BeTrue()) }) }) Describe("Getting catalog", func() { It("returns a catalog", func() { expectedNodeCatalog := helpers.LoadNodeCatalog("../spec_assets/dummy_node_catalog_response.json") expectedNodeCatalogData, err := json.Marshal(expectedNodeCatalog) testNodeID := "55e79eb14e66816f6152fffb" Expect(err).ToNot(HaveOccurred()) server.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("GET", fmt.Sprintf("/api/common/nodes/%s/catalogs/ohai", testNodeID)),