Pearl1594 commented on pull request #9:
URL: https://github.com/apache/cloudstack-go/pull/9#issuecomment-931137315


   Script used to run tests - details of qa server added:
   ```
   package main
   
   import (
        "encoding/json"
        "github.com/apache/cloudstack-go/v2/cloudstack"
        "log"
   )
   
   func main() {
        apiUrl := "http://qa.cloudstack.cloud:8080/client/api";
        secretKey := 
"PZAM4nrxKbMnlq8RT0GMqAJyYtJGMN5x-PN7owa9vSmE58zObTcn4Yc8pgLeznln1aEUkHH_d2S-QQTt3E2Azw"
        apiKey := 
"DN7uIwbqAMASSB1GUGHWvXqUlDDBf7H6A3XI-kNeXahW5LMUoqgfDEDWMv8zWKaj51fDozg8fjqc7tGCSozScA"
        zoneId := "b6afade4-1919-4f0b-a785-12ff05a4d383"
   
   
        cs := cloudstack.NewAsyncClient(apiUrl, apiKey, secretKey, false)
        zone, _, err := cs.Zone.GetZoneByID(zoneId)
        if err != nil {
                log.Fatalf("Failed to find zone: %v", err)
                return
        }
   
        if zone.Resourcedetails["resourceHAEnabled"] == "true" {
                log.Printf("High Availability enabled for zone: %s. Attempting 
to disable it", zoneId)
                zoneHAParams := &cloudstack.DisableHAForZoneParams{}
                zoneHAParams.SetZoneid(zone.Id)
                resp, err := cs.Zone.DisableHAForZone(zoneHAParams)
                if err != nil {
                        log.Fatalf("Failed to disable HA for zone due to: %v", 
err)
                        return
                }
                log.Printf("HA for zone - disabled? : %v", resp.Success )
        }
   
        if zone.Resourcedetails["resourceHAEnabled"] == "false" {
                log.Printf("High Availability disabled for zone: %s. Attempting 
to enable it", zoneId)
                zoneHAParams := &cloudstack.EnableHAForZoneParams{}
                zoneHAParams.SetZoneid(zone.Id)
                resp, err := cs.Zone.EnableHAForZone(zoneHAParams)
                if err != nil {
                        log.Fatalf("Failed to enable HA for zone due to: %v", 
err)
                        return
                }
                log.Printf("HA for zone - enabled? : %v", resp.Success )
        }
   
        p := &cloudstack.ListHostsParams{}
        p.SetZoneid(zoneId)
        hosts, err := cs.Host.ListHosts(p)
        if err != nil {
                log.Fatalf("Failed to list all hosts in zone: %s due to: %v", 
zone.Name, err)
                return
        }
        for _, host := range hosts.Hosts {
                log.Printf("Host - Name: %s \t Host - HA Response: %v", 
host.Name, host.Hostha)
        }
   
        host := hosts.Hosts[0]
        log.Println(host.Resourcestate)
        if host.Resourcestate == "Enabled" {
                log.Printf("Prepare host %s for maintenance", host.Name)
                prepHostMnt := &cloudstack.PrepareHostForMaintenanceParams{}
                prepHostMnt.SetId(host.Id)
                resp, err := cs.Host.PrepareHostForMaintenance(prepHostMnt)
                if err != nil {
                        log.Fatalf("Failed to prepare host %s for maintenance 
due to: %v", host.Name, err)
                        return
                }
                b, err := json.MarshalIndent(resp, "", "    ")
                if err != nil {
                        log.Printf("%v", err)
                        return
                }
                log.Printf("Host response : %v", string(b))
        }
   
        if host.Resourcestate == "Maintenance" {
                log.Printf("Cancelinng host for maintenance on host: %s", 
host.Name)
                cancelHostMnt := &cloudstack.CancelHostMaintenanceParams{}
                cancelHostMnt.SetId(host.Id)
                resp, err := cs.Host.CancelHostMaintenance(cancelHostMnt)
                if err != nil {
                        log.Fatalf("Failed to cancel host for maintenance on %s 
due to: %v", host.Name, err)
                        return
                }
                b, err := json.MarshalIndent(resp, "", "    ")
                if err != nil {
                        log.Printf("%v", err)
                        return
                }
                log.Printf("Host response : %v", string(b))
        }
   }
   
   ```
   
   #### Output:
   ```
   2021/09/30 15:00:23 High Availability enabled for zone: 
b6afade4-1919-4f0b-a785-12ff05a4d383. Attempting to disable it
   2021/09/30 15:00:23 HA for zone - disabled? : false
   2021/09/30 15:00:24 Host - Name: 
SimulatedAgent.200634f3-68d0-48ca-89d2-9630e2df1ac4     Host - HA Response: 
{false  Disabled   0 false}
   2021/09/30 15:00:24 Host - Name: 
SimulatedAgent.f3c875a9-6f08-4df1-a079-c8995eaccfa0     Host - HA Response: 
{false  Disabled   0 false}
   2021/09/30 15:00:24 Host - Name: 
SimulatedAgent.2a1689d9-778d-49f4-ab85-87f2d8c88bcb     Host - HA Response: 
{false  Disabled   0 false}
   2021/09/30 15:00:24 Host - Name: s-143-QA        Host - HA Response: {false  
Disabled   0 false}
   2021/09/30 15:00:24 Host - Name: s-143-QA        Host - HA Response: {false  
Disabled   0 false}
   2021/09/30 15:00:24 Maintenance
   2021/09/30 15:00:24 Cancelinng host for maintenance on host: 
SimulatedAgent.200634f3-68d0-48ca-89d2-9630e2df1ac4
   2021/09/30 15:00:24 Host response : {
       "annotation": "",
       "capabilities": "hvm",
       "clusterid": "363676ef-b414-442c-97eb-231987beedf6",
       "clustername": "DemoClusterSIG",
       "clustertype": "CloudManaged",
       "cpuallocated": "0%",
       "cpuallocatedpercentage": "0%",
       "cpuallocatedvalue": 0,
       "cpuallocatedwithoverprovisioning": "0%",
       "cpuloadaverage": 0,
       "cpunumber": 4,
       "cpusockets": 0,
       "cpuspeed": 8000,
       "cpuused": "0%",
       "cpuwithoverprovisioning": "32000",
       "created": "2020-03-30T10:07:58+0000",
       "details": null,
       "disconnected": "2021-09-28T20:05:04+0000",
       "disksizeallocated": 0,
       "disksizetotal": 0,
       "events": "Ping; ShutdownRequested; PingTimeout; ManagementServerDown; 
AgentConnected; AgentDisconnected; Remove; StartAgentRebalance; HostDown",
       "gpugroup": null,
       "hahost": false,
       "hasenoughcapacity": false,
       "hostha": {                                                              
 <----- Host HA response
           "haenable": false,
           "haprovider": "",
           "hastate": "Disabled",
           "hostid": "",
           "jobid": "",
           "jobstatus": 0,
           "status": false
       },
       "hosttags": "null",
       "hypervisor": "Simulator",
       "hypervisorversion": "4.14.0.0-SNAPSHOT",
       "id": "4f944183-7cfe-41c7-a34c-b7230bb503d5",
       "ipaddress": "172.23.1.13",
       "islocalstorageactive": false,
       "jobid": "75b78ba4-2481-4bc7-9cb9-90118605e624",
       "jobstatus": 0,
       "lastannotated": "",
       "lastpinged": "1970-01-19T10:58:30+0000",
       "managementserverid": "18c349c6-ed36-4890-b670-4ef76e48485e",
       "memoryallocated": 0,
       "memoryallocatedbytes": 0,
       "memoryallocatedpercentage": "0%",
       "memorytotal": 8589934592,
       "memoryused": 0,
       "memorywithoverprovisioning": "8589934592",
       "name": "SimulatedAgent.200634f3-68d0-48ca-89d2-9630e2df1ac4",
       "networkkbsread": 32768,
       "networkkbswrite": 16384,
       "oscategoryid": "e4992bed-5fdf-11ea-9a56-1e006800018c",
       "oscategoryname": "CentOS",
       "outofbandmanagement": {
           "action": "",
           "address": "",
           "description": "",
           "driver": "",
           "enabled": false,
           "hostid": "",
           "jobid": "",
           "jobstatus": 0,
           "password": "",
           "port": "",
           "powerstate": "Disabled",
           "status": false,
           "username": ""
       },
       "podid": "83a739b7-bf5f-481e-8016-3a6045045e0b",
       "podname": "DemoSIGPod",
       "removed": "",
       "resourcestate": "Enabled",
       "state": "Up",
       "suitableformigration": false,
       "type": "Routing",
       "ueficapability": false,
       "username": "",
       "version": "4.14.0.0-SNAPSHOT",
       "zoneid": "b6afade4-1919-4f0b-a785-12ff05a4d383",
       "zonename": "DemoSIGZone"
   }
   
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to