Skip to content

Commit 2a9d991

Browse files
author
Pearl Dsilva
committed
Add support for managing guest OS category - create, delete, update
1 parent ec462f4 commit 2a9d991

4 files changed

Lines changed: 471 additions & 0 deletions

File tree

cloudstack/GuestOSService.go

Lines changed: 339 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ type GuestOSServiceIface interface {
5555
NewUpdateGuestOsMappingParams(id string, osnameforhypervisor string) *UpdateGuestOsMappingParams
5656
GetHypervisorGuestOsNames(p *GetHypervisorGuestOsNamesParams) (*GetHypervisorGuestOsNamesResponse, error)
5757
NewGetHypervisorGuestOsNamesParams(hypervisor string, hypervisorversion string) *GetHypervisorGuestOsNamesParams
58+
AddOsCategory(p *AddOsCategoryParams) (*AddOsCategoryResponse, error)
59+
NewAddOsCategoryParams(name string) *AddOsCategoryParams
60+
DeleteOsCategory(p *DeleteOsCategoryParams) (*DeleteOsCategoryResponse, error)
61+
NewDeleteOsCategoryParams(id string) *DeleteOsCategoryParams
62+
UpdateOsCategory(p *UpdateOsCategoryParams) (*UpdateOsCategoryResponse, error)
63+
NewUpdateOsCategoryParams(id string) *UpdateOsCategoryParams
5864
}
5965

6066
type AddGuestOsParams struct {
@@ -2251,3 +2257,336 @@ type GetHypervisorGuestOsNamesResponseGuestoslist struct {
22512257
Osdisplayname string `json:"osdisplayname"`
22522258
Osnameforhypervisor string `json:"osnameforhypervisor"`
22532259
}
2260+
2261+
type AddOsCategoryParams struct {
2262+
p map[string]interface{}
2263+
}
2264+
2265+
func (p *AddOsCategoryParams) toURLValues() url.Values {
2266+
u := url.Values{}
2267+
if p.p == nil {
2268+
return u
2269+
}
2270+
if v, found := p.p["isfeatured"]; found {
2271+
vv := strconv.FormatBool(v.(bool))
2272+
u.Set("isfeatured", vv)
2273+
}
2274+
if v, found := p.p["name"]; found {
2275+
u.Set("name", v.(string))
2276+
}
2277+
return u
2278+
}
2279+
2280+
func (p *AddOsCategoryParams) SetIsfeatured(v bool) {
2281+
if p.p == nil {
2282+
p.p = make(map[string]interface{})
2283+
}
2284+
p.p["isfeatured"] = v
2285+
}
2286+
2287+
func (p *AddOsCategoryParams) ResetIsfeatured() {
2288+
if p.p != nil && p.p["isfeatured"] != nil {
2289+
delete(p.p, "isfeatured")
2290+
}
2291+
}
2292+
2293+
func (p *AddOsCategoryParams) GetIsfeatured() (bool, bool) {
2294+
if p.p == nil {
2295+
p.p = make(map[string]interface{})
2296+
}
2297+
value, ok := p.p["isfeatured"].(bool)
2298+
return value, ok
2299+
}
2300+
2301+
func (p *AddOsCategoryParams) SetName(v string) {
2302+
if p.p == nil {
2303+
p.p = make(map[string]interface{})
2304+
}
2305+
p.p["name"] = v
2306+
}
2307+
2308+
func (p *AddOsCategoryParams) ResetName() {
2309+
if p.p != nil && p.p["name"] != nil {
2310+
delete(p.p, "name")
2311+
}
2312+
}
2313+
2314+
func (p *AddOsCategoryParams) GetName() (string, bool) {
2315+
if p.p == nil {
2316+
p.p = make(map[string]interface{})
2317+
}
2318+
value, ok := p.p["name"].(string)
2319+
return value, ok
2320+
}
2321+
2322+
// You should always use this function to get a new AddOsCategoryParams instance,
2323+
// as then you are sure you have configured all required params
2324+
func (s *GuestOSService) NewAddOsCategoryParams(name string) *AddOsCategoryParams {
2325+
p := &AddOsCategoryParams{}
2326+
p.p = make(map[string]interface{})
2327+
p.p["name"] = name
2328+
return p
2329+
}
2330+
2331+
// Adds a new OS category
2332+
func (s *GuestOSService) AddOsCategory(p *AddOsCategoryParams) (*AddOsCategoryResponse, error) {
2333+
resp, err := s.cs.newPostRequest("addOsCategory", p.toURLValues())
2334+
if err != nil {
2335+
return nil, err
2336+
}
2337+
2338+
var r AddOsCategoryResponse
2339+
if err := json.Unmarshal(resp, &r); err != nil {
2340+
return nil, err
2341+
}
2342+
2343+
return &r, nil
2344+
}
2345+
2346+
type AddOsCategoryResponse struct {
2347+
Created string `json:"created"`
2348+
Icon interface{} `json:"icon"`
2349+
Id string `json:"id"`
2350+
Isfeatured bool `json:"isfeatured"`
2351+
JobID string `json:"jobid"`
2352+
Jobstatus int `json:"jobstatus"`
2353+
Name string `json:"name"`
2354+
}
2355+
2356+
type DeleteOsCategoryParams struct {
2357+
p map[string]interface{}
2358+
}
2359+
2360+
func (p *DeleteOsCategoryParams) toURLValues() url.Values {
2361+
u := url.Values{}
2362+
if p.p == nil {
2363+
return u
2364+
}
2365+
if v, found := p.p["id"]; found {
2366+
u.Set("id", v.(string))
2367+
}
2368+
return u
2369+
}
2370+
2371+
func (p *DeleteOsCategoryParams) SetId(v string) {
2372+
if p.p == nil {
2373+
p.p = make(map[string]interface{})
2374+
}
2375+
p.p["id"] = v
2376+
}
2377+
2378+
func (p *DeleteOsCategoryParams) ResetId() {
2379+
if p.p != nil && p.p["id"] != nil {
2380+
delete(p.p, "id")
2381+
}
2382+
}
2383+
2384+
func (p *DeleteOsCategoryParams) GetId() (string, bool) {
2385+
if p.p == nil {
2386+
p.p = make(map[string]interface{})
2387+
}
2388+
value, ok := p.p["id"].(string)
2389+
return value, ok
2390+
}
2391+
2392+
// You should always use this function to get a new DeleteOsCategoryParams instance,
2393+
// as then you are sure you have configured all required params
2394+
func (s *GuestOSService) NewDeleteOsCategoryParams(id string) *DeleteOsCategoryParams {
2395+
p := &DeleteOsCategoryParams{}
2396+
p.p = make(map[string]interface{})
2397+
p.p["id"] = id
2398+
return p
2399+
}
2400+
2401+
// Deletes an OS category
2402+
func (s *GuestOSService) DeleteOsCategory(p *DeleteOsCategoryParams) (*DeleteOsCategoryResponse, error) {
2403+
resp, err := s.cs.newPostRequest("deleteOsCategory", p.toURLValues())
2404+
if err != nil {
2405+
return nil, err
2406+
}
2407+
2408+
var r DeleteOsCategoryResponse
2409+
if err := json.Unmarshal(resp, &r); err != nil {
2410+
return nil, err
2411+
}
2412+
2413+
return &r, nil
2414+
}
2415+
2416+
type DeleteOsCategoryResponse struct {
2417+
Displaytext string `json:"displaytext"`
2418+
JobID string `json:"jobid"`
2419+
Jobstatus int `json:"jobstatus"`
2420+
Success bool `json:"success"`
2421+
}
2422+
2423+
func (r *DeleteOsCategoryResponse) UnmarshalJSON(b []byte) error {
2424+
var m map[string]interface{}
2425+
err := json.Unmarshal(b, &m)
2426+
if err != nil {
2427+
return err
2428+
}
2429+
2430+
if success, ok := m["success"].(string); ok {
2431+
m["success"] = success == "true"
2432+
b, err = json.Marshal(m)
2433+
if err != nil {
2434+
return err
2435+
}
2436+
}
2437+
2438+
if ostypeid, ok := m["ostypeid"].(float64); ok {
2439+
m["ostypeid"] = strconv.Itoa(int(ostypeid))
2440+
b, err = json.Marshal(m)
2441+
if err != nil {
2442+
return err
2443+
}
2444+
}
2445+
2446+
type alias DeleteOsCategoryResponse
2447+
return json.Unmarshal(b, (*alias)(r))
2448+
}
2449+
2450+
type UpdateOsCategoryParams struct {
2451+
p map[string]interface{}
2452+
}
2453+
2454+
func (p *UpdateOsCategoryParams) toURLValues() url.Values {
2455+
u := url.Values{}
2456+
if p.p == nil {
2457+
return u
2458+
}
2459+
if v, found := p.p["id"]; found {
2460+
u.Set("id", v.(string))
2461+
}
2462+
if v, found := p.p["isfeatured"]; found {
2463+
vv := strconv.FormatBool(v.(bool))
2464+
u.Set("isfeatured", vv)
2465+
}
2466+
if v, found := p.p["name"]; found {
2467+
u.Set("name", v.(string))
2468+
}
2469+
if v, found := p.p["sortkey"]; found {
2470+
vv := strconv.Itoa(v.(int))
2471+
u.Set("sortkey", vv)
2472+
}
2473+
return u
2474+
}
2475+
2476+
func (p *UpdateOsCategoryParams) SetId(v string) {
2477+
if p.p == nil {
2478+
p.p = make(map[string]interface{})
2479+
}
2480+
p.p["id"] = v
2481+
}
2482+
2483+
func (p *UpdateOsCategoryParams) ResetId() {
2484+
if p.p != nil && p.p["id"] != nil {
2485+
delete(p.p, "id")
2486+
}
2487+
}
2488+
2489+
func (p *UpdateOsCategoryParams) GetId() (string, bool) {
2490+
if p.p == nil {
2491+
p.p = make(map[string]interface{})
2492+
}
2493+
value, ok := p.p["id"].(string)
2494+
return value, ok
2495+
}
2496+
2497+
func (p *UpdateOsCategoryParams) SetIsfeatured(v bool) {
2498+
if p.p == nil {
2499+
p.p = make(map[string]interface{})
2500+
}
2501+
p.p["isfeatured"] = v
2502+
}
2503+
2504+
func (p *UpdateOsCategoryParams) ResetIsfeatured() {
2505+
if p.p != nil && p.p["isfeatured"] != nil {
2506+
delete(p.p, "isfeatured")
2507+
}
2508+
}
2509+
2510+
func (p *UpdateOsCategoryParams) GetIsfeatured() (bool, bool) {
2511+
if p.p == nil {
2512+
p.p = make(map[string]interface{})
2513+
}
2514+
value, ok := p.p["isfeatured"].(bool)
2515+
return value, ok
2516+
}
2517+
2518+
func (p *UpdateOsCategoryParams) SetName(v string) {
2519+
if p.p == nil {
2520+
p.p = make(map[string]interface{})
2521+
}
2522+
p.p["name"] = v
2523+
}
2524+
2525+
func (p *UpdateOsCategoryParams) ResetName() {
2526+
if p.p != nil && p.p["name"] != nil {
2527+
delete(p.p, "name")
2528+
}
2529+
}
2530+
2531+
func (p *UpdateOsCategoryParams) GetName() (string, bool) {
2532+
if p.p == nil {
2533+
p.p = make(map[string]interface{})
2534+
}
2535+
value, ok := p.p["name"].(string)
2536+
return value, ok
2537+
}
2538+
2539+
func (p *UpdateOsCategoryParams) SetSortkey(v int) {
2540+
if p.p == nil {
2541+
p.p = make(map[string]interface{})
2542+
}
2543+
p.p["sortkey"] = v
2544+
}
2545+
2546+
func (p *UpdateOsCategoryParams) ResetSortkey() {
2547+
if p.p != nil && p.p["sortkey"] != nil {
2548+
delete(p.p, "sortkey")
2549+
}
2550+
}
2551+
2552+
func (p *UpdateOsCategoryParams) GetSortkey() (int, bool) {
2553+
if p.p == nil {
2554+
p.p = make(map[string]interface{})
2555+
}
2556+
value, ok := p.p["sortkey"].(int)
2557+
return value, ok
2558+
}
2559+
2560+
// You should always use this function to get a new UpdateOsCategoryParams instance,
2561+
// as then you are sure you have configured all required params
2562+
func (s *GuestOSService) NewUpdateOsCategoryParams(id string) *UpdateOsCategoryParams {
2563+
p := &UpdateOsCategoryParams{}
2564+
p.p = make(map[string]interface{})
2565+
p.p["id"] = id
2566+
return p
2567+
}
2568+
2569+
// Updates an OS category
2570+
func (s *GuestOSService) UpdateOsCategory(p *UpdateOsCategoryParams) (*UpdateOsCategoryResponse, error) {
2571+
resp, err := s.cs.newPostRequest("updateOsCategory", p.toURLValues())
2572+
if err != nil {
2573+
return nil, err
2574+
}
2575+
2576+
var r UpdateOsCategoryResponse
2577+
if err := json.Unmarshal(resp, &r); err != nil {
2578+
return nil, err
2579+
}
2580+
2581+
return &r, nil
2582+
}
2583+
2584+
type UpdateOsCategoryResponse struct {
2585+
Created string `json:"created"`
2586+
Icon interface{} `json:"icon"`
2587+
Id string `json:"id"`
2588+
Isfeatured bool `json:"isfeatured"`
2589+
JobID string `json:"jobid"`
2590+
Jobstatus int `json:"jobstatus"`
2591+
Name string `json:"name"`
2592+
}

0 commit comments

Comments
 (0)