-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
242 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package disk | ||
|
||
import "github.com/czerwonk/ovirt_exporter/storagedomain" | ||
|
||
// Disk represents the disk resource | ||
type Disk struct { | ||
ID string `xml:"id,attr"` | ||
Name string `xml:"name,omitempty"` | ||
Alias string `xml:"alias,omitempty"` | ||
ProvisionedSize uint64 `xml:"provisioned_size,omitempty"` | ||
ActualSize uint64 `xml:"actual_size,omitempty"` | ||
TotalSize uint64 `xml:"total_size,omitempty"` | ||
StorageDomains *storagedomain.StorageDomains `xml:"storage_domains,omitempty"` | ||
} | ||
|
||
// StorageDomainName returns the name of the storage domain of the disk | ||
func (d *Disk) StorageDomainName() string { | ||
if len(d.StorageDomains.Domains) == 0 { | ||
return "" | ||
} | ||
|
||
return d.StorageDomains.Domains[0].Name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package disk | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/czerwonk/ovirt_api/api" | ||
"github.com/czerwonk/ovirt_exporter/storagedomain" | ||
) | ||
|
||
// Get retrieves disk information | ||
func Get(id string, client *api.Client) (*Disk, error) { | ||
path := fmt.Sprintf("disks/%s", id) | ||
|
||
d := &Disk{} | ||
err := client.GetAndParse(path, &d) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for i, dom := range d.StorageDomains.Domains { | ||
d.StorageDomains.Domains[i] = storagedomain.StorageDomain{ | ||
ID: dom.ID, | ||
Name: storagedomain.Name(dom.ID, client), | ||
} | ||
} | ||
|
||
return d, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package storagedomain | ||
|
||
import ( | ||
"sync" | ||
|
||
"fmt" | ||
|
||
"github.com/czerwonk/ovirt_api/api" | ||
"github.com/prometheus/common/log" | ||
) | ||
|
||
var ( | ||
cacheMutex = sync.Mutex{} | ||
nameCache = make(map[string]string) | ||
) | ||
|
||
// Get retrieves domain information | ||
func Get(id string, client *api.Client) (*StorageDomain, error) { | ||
path := fmt.Sprintf("storagedomains/%s", id) | ||
|
||
d := StorageDomain{} | ||
err := client.GetAndParse(path, &d) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &d, nil | ||
} | ||
|
||
// Name retrieves domain name | ||
func Name(id string, client *api.Client) string { | ||
cacheMutex.Lock() | ||
defer cacheMutex.Unlock() | ||
|
||
if n, found := nameCache[id]; found { | ||
return n | ||
} | ||
|
||
d, err := Get(id, client) | ||
if err != nil { | ||
log.Error(err) | ||
return "" | ||
} | ||
|
||
if (d == nil) { | ||
log.Errorf("could not find name for storage domain with ID %s", id) | ||
return "" | ||
} | ||
|
||
nameCache[id] = d.Name | ||
return d.Name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,27 @@ | ||
package storagedomain | ||
|
||
// StorageDomains is a collection of storage domains | ||
type StorageDomains struct { | ||
Domains []StorageDomain `xml:"storage_domain"` | ||
} | ||
|
||
// StorageDomain represents the storage domain resource | ||
type StorageDomain struct { | ||
ID string `xml:"id,attr"` | ||
Name string `xml:"name"` | ||
Name string `xml:"name,omitempty"` | ||
Storage struct { | ||
Path string `xml:"path"` | ||
Type string `xml:"type"` | ||
Path string `xml:"path,omitempty"` | ||
Type string `xml:"type,omitempty"` | ||
} `xml:"storage,omitempty"` | ||
Type string `xml:"type"` | ||
Available float64 ` xml:"available"` | ||
Committed float64 `xml:"committed"` | ||
Used float64 `xml:"used"` | ||
ExternalStatus string `xml:"external_status"` | ||
Master bool `xml:"master"` | ||
Type string `xml:"type,omitempty"` | ||
Available float64 ` xml:"available,omitempty"` | ||
Committed float64 `xml:"committed,omitempty"` | ||
Used float64 `xml:"used,omitempty"` | ||
ExternalStatus string `xml:"external_status,omitempty"` | ||
Master bool `xml:"master,omitempty"` | ||
DataCenters struct { | ||
DataCenter struct { | ||
ID string `xml:"id,attr"` | ||
} `xml:"data_center"` | ||
} `xml:"data_centers"` | ||
} `xml:"data_centers,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package vm | ||
|
||
import "github.com/czerwonk/ovirt_exporter/disk" | ||
|
||
// DiskAttachments is a collection of diskattachments | ||
type DiskAttachments struct { | ||
Attachment []DiskAttachment `xml:"disk_attachment"` | ||
} | ||
|
||
// DiskAttachment represents the diskattachment resource | ||
type DiskAttachment struct { | ||
LogicalName string `xml:"logical_name"` | ||
Disk disk.Disk `xml:"disk"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.