|
39 | 39 | _ = namegenerator.GetRandomName |
40 | 40 | ) |
41 | 41 |
|
| 42 | +type ConnectivityDiagnosticActionType string |
| 43 | + |
| 44 | +const ( |
| 45 | + ConnectivityDiagnosticActionTypeRebootServer = ConnectivityDiagnosticActionType("reboot_server") |
| 46 | + ConnectivityDiagnosticActionTypeReinstallServer = ConnectivityDiagnosticActionType("reinstall_server") |
| 47 | +) |
| 48 | + |
| 49 | +func (enum ConnectivityDiagnosticActionType) String() string { |
| 50 | + if enum == "" { |
| 51 | + // return default value if empty |
| 52 | + return "reboot_server" |
| 53 | + } |
| 54 | + return string(enum) |
| 55 | +} |
| 56 | + |
| 57 | +func (enum ConnectivityDiagnosticActionType) Values() []ConnectivityDiagnosticActionType { |
| 58 | + return []ConnectivityDiagnosticActionType{ |
| 59 | + "reboot_server", |
| 60 | + "reinstall_server", |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +func (enum ConnectivityDiagnosticActionType) MarshalJSON() ([]byte, error) { |
| 65 | + return []byte(fmt.Sprintf(`"%s"`, enum)), nil |
| 66 | +} |
| 67 | + |
| 68 | +func (enum *ConnectivityDiagnosticActionType) UnmarshalJSON(data []byte) error { |
| 69 | + tmp := "" |
| 70 | + |
| 71 | + if err := json.Unmarshal(data, &tmp); err != nil { |
| 72 | + return err |
| 73 | + } |
| 74 | + |
| 75 | + *enum = ConnectivityDiagnosticActionType(ConnectivityDiagnosticActionType(tmp).String()) |
| 76 | + return nil |
| 77 | +} |
| 78 | + |
| 79 | +type ConnectivityDiagnosticDiagnosticStatus string |
| 80 | + |
| 81 | +const ( |
| 82 | + ConnectivityDiagnosticDiagnosticStatusUnknownStatus = ConnectivityDiagnosticDiagnosticStatus("unknown_status") |
| 83 | + ConnectivityDiagnosticDiagnosticStatusProcessing = ConnectivityDiagnosticDiagnosticStatus("processing") |
| 84 | + ConnectivityDiagnosticDiagnosticStatusError = ConnectivityDiagnosticDiagnosticStatus("error") |
| 85 | + ConnectivityDiagnosticDiagnosticStatusCompleted = ConnectivityDiagnosticDiagnosticStatus("completed") |
| 86 | +) |
| 87 | + |
| 88 | +func (enum ConnectivityDiagnosticDiagnosticStatus) String() string { |
| 89 | + if enum == "" { |
| 90 | + // return default value if empty |
| 91 | + return "unknown_status" |
| 92 | + } |
| 93 | + return string(enum) |
| 94 | +} |
| 95 | + |
| 96 | +func (enum ConnectivityDiagnosticDiagnosticStatus) Values() []ConnectivityDiagnosticDiagnosticStatus { |
| 97 | + return []ConnectivityDiagnosticDiagnosticStatus{ |
| 98 | + "unknown_status", |
| 99 | + "processing", |
| 100 | + "error", |
| 101 | + "completed", |
| 102 | + } |
| 103 | +} |
| 104 | + |
| 105 | +func (enum ConnectivityDiagnosticDiagnosticStatus) MarshalJSON() ([]byte, error) { |
| 106 | + return []byte(fmt.Sprintf(`"%s"`, enum)), nil |
| 107 | +} |
| 108 | + |
| 109 | +func (enum *ConnectivityDiagnosticDiagnosticStatus) UnmarshalJSON(data []byte) error { |
| 110 | + tmp := "" |
| 111 | + |
| 112 | + if err := json.Unmarshal(data, &tmp); err != nil { |
| 113 | + return err |
| 114 | + } |
| 115 | + |
| 116 | + *enum = ConnectivityDiagnosticDiagnosticStatus(ConnectivityDiagnosticDiagnosticStatus(tmp).String()) |
| 117 | + return nil |
| 118 | +} |
| 119 | + |
42 | 120 | type ListServersRequestOrderBy string |
43 | 121 |
|
44 | 122 | const ( |
@@ -233,6 +311,21 @@ type ServerTypeNetwork struct { |
233 | 311 | PublicBandwidthBps uint64 `json:"public_bandwidth_bps"` |
234 | 312 | } |
235 | 313 |
|
| 314 | +// ConnectivityDiagnosticServerHealth: connectivity diagnostic server health. |
| 315 | +type ConnectivityDiagnosticServerHealth struct { |
| 316 | + LastCheckinDate *time.Time `json:"last_checkin_date"` |
| 317 | + |
| 318 | + IsServerAlive bool `json:"is_server_alive"` |
| 319 | + |
| 320 | + IsAgentAlive bool `json:"is_agent_alive"` |
| 321 | + |
| 322 | + IsMdmAlive bool `json:"is_mdm_alive"` |
| 323 | + |
| 324 | + IsSSHPortUp bool `json:"is_ssh_port_up"` |
| 325 | + |
| 326 | + IsVncPortUp bool `json:"is_vnc_port_up"` |
| 327 | +} |
| 328 | + |
236 | 329 | // ServerType: server type. |
237 | 330 | type ServerType struct { |
238 | 331 | // CPU: CPU description. |
@@ -322,6 +415,22 @@ type Server struct { |
322 | 415 | Delivered bool `json:"delivered"` |
323 | 416 | } |
324 | 417 |
|
| 418 | +// ConnectivityDiagnostic: connectivity diagnostic. |
| 419 | +type ConnectivityDiagnostic struct { |
| 420 | + ID string `json:"id"` |
| 421 | + |
| 422 | + // Status: default value: unknown_status |
| 423 | + Status ConnectivityDiagnosticDiagnosticStatus `json:"status"` |
| 424 | + |
| 425 | + IsHealthy bool `json:"is_healthy"` |
| 426 | + |
| 427 | + HealthDetails *ConnectivityDiagnosticServerHealth `json:"health_details"` |
| 428 | + |
| 429 | + SupportedActions []ConnectivityDiagnosticActionType `json:"supported_actions"` |
| 430 | + |
| 431 | + ErrorMessage string `json:"error_message"` |
| 432 | +} |
| 433 | + |
325 | 434 | // CreateServerRequest: create server request. |
326 | 435 | type CreateServerRequest struct { |
327 | 436 | // Zone: zone to target. If none is passed will use default zone from the config. |
@@ -349,6 +458,14 @@ type DeleteServerRequest struct { |
349 | 458 | ServerID string `json:"-"` |
350 | 459 | } |
351 | 460 |
|
| 461 | +// GetConnectivityDiagnosticRequest: get connectivity diagnostic request. |
| 462 | +type GetConnectivityDiagnosticRequest struct { |
| 463 | + // Zone: zone to target. If none is passed will use default zone from the config. |
| 464 | + Zone scw.Zone `json:"-"` |
| 465 | + |
| 466 | + DiagnosticID string `json:"-"` |
| 467 | +} |
| 468 | + |
352 | 469 | // GetOSRequest: get os request. |
353 | 470 | type GetOSRequest struct { |
354 | 471 | // Zone: zone to target. If none is passed will use default zone from the config. |
@@ -505,6 +622,19 @@ type ReinstallServerRequest struct { |
505 | 622 | OsID *string `json:"os_id,omitempty"` |
506 | 623 | } |
507 | 624 |
|
| 625 | +// StartConnectivityDiagnosticRequest: start connectivity diagnostic request. |
| 626 | +type StartConnectivityDiagnosticRequest struct { |
| 627 | + // Zone: zone to target. If none is passed will use default zone from the config. |
| 628 | + Zone scw.Zone `json:"-"` |
| 629 | + |
| 630 | + ServerID string `json:"server_id"` |
| 631 | +} |
| 632 | + |
| 633 | +// StartConnectivityDiagnosticResponse: start connectivity diagnostic response. |
| 634 | +type StartConnectivityDiagnosticResponse struct { |
| 635 | + DiagnosticID string `json:"diagnostic_id"` |
| 636 | +} |
| 637 | + |
508 | 638 | // UpdateServerRequest: update server request. |
509 | 639 | type UpdateServerRequest struct { |
510 | 640 | // Zone: zone to target. If none is passed will use default zone from the config. |
@@ -911,3 +1041,66 @@ func (s *API) ReinstallServer(req *ReinstallServerRequest, opts ...scw.RequestOp |
911 | 1041 | } |
912 | 1042 | return &resp, nil |
913 | 1043 | } |
| 1044 | + |
| 1045 | +// StartConnectivityDiagnostic: |
| 1046 | +func (s *API) StartConnectivityDiagnostic(req *StartConnectivityDiagnosticRequest, opts ...scw.RequestOption) (*StartConnectivityDiagnosticResponse, error) { |
| 1047 | + var err error |
| 1048 | + |
| 1049 | + if req.Zone == "" { |
| 1050 | + defaultZone, _ := s.client.GetDefaultZone() |
| 1051 | + req.Zone = defaultZone |
| 1052 | + } |
| 1053 | + |
| 1054 | + if fmt.Sprint(req.Zone) == "" { |
| 1055 | + return nil, errors.New("field Zone cannot be empty in request") |
| 1056 | + } |
| 1057 | + |
| 1058 | + scwReq := &scw.ScalewayRequest{ |
| 1059 | + Method: "POST", |
| 1060 | + Path: "/apple-silicon/v1alpha1/zones/" + fmt.Sprint(req.Zone) + "/connectivity-diagnostics", |
| 1061 | + } |
| 1062 | + |
| 1063 | + err = scwReq.SetBody(req) |
| 1064 | + if err != nil { |
| 1065 | + return nil, err |
| 1066 | + } |
| 1067 | + |
| 1068 | + var resp StartConnectivityDiagnosticResponse |
| 1069 | + |
| 1070 | + err = s.client.Do(scwReq, &resp, opts...) |
| 1071 | + if err != nil { |
| 1072 | + return nil, err |
| 1073 | + } |
| 1074 | + return &resp, nil |
| 1075 | +} |
| 1076 | + |
| 1077 | +// GetConnectivityDiagnostic: |
| 1078 | +func (s *API) GetConnectivityDiagnostic(req *GetConnectivityDiagnosticRequest, opts ...scw.RequestOption) (*ConnectivityDiagnostic, error) { |
| 1079 | + var err error |
| 1080 | + |
| 1081 | + if req.Zone == "" { |
| 1082 | + defaultZone, _ := s.client.GetDefaultZone() |
| 1083 | + req.Zone = defaultZone |
| 1084 | + } |
| 1085 | + |
| 1086 | + if fmt.Sprint(req.Zone) == "" { |
| 1087 | + return nil, errors.New("field Zone cannot be empty in request") |
| 1088 | + } |
| 1089 | + |
| 1090 | + if fmt.Sprint(req.DiagnosticID) == "" { |
| 1091 | + return nil, errors.New("field DiagnosticID cannot be empty in request") |
| 1092 | + } |
| 1093 | + |
| 1094 | + scwReq := &scw.ScalewayRequest{ |
| 1095 | + Method: "GET", |
| 1096 | + Path: "/apple-silicon/v1alpha1/zones/" + fmt.Sprint(req.Zone) + "/connectivity-diagnostics/" + fmt.Sprint(req.DiagnosticID) + "", |
| 1097 | + } |
| 1098 | + |
| 1099 | + var resp ConnectivityDiagnostic |
| 1100 | + |
| 1101 | + err = s.client.Do(scwReq, &resp, opts...) |
| 1102 | + if err != nil { |
| 1103 | + return nil, err |
| 1104 | + } |
| 1105 | + return &resp, nil |
| 1106 | +} |
0 commit comments