Skip to content

Commit

Permalink
fix: Windows OS (#33)
Browse files Browse the repository at this point in the history
* feat: Windows OS - implementation
* implementation Data provider
* fix: double naming
* docs: templating documentation and examples
* fix: Change of Windows Deployment, Timeout in Data
* fix: timeout - waiting
* fix: force new behavior
* fix: waiting behavior

---------

Co-authored-by: Maximilian.Brand <Maximilian.Brand@cancom.de>
  • Loading branch information
atddo and cancom-mbrand authored Nov 30, 2023
1 parent e2607db commit 1dad965
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
2 changes: 2 additions & 0 deletions cancom/services/windows-os/resource_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func resourceWindowsOSDeployment() *schema.Resource {
"role": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Role of the Machine - needs to match predefined roles.",
},
"maintenance_window_id": {
Expand All @@ -38,6 +39,7 @@ func resourceWindowsOSDeployment() *schema.Resource {
"services": {
Type: schema.TypeList,
Required: true,
ForceNew: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Expand Down
33 changes: 14 additions & 19 deletions client/services/windows-os/windows-os.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ func (c *Client) CreateWindowsDeploymentStatus(id string) (*WindowsOS_Deplyoment
//The deployment itself is run by the CANCOM Windows OS Service backend.
for {
req, err := http.NewRequest("GET", fmt.Sprintf("%s/%s/%s", c.HostURL, urlPath, id), nil)
req.Header.Add("Content-Type", "application/json")

resp, err := (*client.Client)(c).DoRequest(req)
if err != nil {

// allow timeouts because of long running queries in background
Expand All @@ -89,27 +92,19 @@ func (c *Client) CreateWindowsDeploymentStatus(id string) (*WindowsOS_Deplyoment
}
} else {
timeoutCount = 0

}
req.Header.Add("Content-Type", "application/json")

resp, err := (*client.Client)(c).DoRequest(req)
if err != nil {
return nil, err
}
apiResultObject := WindowsOS_Deplyoment{}
err = json.Unmarshal(resp, &apiResultObject)
if err != nil {
return nil, err
}
if slices.Contains(errorstatus, apiResultObject.Status) {
return nil, err
} else if slices.Contains(sucessstatus, apiResultObject.Status) {
return &apiResultObject, nil
apiResultObject := WindowsOS_Deplyoment{}
err = json.Unmarshal(resp, &apiResultObject)
if err != nil {
return nil, err
}
if slices.Contains(errorstatus, apiResultObject.Status) {
return nil, err
} else if slices.Contains(sucessstatus, apiResultObject.Status) {
return &apiResultObject, nil
}
}
time.Sleep(30 * time.Second) // sleep for 30 seconds to aviod active
time.Sleep(30 * time.Second) // sleep for 30 seconds to aviod active waiting
}

}

func (c *Client) UpdateWindowsOsDeployment(id string, windowsOSDeployment *WindowsOS_Deplyoment) (*WindowsOS_Deplyoment, error) {
Expand Down

0 comments on commit 1dad965

Please sign in to comment.