Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hypervisor manager #209

Merged
merged 11 commits into from
Apr 16, 2020
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html)


# [v1.3.0](Unreleased)
# [v1.3.0](unreleased)
### Notes
- This release supports for API V800,V1000 and V1200 for HypervisorManager resource
- Added resource files for Server Certificate supporting API V800, V1000, V1200
### Oneview Features supported
- HypervisorManager
- Server Certificate

# [v1.2.0] (2019-12-13)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add space between the version notes

Expand Down
8 changes: 7 additions & 1 deletion endpoints-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@
|<sub>/rest/fcoe-networks/{id}</sub> | PATCH | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_multiplication_x: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: |
|<sub>/rest/fcoe-networks/{id}</sub> | PUT | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/fcoe-networks/{id}</sub> | DELETE | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| **Interconnects** |
| **Hypervisor Managers** |
|<sub>/rest/hypervisor-managers</sub> | GET | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/hypervisor-managers</sub> | POST | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/hypervisor-managers/{id}</sub> | GET | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/hypervisor-managers/{id}</sub> | PUT | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/hypervisor-managers/{id}</sub> | DELETE | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| **Interconnects** |
|<sub>/rest/interconnects</sub> | GET | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/interconnects/{id}</sub> | GET | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| **Interconnect Types** |
Expand Down
82 changes: 82 additions & 0 deletions examples/hypervisor_manager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package main

import (
"fmt"
"github.com/HewlettPackard/oneview-golang/ov"
"github.com/HewlettPackard/oneview-golang/utils"
"os"
)

func main() {
var (
ClientOV *ov.OVClient
hypervisor_manager = "172.18.13.11"
hypervisor_manager_display_name = "HM2"
)
ovc := ClientOV.NewOVClient(
os.Getenv("ONEVIEW_OV_USER"),
os.Getenv("ONEVIEW_OV_PASSWORD"),
os.Getenv("ONEVIEW_OV_DOMAIN"),
os.Getenv("ONEVIEW_OV_ENDPOINT"),
false,
800,
"")
initialScopeUris := &[]utils.Nstring{utils.NewNstring("/rest/scopes/03beb5a0-bf48-4c43-94a5-74b7b5de1255")}
hypervisorManager := ov.HypervisorManager{DisplayName: "HM1",
Name: "172.18.13.11",
Username: "dcs",
Password: "dcs",
Port: 443,
InitialScopeUris: *initialScopeUris,
Type: "HypervisorManagerV2"}

err := ovc.CreateHypervisorManager(hypervisorManager)
if err != nil {
fmt.Println("............... Create Hypervisor Manager Failed:", err)
} else {
fmt.Println(".... Create Hypervisor Manager Success")
}

fmt.Println("#................... Hypervisor Manager by Name ...............#")
hypervisor_mgr, err := ovc.GetHypervisorManagerByName(hypervisor_manager)
if err != nil {
fmt.Println(err)
} else {
fmt.Println(hypervisor_mgr)
}

sort := "name:desc"
hypervisor_mgr_list, err := ovc.GetHypervisorManagers("", "", "", sort)
if err != nil {
fmt.Println(err)
} else {
fmt.Println("# ................... Hypervisor Managers List .................#")
for i := 0; i < len(hypervisor_mgr_list.Members); i++ {
fmt.Println(hypervisor_mgr_list.Members[i].Name)
}
}

hypervisor_mgr.DisplayName = hypervisor_manager_display_name
err = ovc.UpdateHypervisorManager(hypervisor_mgr)
if err != nil {
fmt.Println(err)
} else {
fmt.Println("#.................... Hypervisor Manager after Updating ...........#")
hypervisor_mgr_after_update, err := ovc.GetHypervisorManagers("", "", "", sort)
if err != nil {
fmt.Println(err)
} else {
for i := 0; i < len(hypervisor_mgr_after_update.Members); i++ {
fmt.Println(hypervisor_mgr_after_update.Members[i].Name)
}
}
}

err = ovc.DeleteHypervisorManager(hypervisor_manager)
if err != nil {
fmt.Println(err)
} else {
fmt.Println("#...................... Deleteed Hypervisor Manager Successfully .....#")
}

}
234 changes: 234 additions & 0 deletions ov/hypervisor_manager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
package ov

import (
"encoding/json"
"fmt"
"github.com/HewlettPackard/oneview-golang/rest"
"github.com/HewlettPackard/oneview-golang/utils"
"github.com/docker/machine/libmachine/log"
)

type HypervisorManager struct {
Category string `json:"category,omitempty"` // "category": "hypervisor-managers",
AvailableDvsVersions []utils.Nstring `json:"availableDvsVersions,omitempty"` // "availableDvsVersions": "",
Created string `json:"created,omitempty"` // "created": "20150831T154835.250Z",
Description utils.Nstring `json:"description,omitempty"` // "description": "Hypervisor Manager 1",
DisplayName string `json:"displayName,omitempty"` // "displayName": "HypervisorManager1",
ETAG string `json:"eTag,omitempty"` // "eTag": "1441036118675/8",
HypervisorType string `json:"hypervisorType,omitempty"` // "hypervisorType": "HyperV","Vmware",
Modified string `json:"modified,omitempty"` // "modified": "20150831T154835.250Z",
Name string `json:"name,omitempty"` // "name": "hostname or IP",
Password string `json:"password,omitempty"` // "password": "",
Port int `json:"port,omitempty"` // "port": 443,
Preferences *Preference `json:"preferences"` // "preferences": HypervisorClusterSettings,
RefreshState string `json:"refreshState,omitempty"` // "refreshState": "NotRfreshing",
ResourcePaths []ResourcePath `json:"resourcePaths,omitempty"` //"resourcePaths":""
ScopesUri utils.Nstring `json:"scopesUri,omitempty"` // "scopesUri":
State string `json:"state,omitempty"` // "state": "Connected",
StateReason string `json:"stateReason,omitempty"` // "state": "",
Status string `json:"status,omitempty"` // "status": "Critical",
Type string `json:"type,omitempty"` // "type": "HypervisorManagerV2",
URI utils.Nstring `json:"uri,omitempty"` // "uri": "/rest/hypervisor-managers/e2f0031b-52bd-4223-9ac1-d91cb519d548"
Username string `json:"username,omitempty"` // "username": "name1",
Version string `json:"version,omitempty"` // "version": ""
InitialScopeUris []utils.Nstring `json:"initialScopeUris,omitempty"` // "initialScopUris":
}

type ResourcePath struct {
UserPath string `json:"userPath,omitempty"` // "userPath":"DC1"
ActualPath string `json:"actualPath,omitempty"` // "actualPath":"DC1/host"
}

type Preference struct {
Type string `json:"type"` //"type":"Vmware"
VirtualSwitchType string `json:"virtualSwitchType"` // "virtualSwitchType":"Standard"
DistributedSwitchVersion string `json:"distributedSwitchVersion,omitempty"` //"distributedSwitchVersion":null
DistributedSwitchUsage string `json:"distributedSwitchUsage,omitempty"` //"distributedSwitchUsage":null
MultiNicVMotion bool `json:"multiNicVMotion"` //"multiNicVMotion":false
DrsEnabled bool `json:"drsEnabled"` //"drsEnabled":true
HaEnabled bool `json:"haEnabled"` //"haEnabled":false

}
type HypervisorManagerList struct {
Total int `json:"total,omitempty"` // "total": 1,
Count int `json:"count,omitempty"` // "count": 1,
Start int `json:"start,omitempty"` // "start": 0,
PrevPageURI utils.Nstring `json:"prevPageUri,omitempty"` // "prevPageUri": null,
NextPageURI utils.Nstring `json:"nextPageUri,omitempty"` // "nextPageUri": null,
URI utils.Nstring `json:"uri,omitempty"` // "uri": "/rest/hypervisor-managers?filter=connectionTemplateUri%20matches%7769cae0-b680-435b-9b87-9b864c81657fsort=name:asc"
Members []HypervisorManager `json:"members,omitempty"` // "members":[]
}

func (c *OVClient) GetHypervisorManagerByName(name string) (HypervisorManager, error) {
var (
hypM HypervisorManager
)
hypMs, err := c.GetHypervisorManagers("", "", fmt.Sprintf("name matches '%s'", name), "name:asc")
if hypMs.Total > 0 {
return hypMs.Members[0], err
} else {
return hypM, err
}
}

func (c *OVClient) GetHypervisorManagers(start string, count string, filter string, sort string) (HypervisorManagerList, error) {
var (
uri = "/rest/hypervisor-managers"
q map[string]interface{}
hypervisorManagers HypervisorManagerList
)
q = make(map[string]interface{})
if len(filter) > 0 {
q["filter"] = filter
}

if sort != "" {
q["sort"] = sort
}

if start != "" {
q["start"] = start
}

if count != "" {
q["count"] = count
}

// refresh login
c.RefreshLogin()
c.SetAuthHeaderOptions(c.GetAuthHeaderMap())
// Setup query
if len(q) > 0 {
c.SetQueryString(q)
}

data, err := c.RestAPICall(rest.GET, uri, nil)
if err != nil {
return hypervisorManagers, err
}

log.Debugf("GetHypervisorManagers %s", data)
if err := json.Unmarshal([]byte(data), &hypervisorManagers); err != nil {
return hypervisorManagers, err
}
return hypervisorManagers, nil
}

func (c *OVClient) CreateHypervisorManager(hypM HypervisorManager) error {
log.Infof("Initializing adding of HypervisorManager %s.", hypM.Name)
var (
uri = "/rest/hypervisor-managers"
t *Task
)
// refresh login
c.RefreshLogin()
c.SetAuthHeaderOptions(c.GetAuthHeaderMap())

t = t.NewProfileTask(c)
t.ResetTask()
log.Infof("REST : %s \n %+v\n", uri, hypM)
log.Debugf("task -> %+v", t)
data, err := c.RestAPICall(rest.POST, uri, hypM)
if err != nil {
t.TaskIsDone = true
log.Errorf("Error submitting new add HypervisorManager request: %s", err)
return err
}

log.Debugf("Response New HypervisorManager %s", data)
if err := json.Unmarshal([]byte(data), &t); err != nil {
t.TaskIsDone = true
log.Errorf("Error with task un-marshal: %s", err)
return err
}

err = t.Wait()
if err != nil {
return err
}

return nil
}

func (c *OVClient) DeleteHypervisorManager(name string) error {
var (
hypM HypervisorManager
err error
t *Task
uri string
)

hypM, err = c.GetHypervisorManagerByName(name)
if err != nil {
return err
}
if hypM.Name != "" {
t = t.NewProfileTask(c)
t.ResetTask()
log.Debugf("REST : %s \n %+v\n", hypM.URI, hypM)
log.Debugf("task -> %+v", t)
uri = hypM.URI.String()
if uri == "" {
log.Warn("Unable to post delete, no uri found.")
t.TaskIsDone = true
return err
}
data, err := c.RestAPICall(rest.DELETE, uri, nil)
if err != nil {
log.Errorf("Error submitting delete hypervisor manager request: %s", err)
t.TaskIsDone = true
return err
}

log.Debugf("Response delete hypervisor manager %s", data)
if err := json.Unmarshal([]byte(data), &t); err != nil {
t.TaskIsDone = true
log.Errorf("Error with task un-marshal: %s", err)
return err
}
err = t.Wait()
if err != nil {
return err
}
return nil
} else {
log.Infof("Hypervisor Manager could not be found to delete, %s, skipping delete ...", name)
}
return nil
}

func (c *OVClient) UpdateHypervisorManager(hypM HypervisorManager) error {
log.Infof("Initializing update of hypervisor manager for %s.", hypM.Name)
var (
uri = hypM.URI.String()
t *Task
)
// refresh login
c.RefreshLogin()
c.SetAuthHeaderOptions(c.GetAuthHeaderMap())

t = t.NewProfileTask(c)
t.ResetTask()
log.Debugf("REST : %s \n %+v\n", uri, hypM)
log.Debugf("task -> %+v", t)
data, err := c.RestAPICall(rest.PUT, uri, hypM)
if err != nil {
t.TaskIsDone = true
log.Errorf("Error submitting update hypervisor manager request: %s", err)
return err
}

log.Debugf("Response update EthernetNetwork %s", data)
if err := json.Unmarshal([]byte(data), &t); err != nil {
t.TaskIsDone = true
log.Errorf("Error with task un-marshal: %s", err)
return err
}

err = t.Wait()
if err != nil {
return err
}

return nil
}