Skip to content
GitLab
Explore
Sign in
Commits on Source (1)
Added center methods and updated field based on API responses
· e2ad0ea9
Joost Evertse
authored
Sep 27, 2024
e2ad0ea9
Hide whitespace changes
Inline
Side-by-side
center.go
View file @
e2ad0ea9
...
...
@@ -3,6 +3,7 @@ package leostream
import
(
"encoding/json"
"fmt"
"errors"
"net/http"
"strings"
)
...
...
@@ -77,3 +78,49 @@ func (c *Client) CreateCenter(center Center, authToken *string) (*CenterStored,
return
&
newCenter
,
nil
}
// UpdateCenter - Update existing center
func
(
c
*
Client
)
UpdateCenter
(
centerID
string
,
center
Center
,
authToken
*
string
)
(
*
CenterStored
,
error
)
{
rb
,
err
:=
json
.
Marshal
(
center
)
if
err
!=
nil
{
return
nil
,
err
}
req
,
err
:=
http
.
NewRequest
(
"PUT"
,
fmt
.
Sprintf
(
"%s/rest/v1/centers/amazon/%s"
,
c
.
HostURL
,
centerID
),
strings
.
NewReader
(
string
(
rb
)))
if
err
!=
nil
{
return
nil
,
err
}
body
,
err
:=
c
.
doRequest
(
req
,
authToken
)
if
err
!=
nil
{
return
nil
,
err
}
updatedCenter
:=
CenterStored
{}
err
=
json
.
Unmarshal
(
body
,
&
updatedCenter
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
updatedCenter
,
nil
}
// DeleteCenter - Deletes an center
func
(
c
*
Client
)
DeleteCenter
(
centerID
string
,
authToken
*
string
)
error
{
req
,
err
:=
http
.
NewRequest
(
"DELETE"
,
fmt
.
Sprintf
(
"%s/rest/v1/centers/%s"
,
c
.
HostURL
,
centerID
),
nil
)
if
err
!=
nil
{
return
err
}
body
,
err
:=
c
.
doRequest
(
req
,
authToken
)
if
err
!=
nil
{
return
err
}
if
string
(
body
)
!=
""
{
return
errors
.
New
(
string
(
body
))
}
return
nil
}
models.go
View file @
e2ad0ea9
...
...
@@ -15,16 +15,16 @@ type CenterSummary struct {
// Center -
type
Center
struct
{
I
d
int64
`json:"id,omitempty"`
I
D
int64
`json:"id,omitempty"`
Status
int64
`json:"status,omitempty"`
Center_definition
CenterDefinition
`json:"center_definition,omitempty"`
Status_label
string
`json:"status_label,omitempty"`
Uuid
string
`json:"uuid,omitempty"`
Images
*
[]
AwsImage
s
`json:"images,omitempty"`
Images
[]
AwsImage
`json:"images,omitempty"`
Updated
string
`json:"updated,omitempty"`
Online
int64
`json:"online,omitempty"`
Needs_upgrade
int64
`json:"needs_upgrade,omitempty"`
Info
*
CenterInfo
`json:"info,omitempty"`
Center_info
*
CenterInfo
`json:"
center_
info,omitempty"`
Created
string
`json:"created,omitempty"`
Active
int64
`json:"active,omitempty"`
}
...
...
@@ -36,23 +36,23 @@ type CenterStored struct {
type
CenterDefinition
struct
{
Name
string
`json:"name,omitempty"`
Type
string
`json:"type
,omitempty
"`
Type_label
string
`json:"type_label
,omitempty
"`
Vc_datacenter
string
`json:"vc_datacenter
,omitempty
"`
Vc_auth_method
string
`json:"vc_auth_method
,omitempty
"`
Vc_name
string
`json:"vc_name
,omitempty
"`
Type
string
`json:"type"`
Type_label
string
`json:"type_label"`
Vc_datacenter
string
`json:"vc_datacenter"`
Vc_auth_method
string
`json:"vc_auth_method"`
Vc_name
string
`json:"vc_name"`
Vc_password
string
`json:"vc_password,omitempty"`
Proxy_address
string
`json:"proxy_address
,omitempty
"`
Notes
string
`json:"notes
,omitempty
"`
Allow_rogue
int64
`json:"allow_rogue
,omitempty
"`
Init_unavailable
int64
`json:"init_unavailable
,omitempty
"`
New_as_deletable
int64
`json:"new_as_deletable
,omitempty
"`
Proxy_address
string
`json:"proxy_address"`
Notes
string
`json:"notes"`
Allow_rogue
int64
`json:"allow_rogue"`
Init_unavailable
int64
`json:"init_unavailable"`
New_as_deletable
int64
`json:"new_as_deletable"`
Offer_vms
int64
`json:"off_vms,omitempty"`
Poll_interval
int64
`json:"poll_interval
,omitempty
"`
Allow_rogue_policy_id
int64
`json:"allow_rogue_policy_id
,omitempty
"`
Continuous_autotag
int64
`json:"continuous_autotag
,omitempty
"`
Wait_inst_status
int64
`json:"wait_inst_status
,omitempty
"`
Wait_sys_status
int64
`json:"wait_sys_status
,omitempty
"`
Poll_interval
int64
`json:"poll_interval"`
Allow_rogue_policy_id
int64
`json:"allow_rogue_policy_id"`
Continuous_autotag
int64
`json:"continuous_autotag"`
Wait_inst_status
int64
`json:"wait_inst_status"`
Wait_sys_status
int64
`json:"wait_sys_status"`
Custom_code
string
`json:"_custom_code,omitempty"`
Custom_endpoint
string
`json:"_custom_endpoint,omitempty"`
Custom_name
string
`json:"_custom_name,omitempty"`
...
...
@@ -61,10 +61,9 @@ type CenterDefinition struct {
type
CenterInfo
struct
{
Aws_sec_groups
[]
Aws_sec_groups
`json:"aws_sec_groups,omitempty"`
Aws_sizes
[]
string
`json:"aws_sizes,omitempty"`
Aws_subnets
[]
string
`json:"aws_subnets,omitempty"`
Aws_sub
_
nets
[]
string
`json:"aws_sub
_
nets,omitempty"`
Os
string
`json:"os,omitempty"`
Os_version
string
`json:"os_version,omitempty"`
Type
string
`json:"type,omitempty"`
}
type
Aws_sec_groups
struct
{
...
...
@@ -74,14 +73,14 @@ type Aws_sec_groups struct {
VpcId
string
`json:"vpcId,omitempty"`
}
type
AwsImage
s
struct
{
type
AwsImage
struct
{
ID
int64
`json:"id,omitempty"`
Name
string
`json:"name,omitempty"`
}
// Gateway -
type
Gateway
struct
{
ID
int64
`json:"id"`
ID
int64
`json:"id
,omitempty
"`
Name
string
`json:"name"`
Address
string
`json:"address"`
Address_private
string
`json:"address_private"`
...
...
@@ -111,7 +110,7 @@ type Provision struct {
Provision_on_off
int64
`json:"provision_on_off"`
Provision_tenant_id
int64
`json:"provision_tenant_id"`
Provision_threshold
int64
`json:"provision_threshold"`
Provision_vm_id
int64
`json:"provision_vm_id"`
Provision_vm_id
int64
`json:"provision_vm_id
,omitempty
"`
Provision_vm_name
string
`json:"provision_vm_name"`
Provision_vm_name_next_value
int64
`json:"provision_vm_name_next_value"`
Provision_vm_display_name
string
`json:"provision_vm_display_name"`
...
...
@@ -119,24 +118,31 @@ type Provision struct {
Provision_server_id
int64
`json:"provision_server_id"`
Provision_max
int64
`json:"provision_max"`
Provision_limits_enforce
int64
`json:"provision_limits_enforce"`
Mark_deleteable
int64
`json:"mark_deletable"`
Mark_unavailable
int64
`json:"mark_unavailable"`
Mark_deletable
int64
`json:"mark_deletable"`
Time_limits
*
[]
PoolTimeLimits
`json:"time_limits,omitempty"`
Center
*
PoolAwsCenter
`json:"center,omitempty"`
}
type
ProvisioningActions
struct
{
Prov_action_action
string
`json:"prov_action_action,omitempty"`
Prov_action_wait_unit
string
`json:"prov_action_wait_unit,omitempty"`
Prov_action_wait_value
int64
`json:"prov_action_wait_value,omitempty"`
}
type
PoolAwsCenter
struct
{
ID
int64
`json:"id,omitempty"`
Name
string
`json:"name,omitempty"`
Type
string
`json:"type,omitempty"`
Aws_size
string
`json:"aws_size,omitempty"`
Aws_t2_unlimited
int64
`json:"aws_t2_unlimited,omitempty"`
Aws_iam_name
string
`json:"aws_iam_name,omitempty"`
Aws_sub_net
string
`json:"aws_sub_net,omitempty"`
Aws_sec_group
string
`json:"aws_sec_group,omitempty"`
Aws_vpc_id
string
`json:"aws_vpc_id,omitempty"`
Vc_resource_pool_id
int64
`json:"vc_resource_pool_id,omitempty"`
Vc_spec_file_id
int64
`json:"vc_spec_file_id,omitempty"`
ID
int64
`json:"id,omitempty"`
Name
string
`json:"name,omitempty"`
Type
string
`json:"type,omitempty"`
Aws_size
string
`json:"aws_size,omitempty"`
Aws_t2_unlimited
int64
`json:"aws_t2_unlimited,omitempty"`
Aws_iam_name
string
`json:"aws_iam_name,omitempty"`
Aws_sub_net
string
`json:"aws_sub_net,omitempty"`
Aws_sec_group
string
`json:"aws_sec_group,omitempty"`
Aws_vpc_id
string
`json:"aws_vpc_id,omitempty"`
Vc_resource_pool_id
int64
`json:"vc_resource_pool_id,omitempty"`
Vc_spec_file_id
int64
`json:"vc_spec_file_id,omitempty"`
Provision_method
string
`json:"provision_time,omitempty"`
Provisioning_actions
[]
ProvisioningActions
`json:"provisioning_actions,omitempty"`
}
// Pool summary
...
...
@@ -167,8 +173,12 @@ type Pool struct {
Provision
*
Provision
`json:"provision,omitempty"`
PoolStats
*
PoolStats
`json:"pool_stats,omitempty"`
Pool_domain
*
PoolDomain
`json:"pool_domain,omitempty"`
Pool_log
*
PoolLog
`json:"pool_log,omitempty"`
Log
*
PoolLog
`json:"pool_log,omitempty"`
Vms_list
*
[]
Vms
`json:"vms_list,omitempty"`
Is_root
int64
`json:"is_root,omitempty"`
Pool_type
string
`json:"pool_type,omitempty"`
Read_only
int64
`json:"read_only,omitempty"`
Vc_datastore_id
int64
`json:"vc_datastore_id,omitempty"`
}
type
Vms
struct
{
...
...
@@ -183,6 +193,9 @@ type Vms struct {
type
PoolDefinition
struct
{
Restrict_by
string
`json:"restrict_by,omitempty"`
Restrict_by_desc
string
`json:"restrict_by_desc,omitempty"`
Parent_pool_id
int64
`json:"parent_pool_id,omitempty"`
Parent_pool_name
string
`json:"parent_pool_name,omitempty"`
Vm_tags
[]
string
`json:"vm_tags,omitempty"`
Vm_tags_join
string
`json:"vm_tags_join,omitempty"`
Pool_attribute_join
string
`json:"pool_attribute_join,omitempty"`
...
...
@@ -191,7 +204,7 @@ type PoolDefinition struct {
Adhoc_vc_clusters
[]
int64
`json:"adhoc_vc_clusters,omitempty"`
Adhoc_vc_resource_pools
[]
int64
`json:"adhoc_vc_resource_pools,omitempty"`
Never_rogue
int64
`json:"never_rogue"`
Server_ids
[]
int64
`json:"server_ids
,omitempty"
`
Server_ids
[]
int64
`json:"server_ids`
Use_vmotion
int64
`json:"use_vmotion"`
Vm_server_distribution
int64
`json:"vm_server_distribution,omitempty"`
Attributes
[]
PoolAttributes
`json:"attributes,omitempty"`
...
...
@@ -199,8 +212,8 @@ type PoolDefinition struct {
type
PoolAttributes
struct
{
Vm_table_field
string
`json:"vm_table_field,omitempty"`
Ad_attribute_field
string
`json:"ad_attribute_field"`
Vm_gpu_field
string
`json:"vm_gpu_field"`
Ad_attribute_field
string
`json:"ad_attribute_field
,omitempty
"`
Vm_gpu_field
string
`json:"vm_gpu_field
,omitempty
"`
Text_to_match
string
`json:"text_to_match,omitempty"`
Condition_type
string
`json:"condition_type,omitempty"`
}
...
...
@@ -217,6 +230,7 @@ type PoolDomain struct {
Domain_join
int64
`json:"domain_join,omitempty"`
Domain_join_ou
string
`json:"domain_join_ou,omitempty"`
Domain_join_hostname_as_vm_name
int64
`json:"domain_join_hostname_as_vm_name,omitempty"`
Domain_join_remove_on_delete
int64
`json:"domain_join_remove_on_delete,omitempty"`
Remote_authentication
PoolRemoteAuthentication
`json:"remote_authentication,omitempty"`
Pool_join_ad_groups
[]
PoolJoinAdGroups
`json:"pool_join_ad_groups,omitempty"`
}
...
...
@@ -226,7 +240,8 @@ type PoolJoinAdGroups struct {
}
type
PoolRemoteAuthentication
struct
{
Domain_join_remote_authentication_id
int64
`json:"domain_join_remote_authentication_id,omitempty"`
Domain_join_remote_authentication_id
int64
`json:"domain_join_remote_authentication_id,omitempty"`
Name
string
`json:name,omitempty`
}
type
PoolLog
struct
{
...
...