release/release-0.2.0
parent 1b7ea807d3
commit ab8a014a09

13
Gopkg.lock generated

@ -4,8 +4,11 @@
[[projects]]
branch = "develop"
name = "g.hazardous.org/fkr/libretto"
packages = ["virtualmachine/gridscale"]
revision = "a9dbe19ebdc0853912cf9fd292bd4868d04c329f"
packages = [
"virtualmachine",
"virtualmachine/gridscale"
]
revision = "24ef83ed3f4e0b2932879b7847c20c6a87555559"
[[projects]]
name = "github.com/apcera/libretto"
@ -56,7 +59,7 @@
branch = "master"
name = "github.com/mitchellh/mapstructure"
packages = ["."]
revision = "00c29f56e2386353d58c599509e8dc3801b0d716"
revision = "bb74f1db0675b241733089d5a1faa5dd8b0ef57b"
[[projects]]
name = "github.com/pelletier/go-toml"
@ -108,13 +111,13 @@
"poly1305",
"ssh"
]
revision = "2b6c08872f4b66da917bb4ce98df4f0307330f78"
revision = "94e3fad7f1b4eed4ec147751ad6b4c4d33f00611"
[[projects]]
branch = "master"
name = "golang.org/x/sys"
packages = ["unix"]
revision = "79b0c6888797020a994db17c8510466c72fe75d9"
revision = "d0faeb539838e250bd0a9db4182d48d4a1915181"
[[projects]]
name = "golang.org/x/text"

@ -3,30 +3,40 @@
package gridscale
import (
"github.com/mitchellh/mapstructure"
"time"
"github.com/mitchellh/mapstructure"
)
type Ip struct {
Status string `json:"status"`
LocationIata string `json:"location_iata"`
Failover bool `json:"failover"`
Status string `json:"status" mapstructure:"status"`
LocationIata string `json:"location_iata" mapstructure:"location_iata"`
Failover bool `json:"failover" mapstructure:"failover"`
ObjectUUID string `json:"object_uuid" mapstructure:"object_uuid"`
ChangeTime time.Time `json:"change_time"`
Family int `json:"family"`
LocationUUID string `json:"location_uuid"`
Prefix string `json:"prefix"`
ReverseDNS string `json:"reverse_dns"`
DeleteBlock bool `json:"delete_block"`
UsageInMinutes float64 `json:"usage_in_minutes"`
CreateTime time.Time `json:"create_time"`
Name string `json:"name"`
IP string `json:"ip"`
Labels []interface{} `json:"labels"`
LocationCountry string `json:"location_country"`
LocationName string `json:"location_name"`
Server []*Server `json:"servers"`
LoadBalancer []*LoadBalancer `json:"loadbalancers"`
ChangeTime time.Time `json:"change_time" mapstructure:"change_time"`
Family int `json:"family" mapstructure:"family"`
LocationUUID string `json:"location_uuid" mapstructure:"location_uuid"`
Prefix string `json:"prefix" mapstructure:"prefix"`
ReverseDNS string `json:"reverse_dns" mapstructure:"reverse_dns"`
DeleteBlock bool `json:"delete_block" mapstructure:"delete_block"`
UsageInMinutes float64 `json:"usage_in_minutes" mapstructure:"usage_in_minutes"`
CreateTime time.Time `json:"create_time" mapstructure:"create_time"`
Name string `json:"name" mapstructure:"name"`
IP string `json:"ip" mapstructure:"ip"`
Labels []interface{} `json:"labels" mapstructure:"labels"`
LocationCountry string `json:"location_country" mapstructure:"location_country"`
LocationName string `json:"location_name" mapstructure:"location_name"`
Server []*Server `json:"servers" mapstructure:"servers"`
LoadBalancer []*LoadBalancer `json:"loadbalancers" mapstructure:"loadbalancers"`
}
type IpRelation struct {
Prefix string `json:"prefix" mapstructure:"prefix"`
ServerUUID string `json:"server_uuid" mapstructure:"server_uuid""`
CreateTime time.Time `json:"create_time" mapstructure:"create_time"`
IP string `json:"ip" mapstructure:"ip"`
Family int `json:"family" mapstructure:"family"`
ObjectUUID string `json:"object_uuid" mapstructure:"object_uuid"`
}
type LoadBalancer struct {
@ -56,12 +66,13 @@ func GetIPs(userId string, token string) (map[string]*Ip, error) {
// get our objects
objs, err := GetObjects(userId, token, apiIPBase)
ips := (*objs["ips"]).(map[string]interface{})
if err != nil {
return nil, err
}
ips := (*objs["ips"]).(map[string]interface{})
for key, value := range ips {
var ip1 Ip
err := mapstructure.Decode(value.(map[string]interface{}), &ip1)

@ -3,27 +3,37 @@
package gridscale
import (
"github.com/mitchellh/mapstructure"
"time"
"github.com/mitchellh/mapstructure"
)
type Isoimage struct {
LocationCountry string `json:"location_country"`
Status string `json:"status"`
Labels []interface{} `json:"labels"`
SourceURL string `json:"source_url"`
Capacity int `json:"capacity"`
Description interface{} `json:"description"`
ChangeTime time.Time `json:"change_time"`
Version interface{} `json:"version"`
UsageInMinutes int `json:"usage_in_minutes"`
LocationIata string `json:"location_iata"`
Name string `json:"name"`
LocationCountry string `json:"location_country" mapstructure:"location_country"`
Status string `json:"status" mapstructure:"status"`
Labels []interface{} `json:"labels" mapstructure:"labels"`
SourceURL string `json:"source_url" mapstructure:"source_url"`
Capacity int `json:"capacity" mapstructure:"capacity"`
Description interface{} `json:"description" mapstructure:"description"`
ChangeTime time.Time `json:"change_time" mapstructure:"change_time"`
Version interface{} `json:"version" mapstructure:"version"`
UsageInMinutes int `json:"usage_in_minutes" mapstructure:"usage_in_minutes"`
LocationIata string `json:"location_iata" mapstructure:"location_iata"`
Name string `json:"name" mapstructure:"name"`
ObjectUUID string `json:"object_uuid" mapstructure:"object_uuid"`
Private bool `json:"private"`
CreateTime time.Time `json:"create_time"`
LocationUUID string `json:"location_uuid"`
LocationName string `json:"location_name"`
Private bool `json:"private" mapstructure:"private"`
CreateTime time.Time `json:"create_time" mapstructure:"create_time"`
LocationUUID string `json:"location_uuid" mapstructure:"location_uuid"`
LocationName string `json:"location_name" mapstructure:"location_name"`
}
type IsoimageRelation struct {
CreateTime time.Time `json:"create_time" mapstructure:"create_time"`
Bootdevice bool `json:"bootdevice" mapstructure:"bootdevice"`
ServerUUID string `json:"server_uuid" mapstructure:"server_uuid"`
ObjectName string `json:"object_name" mapstructure:"object_name"`
Private bool `json:"private" mapstructure:"private"`
ObjectUUID string `json:"object_uuid" mapstructure:"object_uuid"`
}
func GetIsoimage(userId string, token string, name string) (*Isoimage, error) {
@ -50,12 +60,13 @@ func GetIsoimages(userId string, token string) (map[string]*Isoimage, error) {
// get our objects
objs, err := GetObjects(userId, token, apiIsoimageBase)
isoimages := (*objs["isoimages"]).(map[string]interface{})
if err != nil {
return nil, err
}
isoimages := (*objs["isoimages"]).(map[string]interface{})
for key, value := range isoimages {
var isoimage1 Isoimage
err := mapstructure.Decode(value.(map[string]interface{}), &isoimage1)

@ -7,12 +7,12 @@ import (
)
type Location struct {
Country string `json:"country"`
Name string `json:"name"`
Country string `json:"country" mapstructure:"country"`
Name string `json:"name" mapstructure:"name"`
ObjectUUID string `json:"object_uuid" mapstructure:"object_uuid"`
Labels []interface{} `json:"labels"`
Iata string `json:"iata"`
Status string `json:"status"`
Labels []interface{} `json:"labels" mapstructure:"labels"`
Iata string `json:"iata" mapstructure:"iata"`
Status string `json:"status" mapstructure:"status"`
}
func GetLocation(userId string, token string, name string) (*Location, error) {
@ -39,12 +39,13 @@ func GetLocations(userId string, token string) (map[string]*Location, error) {
// get our objects
objs, err := GetObjects(userId, token, apiLocationBase)
locations := (*objs["locations"]).(map[string]interface{})
if err != nil {
return nil, err
}
locations := (*objs["locations"]).(map[string]interface{})
for key, value := range locations {
var location1 Location
err := mapstructure.Decode(value.(map[string]interface{}), &location1)

@ -3,27 +3,49 @@
package gridscale
import (
"github.com/mitchellh/mapstructure"
"time"
"github.com/mitchellh/mapstructure"
)
type Network struct {
LocationUUID interface{} `json:"location_uuid"`
Name string `json:"name"`
Status string `json:"status"`
PublicNet bool `json:"public_net"`
LocationCountry interface{} `json:"location_country"`
NetworkType string `json:"network_type"`
L2Security bool `json:"l2security"`
LocationUUID interface{} `json:"location_uuid" mapstructure:"location_uuid"`
Name string `json:"name" mapstructure:"name"`
Status string `json:"status" mapstructure:"status"`
PublicNet bool `json:"public_net" mapstructure:"public_net"`
LocationCountry interface{} `json:"location_country" mapstructure:"location_country"`
NetworkType string `json:"network_type" mapstructure:"network_type"`
L2Security bool `json:"l2security" mapstructure:"l2security"`
// LocationIata interface{} `json:"location_iata"`
ObjectUUID string `json:"object_uuid" mapstructure:"object_uuid"`
DeleteBlock bool `json:"delete_block"`
Vlans []*Vlan `json:"vlans"`
Servers []*Server `json:"servers"`
CreateTime time.Time `json:"create_time"`
ChangeTime time.Time `json:"change_time"`
LocationName interface{} `json:"location_name"`
Labels []interface{} `json:"labels"`
DeleteBlock bool `json:"delete_block" mapstructure:"delete_block"`
Vlans []*Vlan `json:"vlans" mapstructure:"vlans"`
Servers []*Server `json:"servers" mapstructure:"servers"`
CreateTime time.Time `json:"create_time" mapstructure:"create_time"`
ChangeTime time.Time `json:"change_time" mapstructure:"change_time"`
LocationName interface{} `json:"location_name" mapstructure:"location_name"`
Labels []interface{} `json:"labels" mapstructure:"labels"`
}
type NetworkRelation struct {
PartnerUUID string `json:"partner_uuid" mapstructure:"partner_uuid"`
Mac string `json:"mac" mapstructure:"mac"`
Firewall interface{} `json:"firewall" mapstructure:"firewall"`
PublicNet bool `json:"public_net" mapstructure:"public_net"`
ServerUUID string `json:"server_uuid" mapstructure:"server_uuid"`
FirewallTemplateUUID interface{} `json:"firewall_template_uuid" mapstructure:"firewall_template_uuid"`
NetworkType string `json:"network_type" mapstructure:"network_type"`
Vxlan int `json:"vxlan" mapstructure:"vxlan"`
Ordering int `json:"ordering" mapstructure:"ordering"`
L3Security interface{} `json:"l3security" mapstructure:"l3security"`
ObjectName string `json:"object_name" mapstructure:"object_name"`
L2Security bool `json:"l2security" mapstructure:"l2security"`
Vlan interface{} `json:"vlan" mapstructure:"vlan"`
NetworkUUID string `json:"network_uuid" mapstructure:"network_uuid"`
Bootdevice bool `json:"bootdevice" mapstructure:"bootdevice"`
Mcast string `json:"mcast" mapstructure:"mcast"`
CreateTime time.Time `json:"create_time" mapstructure:"create_time"`
ObjectUUID string `json:"object_uuid" mapstructure:"object_uuid"`
}
type Vlan struct {
@ -53,12 +75,13 @@ func GetNetworks(userId string, token string) (map[string]*Network, error) {
// get our objects
objs, err := GetObjects(userId, token, apiNetworkBase)
netwworks := (*objs["networks"]).(map[string]interface{})
if err != nil {
return nil, err
}
netwworks := (*objs["networks"]).(map[string]interface{})
for key, value := range netwworks {
var network1 Network
err := mapstructure.Decode(value.(map[string]interface{}), &network1)

@ -3,26 +3,27 @@
package gridscale
import (
"github.com/mitchellh/mapstructure"
"time"
"github.com/mitchellh/mapstructure"
)
type Snapshot struct {
LocationName string `json:"location_name"`
ParentName string `json:"parent_name"`
Name string `json:"name"`
ChangeTime *time.Time `json:"change_time" mapstructure:"change_time"`
LastUsedTemplate interface{} `json:"last_used_template"`
ParentUUID string `json:"parent_uuid"`
Labels []interface{} `json:"labels"`
UsageInMinutes int `json:"usage_in_minutes"`
LocationCountry string `json:"location_country"`
Status string `json:"status"`
LocationIata string `json:"location_iata"`
CreateTime *time.Time `json:"create_time" mapstructure:"create_time"`
ObjectUUID string `json:"object_uuid"`
LocationUUID string `json:"location_uuid"`
Capacity int `json:"capacity"`
LocationName string `json:"location_name" mapstructure:"location_name"`
ParentName string `json:"parent_name" mapstructure:"parent_name"`
Name string `json:"name" mapstructure:"name"`
ChangeTime *time.Time `json:"change_time" mapstructure:"change_time"`
LastUsedTemplate interface{} `json:"last_used_template" mapstructure:"last_used_template"`
ParentUUID string `json:"parent_uuid" mapstructure:"parent_uuid"`
Labels []interface{} `json:"labels" mapstructure:"labels"`
UsageInMinutes int `json:"usage_in_minutes" mapstructure:"usage_in_minutes"`
LocationCountry string `json:"location_country" mapstructure:"location_country"`
Status string `json:"status" mapstructure:"status"`
LocationIata string `json:"location_iata" mapstructure:"location_iata"`
CreateTime *time.Time `json:"create_time" mapstructure:"create_time"`
ObjectUUID string `json:"object_uuid" mapstructure:"object_uuid"`
LocationUUID string `json:"location_uuid" mapstructure:"location_uuid"`
Capacity int `json:"capacity" mapstructure:"capacity"`
}
func GetSnapshot(userId string, token string, name string) (*Storage, error) {
@ -67,13 +68,14 @@ func (storage Storage) GetSnapshots(userId string, token string) (map[string]*Sn
var retSnapshots = make(map[string]*Snapshot)
// get our objects
objs, err := GetObjects(userId, token, apiStorageBase +"/"+ storage.ObjectUUID +"/snapshots")
snapshots := (*objs["snapshots"]).(map[string]interface{})
objs, err := GetObjects(userId, token, apiStorageBase+"/"+storage.ObjectUUID+"/snapshots")
if err != nil {
return nil, err
}
snapshots := (*objs["snapshots"]).(map[string]interface{})
for key, value := range snapshots {
var snapshot1 Snapshot

@ -3,19 +3,20 @@
package gridscale
import (
"github.com/mitchellh/mapstructure"
"time"
"github.com/mitchellh/mapstructure"
)
type SSHKey struct {
ObjectUUID string `json:"object_uuid" mapstructure:"object_uuid"`
Name string `json:"name"`
Sshkey string `json:"sshkey"`
UserUUID string `json:"user_uuid"`
Labels []interface{} `json:"labels"`
Status string `json:"status"`
CreateTime time.Time `json:"create_time"`
ChangeTime time.Time `json:"change_time"`
Name string `json:"name" mapstructure:"name"`
Sshkey string `json:"sshkey" mapstructure:"sshkey"`
UserUUID string `json:"user_uuid" mapstructure:"user_uuid"`
Labels []interface{} `json:"labels" mapstructure:"labels"`
Status string `json:"status" mapstructure:"status"`
CreateTime time.Time `json:"create_time" mapstructure:"create_time"`
ChangeTime time.Time `json:"change_time" mapstructure:"change_time"`
}
func GetSSHKey(userId string, token string, name string) (*SSHKey, error) {
@ -42,12 +43,13 @@ func GetSSHKeys(userId string, token string) (map[string]*SSHKey, error) {
// get our objects
objs, err := GetObjects(userId, token, apiSSHKeyBase)
sshKeys := (*objs["sshkeys"]).(map[string]interface{})
if err != nil {
return nil, err
}
sshKeys := (*objs["sshkeys"]).(map[string]interface{})
for key, value := range sshKeys {
var sshKey1 SSHKey
err := mapstructure.Decode(value.(map[string]interface{}), &sshKey1)

@ -6,10 +6,11 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/mitchellh/mapstructure"
"io/ioutil"
"net/http"
"time"
"github.com/mitchellh/mapstructure"
)
const (
@ -27,22 +28,38 @@ const (
type Storage struct {
ObjectUUID string `json:"object_uuid,omitempty" mapstructure:"object_uuid"`
Labels []interface{} `json:"labels,omitempty"`
Labels []interface{} `json:"labels,omitempty" mapstructure:"labels"`
CreateTime time.Time `json:"create_time,omitempty" mapstructure:"create_time"`
LocationName string `json:"location_name,omitempty"`
LastUsedTemplate string `json:"last_used_template,omitempty"`
Status string `json:"status,omitempty"`
LocationName string `json:"location_name,omitempty" mapstructure:"location_name"`
LastUsedTemplate string `json:"last_used_template,omitempty" mapstructure:"last_used_template"`
Status string `json:"status,omitempty" mapstructure:"status"`
ChangeTime time.Time `json:"change_time,omitempty" mapstructure:"change_time"`
StorageType string `json:"storage_type,omitempty"`
Snapshots []interface{} `json:"snapshots,omitempty"`
Capacity int `json:"capacity,omitempty"`
ParentUUID string `json:"parent_uuid,omitempty"`
LocationIata string `json:"location_iata,omitempty"`
LocationUUID string `json:"location_uuid,omitempty"`
LicenseProductNo interface{} `json:"license_product_no,omitempty"`
LocationCountry string `json:"location_country,omitempty"`
UsageInMinutes int `json:"usage_in_minutes,omitempty"`
Name string `json:"name,omitempty"`
StorageType string `json:"storage_type,omitempty" mapstructure:"storage_type"`
Snapshots []interface{} `json:"snapshots,omitempty" mapstructure:"snapshots"`
Capacity int `json:"capacity,omitempty" mapstructure:"capacity"`
ParentUUID string `json:"parent_uuid,omitempty" mapstructure:"parent_uuid"`
LocationIata string `json:"location_iata,omitempty" mapstructure:"location_iata"`
LocationUUID string `json:"location_uuid,omitempty" mapstructure:"location_uuid"`
LicenseProductNo interface{} `json:"license_product_no,omitempty" mapstructure:"license_product_no"`
LocationCountry string `json:"location_country,omitempty" mapstructure:"location_country"`
UsageInMinutes int `json:"usage_in_minutes,omitempty" mapstructure:"usage_in_minutes"`
Name string `json:"name,omitempty" mapstructure:"name"`
}
type StorageRelation struct {
LicenseProductNo interface{} `json:"license_product_no" mapstructure:"license_product_no"`
LastUsedTemplate string `json:"last_used_template" mapstructure:"last_used_template"`
ObjectName string `json:"object_name" mapstructure:"object_name"`
StorageType string `json:"storage_type" mapstructure:"storage_type"`
Capacity int `json:"capacity" mapstructure:"capacity"`
ServerUUID string `json:"server_uuid" mapstructure:"server_uuid"`
Lun int `json:"lun" mapstructure:"lun"`
Bootdevice bool `json:"bootdevice" mapstructure:"bootdevice"`
Bus int `json:"bus" mapstructure:"bus"`
Controller int `json:"controller" mapstructure:"controller"`
CreateTime time.Time `json:"create_time" mapstructure:"create_time"`
ObjectUUID string `json:"object_uuid" mapstructure:"object_uuid"`
Target int `json:"target" mapstructure:"target"`
}
type StorageProvisionRequest struct {
@ -109,13 +126,14 @@ func (storage *Storage) Provision(config UserConfig, requestTemplate *StorageTem
}
func GetStorageByUUID(userId string, token string, objectUuid string) (*Storage, error) {
objs, err := GetObjects(userId, token, apiStorageBase+"/" + objectUuid)
storage := (*objs["storage"]).(map[string]interface{})
objs, err := GetObjects(userId, token, apiStorageBase+"/"+objectUuid)
if err != nil {
return nil, err
}
storage := (*objs["storage"]).(map[string]interface{})
var storage1 Storage
config := mapstructure.DecoderConfig{
DecodeHook: StringToDateTimeHook,
@ -160,12 +178,13 @@ func GetStorages(userId string, token string) (map[string]*Storage, error) {
// get our objects
objs, err := GetObjects(userId, token, apiStorageBase)
storages := (*objs["storages"]).(map[string]interface{})
if err != nil {
return nil, err
}
storages := (*objs["storages"]).(map[string]interface{})
for key, value := range storages {
var storage1 Storage

@ -3,29 +3,30 @@
package gridscale
import (
"github.com/mitchellh/mapstructure"
"time"
"github.com/mitchellh/mapstructure"
)
type Template struct {
LicenseProductNo interface{} `json:"license_product_no"`
LocationCountry string `json:"location_country"`
Labels []interface{} `json:"labels"`
Name string `json:"name"`
Version string `json:"version"`
Ostype string `json:"ostype"`
LocationIata string `json:"location_iata"`
Status string `json:"status"`
Description string `json:"description"`
LocationName string `json:"location_name"`
LicenseProductNo interface{} `json:"license_product_no" mapstructure:"license_product_no"`
LocationCountry string `json:"location_country" mapstructure:"location_country"`
Labels []interface{} `json:"labels" mapstructure:"labels"`
Name string `json:"name" mapstructure:"name"`
Version string `json:"version" mapstructure:"version"`
Ostype string `json:"ostype" mapstructure:"ostype"`
LocationIata string `json:"location_iata" mapstructure:"location_iata"`
Status string `json:"status" mapstructure:"status"`
Description string `json:"description" mapstructure:"description"`
LocationName string `json:"location_name" mapstructure:"location_name"`
ObjectUUID string `json:"object_uuid" mapstructure:"object_uuid"`
Distro string `json:"distro"`
Private bool `json:"private"`
ChangeTime time.Time `json:"change_time"`
LocationUUID string `json:"location_uuid"`
Capacity int `json:"capacity"`
UsageInMinutes int `json:"usage_in_minutes"`
CreateTime time.Time `json:"create_time"`
Distro string `json:"distro" mapstructure:"distro"`
Private bool `json:"private" mapstructure:"private"`
ChangeTime time.Time `json:"change_time" mapstructure:"change_time"`
LocationUUID string `json:"location_uuid" mapstructure:"location_uuid"`
Capacity int `json:"capacity" mapstructure:"capacity"`
UsageInMinutes int `json:"usage_in_minutes" mapstructure:"usage_in_minutes"`
CreateTime time.Time `json:"create_time" mapstructure:"create_time"`
}
func GetTemplate(userId string, token string, name string) (*Template, error) {
@ -53,12 +54,13 @@ func GetTemplates(userId string, token string) (map[string]*Template, error) {
// get our objects
objs, err := GetObjects(userId, token, apiTemplatesBase)
templates := (*objs["templates"]).(map[string]interface{})
if err != nil {
return nil, err
}
templates := (*objs["templates"]).(map[string]interface{})
for key, value := range templates {
var template1 Template
err := mapstructure.Decode(value.(map[string]interface{}), &template1)

@ -1,13 +1,30 @@
package gridscale
import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"reflect"
"time"
"io/ioutil"
"fmt"
"encoding/json"
)
// Base API URL strings
const (
// API URLs
apiBaseURL = "https://api.gridscale.io/objects"
apiIPBase = "/ips"
apiIsoimageBase = "/isoimages"
apiLocationBase = "/locations"
apiNetworkBase = "/networks"
apiServerBase = "/servers"
apiSSHKeyBase = "/sshkeys"
apiStorageBase = "/storages"
apiTemplatesBase = "/templates"
// various
StatusOk = '2'
)
// BuildRequest builds an http request for this provider.

@ -12,26 +12,14 @@ import (
"time"
"bytes"
"strconv"
lvm "g.hazardous.org/fkr/libretto/virtualmachine"
libssh "github.com/apcera/libretto/ssh"
"github.com/apcera/libretto/util"
lvm "github.com/apcera/libretto/virtualmachine"
"strconv"
"github.com/mitchellh/mapstructure"
)
// Base API URL strings
const (
apiBaseURL = "https://api.gridscale.io/objects"
apiIPBase = "/ips"
apiIsoimageBase = "/isoimages"
apiLocationBase = "/locations"
apiNetworkBase = "/networks"
apiServerBase = "/servers"
apiSSHKeyBase = "/sshkeys"
apiStorageBase = "/storages"
apiTemplatesBase = "/templates"
)
// Vm struct represents a full gridscale VM in libretto. It contains the server
// itself, along with associated storages, networks and such.
type VM struct {
@ -41,9 +29,15 @@ type VM struct {
Config UserConfig
Server *Server
Location *Location
Relations map[string][]*interface{}
Storages []*Storage
StoragesRelations []*StorageRelation
Networks []*Network
NetworksRelations []*NetworkRelation
IPs []*Ip
IPsRelations []*IpRelation
Isoimages []*Isoimage
IsoimagesRelations []*IsoimageRelation
Credentials libssh.Credentials
BootDevice string
}
@ -90,25 +84,25 @@ type ServerAttachObjectRequest struct {
}
type Server struct {
Legacy bool `json:"legacy,omitempty"`
LocationName string `json:"location_name,omitempty"`
ObjectUUID string `json:"object_uuid,omitempty"`
UsageInMinutesMemory int `json:"usage_in_minutes_memory,omitempty"`
Memory int `json:"memory,omitempty"`
Legacy bool `json:"legacy,omitempty" mapstructure:"legacy"`
LocationName string `json:"location_name,omitempty" mapstructure:"location_name"'`
ObjectUUID string `json:"object_uuid,omitempty" mapstructure:"object_uuid"`
UsageInMinutesMemory int `json:"usage_in_minutes_memory,omitempty" mapstructure:"usage_in_minutes_memory"`
Memory int `json:"memory,omitempty" mapstructure:"memory"`
CreateTime time.Time `json:"create_time,omitempty" mapstructure:"create_time"`
LocationUUID string `json:"location_uuid,omitempty"`
ConsoleToken string `json:"console_token,omitempty"`
Cores int `json:"cores,omitempty"`
AutoRecovery bool `json:"auto_recovery,omitempty"`
LocationIata string `json:"location_iata,omitempty"`
AvailabilityZone interface{} `json:"availability_zone,omitempty"`
Power bool `json:"power,omitempty"`
Labels []interface{} `json:"labels,omitempty"`
UsageInMinutesCores int `json:"usage_in_minutes_cores,omitempty"`
LocationUUID string `json:"location_uuid,omitempty" mapstructure:"location_uuid"`
ConsoleToken string `json:"console_token,omitempty" mapstructure:"console_token""`
Cores int `json:"cores,omitempty" mapstructure:"cores"`
AutoRecovery bool `json:"auto_recovery,omitempty" mapstructure:"auto_recovery"`
LocationIata string `json:"location_iata,omitempty" mapstructure:"location_iata"`
AvailabilityZone interface{} `json:"availability_zone,omitempty" mapstructure:"availability_zone"`
Power bool `json:"power,omitempty" mapstructure:"power"`
Labels []interface{} `json:"labels,omitempty" mapstructure:"labels"`
UsageInMinutesCores int `json:"usage_in_minutes_cores,omitempty" mapstructure:"usage_in_minutes_cores"`
ChangeTime time.Time `json:"change_time,omitempty" mapstructure:"change_time"`
LocationCountry string `json:"location_country,omitempty"`
Name string `json:"name,omitempty"`
Status string `json:"status,omitempty"`
LocationCountry string `json:"location_country,omitempty" mapstructure:"location_country"`
Name string `json:"name,omitempty" mapstructure:"name"`
Status string `json:"status,omitempty" mapstructure:"status"`
}
type Labels struct {
@ -514,7 +508,7 @@ func (vm *VM) Resume() error {
return lvm.ErrResumeNotSupported
}
// GetServers returns and array of servers
// GetServers returns an array of servers
func GetServers(userId string, token string) (*ServersResponse, error) {
client := &http.Client{}
req, err := BuildRequest(userId, token, "GET", apiBaseURL+apiServerBase, nil)
@ -542,9 +536,9 @@ func GetServers(userId string, token string) (*ServersResponse, error) {
return r, nil
}
// GetServers returns and array of servers
// GetServer returns a server
func GetServer(userId string, token string, objectUuid string) (*Server, error) {
objs, err := GetObjects(userId, token, apiServerBase +"/"+objectUuid)
objs, err := GetObjects(userId, token, apiServerBase+"/"+objectUuid)
if err != nil {
return nil, err
@ -572,7 +566,210 @@ func GetServer(userId string, token string, objectUuid string) (*Server, error)
return &server1, nil
}
const (
// StatusOk is the first number of a successful HTTP return code
StatusOk = '2'
)
// GetVM returns a filled VM struct
func GetVM(userId string, token string, objectUuid string) (*VM, error) {
objs, err := GetObjects(userId, token, apiServerBase+"/"+objectUuid)
if err != nil {
return nil, err
}
server := (*objs["server"]).(map[string]interface{})
var server1 Server
decConfigServer := mapstructure.DecoderConfig{
DecodeHook: StringToDateTimeHook,
Result: &server1,
}
serverDecoder, err := mapstructure.NewDecoder(&decConfigServer)
if err != nil {
return nil, err
}
error := serverDecoder.Decode(server)
if error != nil {
return nil, error
}
var vm1 VM
decConfigVM := mapstructure.DecoderConfig{
DecodeHook: StringToDateTimeHook,
Result: &vm1,
}
vmDecoder, err := mapstructure.NewDecoder(&decConfigVM)
if err != nil {
return nil, err
}
// yes, we decode the same structure twice ;)
error = vmDecoder.Decode(server)
if error != nil {
return nil, error
}
vm1.Server = &server1
var location1 *Location
location1, error = GetLocation(userId, token, server1.LocationName)
if error != nil {
return nil, error
}
vm1.Location = location1
vm1.IPsRelations, error = extractIPs(vm1.Relations["public_ips"])
if error != nil {
return nil, error
}
vm1.IsoimagesRelations, error = extractIsoimages(vm1.Relations["isoimages"])
if error != nil {
return nil, error
}
vm1.NetworksRelations, error = extractNetworks(vm1.Relations["networks"])
if error != nil {
return nil, error
}
vm1.StoragesRelations, error = extractStorages(vm1.Relations["storages"])
if error != nil {
return nil, error
}
return &vm1, nil
}
func extractIPs(n []*interface{}) ([]*IpRelation, error) {
vmIPs := make([]*IpRelation,len(n))
c := 0
for _, v := range n {
var ipRelation1 IpRelation
decConfigIP := mapstructure.DecoderConfig{
DecodeHook: StringToDateTimeHook,
Result: &ipRelation1,
}
ipDecoder, err := mapstructure.NewDecoder(&decConfigIP)
if err != nil {
return nil, err
}
err = ipDecoder.Decode((*v).(map[string]interface{}))
if err != nil {
return nil, err
}
vmIPs[c] = &ipRelation1
c++
}
return vmIPs, nil
}
func extractIsoimages(n []*interface{}) ([]*IsoimageRelation, error) {
vmIsoimages := make([]*IsoimageRelation,len(n))
c := 0
for _, v := range n {
var isoimageRelation1 IsoimageRelation
decConfigIsoimage := mapstructure.DecoderConfig{
DecodeHook: StringToDateTimeHook,
Result: &isoimageRelation1,
}
isoimageDecoder, err := mapstructure.NewDecoder(&decConfigIsoimage)
if err != nil {
return nil, err
}
err = isoimageDecoder.Decode((*v).(map[string]interface{}))
if err != nil {
return nil, err
}
vmIsoimages[c] = &isoimageRelation1
c++
}
return vmIsoimages, nil
}
func extractNetworks(n []*interface{}) ([]*NetworkRelation, error) {
vmNetworks := make([]*NetworkRelation,len(n))
c := 0
for _, v := range n {
var networkRelation1 NetworkRelation
decConfigNetwork := mapstructure.DecoderConfig{
DecodeHook: StringToDateTimeHook,
Result: &networkRelation1,
}
networkDecoder, err := mapstructure.NewDecoder(&decConfigNetwork)
if err != nil {
return nil, err
}
err = networkDecoder.Decode((*v).(map[string]interface{}))
if err != nil {
return nil, err
}
vmNetworks[c] = &networkRelation1
c++
}
return vmNetworks, nil
}
func extractStorages(n []*interface{}) ([]*StorageRelation, error) {
vmStorages := make([]*StorageRelation,len(n))
c := 0
for _, v := range n {
var storageRelation1 StorageRelation
decConfigStorage := mapstructure.DecoderConfig{
DecodeHook: StringToDateTimeHook,
Result: &storageRelation1,
}
storageDecoder, err := mapstructure.NewDecoder(&decConfigStorage)
if err != nil {
return nil, err
}
err = storageDecoder.Decode((*v).(map[string]interface{}))
if err != nil {
return nil, err
}
vmStorages[c] = &storageRelation1
c++
}
return vmStorages, nil
}

@ -0,0 +1,106 @@
// Copyright 2015 Apcera Inc. All rights reserved.
package virtualmachine
import (
"errors"
"net"
"strings"
"github.com/apcera/libretto/ssh"
)
// VirtualMachine represents a VM which can be provisioned using this library.
type VirtualMachine interface {
GetName() string
Provision() error
GetIPs() ([]net.IP, error)
Destroy() error
GetState() (string, error)
Suspend() error
Resume() error
Halt() error
Start() error
GetSSH(ssh.Options) (ssh.Client, error)
}
const (
// VMStarting is the state to use when the VM is starting
VMStarting = "starting"
// VMRunning is the state to use when the VM is running
VMRunning = "running"
// VMHalted is the state to use when the VM is halted or shutdown
VMHalted = "halted"
// VMSuspended is the state to use when the VM is suspended
VMSuspended = "suspended"
// VMPending is the state to use when the VM is waiting for action to complete
VMPending = "pending"
// VMError is the state to use when the VM is in error state
VMError = "error"
// VMUnknown is the state to use when the VM is unknown state
VMUnknown = "unknown"
)
var (
// ErrVMNoIP is returned when a newly provisoned VM does not get an IP address.
ErrVMNoIP = errors.New("error getting a new IP for the virtual machine")
// ErrVMBootTimeout is returned when a timeout occurs waiting for a vm to boot.
ErrVMBootTimeout = errors.New("timed out waiting for virtual machine")
// ErrNICAlreadyDisabled is returned when a NIC we are trying to disable is already disabled.
ErrNICAlreadyDisabled = errors.New("NIC already disabled")
// ErrFailedToGetNICS is returned when no NICS can be found on the vm
ErrFailedToGetNICS = errors.New("failed to get interfaces for vm")
// ErrStartingVM is returned when the VM cannot be started
ErrStartingVM = errors.New("error starting VM")
// ErrCreatingVM is returned when the VM cannot be created
ErrCreatingVM = errors.New("error creating VM")
// ErrStoppingVM is returned when the VM cannot be stopped
ErrStoppingVM = errors.New("error stopping VM")
// ErrDeletingVM is returned when the VM cannot be deleted
ErrDeletingVM = errors.New("error deleting VM")
// ErrVMInfoFailed is returned when the VM cannot be deleted
ErrVMInfoFailed = errors.New("error getting information about VM")
// ErrVMStateFailed is returned when no state can be parsed for the VM
ErrVMStateFailed = errors.New("error getting the state of the VM")
// ErrSourceNotSpecified is returned when no source is specified for the VM
ErrSourceNotSpecified = errors.New("source not specified")
// ErrDestNotSpecified is returned when no destination is specified for the VM
ErrDestNotSpecified = errors.New("source not specified")
// ErrSuspendingVM is returned when the VM cannot be suspended
ErrSuspendingVM = errors.New("error suspending the VM")
// ErrResumingVM is returned when the VM cannot be resumed
ErrResumingVM = errors.New("error resuming the VM")
// ErrNotImplemented is returned when the operation is not implemented
ErrNotImplemented = errors.New("operation not implemented")
// ErrSuspendNotSupported is returned when vm.Suspend() is called, but not supported.
ErrSuspendNotSupported = errors.New("suspend action not supported")
// ErrResumeNotSupported is returned when vm.Resume() is called, but not supported.
ErrResumeNotSupported = errors.New("resume action not supported")
)
// WrapErrors squashes multiple errors into a single error, separated by ": ".
func WrapErrors(errs ...error) error {
s := []string{}
for _, e := range errs {
if e != nil {
s = append(s, e.Error())
}
}
return errors.New(strings.Join(s, ": "))
}

@ -644,16 +644,28 @@ func (d *Decoder) decodeMapFromStruct(name string, dataVal reflect.Value, val re
return fmt.Errorf("cannot assign type '%s' to map value field of type '%s'", v.Type(), valMap.Type().Elem())
}
tagValue := f.Tag.Get(d.config.TagName)
tagParts := strings.Split(tagValue, ",")
// Determine the name of the key in the map
keyName := f.Name
tagValue := f.Tag.Get(d.config.TagName)
tagValue = strings.SplitN(tagValue, ",", 2)[0]
if tagValue != "" {
if tagValue == "-" {
if tagParts[0] != "" {
if tagParts[0] == "-" {
continue
}
keyName = tagParts[0]
}
keyName = tagValue
// If "squash" is specified in the tag, we squash the field down.
squash := false
for _, tag := range tagParts[1:] {
if tag == "squash" {
squash = true
break
}
}
if squash && v.Kind() != reflect.Struct {
return fmt.Errorf("cannot squash non-struct type '%s'", v.Type())
}
switch v.Kind() {
@ -673,7 +685,13 @@ func (d *Decoder) decodeMapFromStruct(name string, dataVal reflect.Value, val re
return err
}
valMap.SetMapIndex(reflect.ValueOf(keyName), vMap)
if squash {
for _, k := range vMap.MapKeys() {
valMap.SetMapIndex(k, vMap.MapIndex(k))
}
} else {
valMap.SetMapIndex(reflect.ValueOf(keyName), vMap)
}
default:
valMap.SetMapIndex(reflect.ValueOf(keyName), v)

@ -0,0 +1,283 @@
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build s390x,!gccgo,!appengine
#include "go_asm.h"
#include "textflag.h"
// This is an implementation of the ChaCha20 encryption algorithm as
// specified in RFC 7539. It uses vector instructions to compute
// 4 keystream blocks in parallel (256 bytes) which are then XORed
// with the bytes in the input slice.
GLOBL ·constants<>(SB), RODATA|NOPTR, $32
// BSWAP: swap bytes in each 4-byte element
DATA ·constants<>+0x00(SB)/4, $0x03020100
DATA ·constants<>+0x04(SB)/4, $0x07060504
DATA ·constants<>+0x08(SB)/4, $0x0b0a0908
DATA ·constants<>+0x0c(SB)/4, $0x0f0e0d0c
// J0: [j0, j1, j2, j3]
DATA ·constants<>+0x10(SB)/4, $0x61707865
DATA ·constants<>+0x14(SB)/4, $0x3320646e
DATA ·constants<>+0x18(SB)/4, $0x79622d32
DATA ·constants<>+0x1c(SB)/4, $0x6b206574
// EXRL targets:
TEXT ·mvcSrcToBuf(SB), NOFRAME|NOSPLIT, $0
MVC $1, (R1), (R8)
RET
TEXT ·mvcBufToDst(SB), NOFRAME|NOSPLIT, $0
MVC $1, (R8), (R9)
RET
#define BSWAP V5
#define J0 V6
#define KEY0 V7
#define KEY1 V8
#define NONCE V9
#define CTR V10
#define M0 V11
#define M1 V12
#define M2 V13
#define M3 V14
#define INC V15
#define X0 V16
#define X1 V17
#define X2 V18
#define X3 V19
#define X4 V20
#define X5 V21
#define X6 V22
#define X7 V23
#define X8 V24
#define X9 V25
#define X10 V26
#define X11 V27
#define X12 V28
#define X13 V29
#define X14 V30
#define X15 V31
#define NUM_ROUNDS 20
#define ROUND4(a0, a1, a2, a3, b0, b1, b2, b3, c0, c1, c2, c3, d0, d1, d2, d3) \
VAF a1, a0, a0 \
VAF b1, b0, b0 \
VAF c1, c0, c0 \
VAF d1, d0, d0 \
VX a0, a2, a2 \
VX b0, b2, b2 \
VX c0, c2, c2 \
VX d0, d2, d2 \
VERLLF $16, a2, a2 \
VERLLF $16, b2, b2 \
VERLLF $16, c2, c2 \
VERLLF $16, d2, d2 \
VAF a2, a3, a3 \
VAF b2, b3, b3 \
VAF c2, c3, c3 \
VAF d2, d3, d3 \
VX a3, a1, a1 \
VX b3, b1, b1 \
VX c3, c1, c1 \
VX d3, d1, d1 \
VERLLF $12, a1, a1 \
VERLLF $12, b1, b1 \
VERLLF $12, c1, c1 \
VERLLF $12, d1, d1 \
VAF a1, a0, a0 \
VAF b1, b0, b0 \
VAF c1, c0, c0 \
VAF d1, d0, d0 \
VX a0, a2, a2 \
VX b0, b2, b2 \
VX c0, c2, c2 \
VX d0, d2, d2 \
VERLLF $8, a2, a2 \
VERLLF $8, b2, b2 \
VERLLF $8, c2, c2 \
VERLLF $8, d2, d2 \
VAF a2, a3, a3 \
VAF b2, b3, b3 \
VAF c2, c3, c3 \
VAF d2, d3, d3 \
VX a3, a1, a1 \
VX b3, b1, b1 \
VX c3, c1, c1 \
VX d3, d1, d1 \
VERLLF $7, a1, a1 \
VERLLF $7, b1, b1 \
VERLLF $7, c1, c1 \
VERLLF $7, d1, d1
#define PERMUTE(mask, v0, v1, v2, v3) \
VPERM v0, v0, mask, v0 \
VPERM v1, v1, mask, v1 \
VPERM v2, v2, mask, v2 \
VPERM v3, v3, mask, v3
#define ADDV(x, v0, v1, v2, v3) \
VAF x, v0, v0 \
VAF x, v1, v1 \
VAF x, v2, v2 \
VAF x, v3, v3
#define XORV(off, dst, src, v0, v1, v2, v3) \
VLM off(src), M0, M3 \
PERMUTE(BSWAP, v0, v1, v2, v3) \
VX v0, M0, M0 \
VX v1, M1, M1 \
VX v2, M2, M2 \
VX v3, M3, M3 \
VSTM M0, M3, off(dst)
#define SHUFFLE(a, b, c, d, t, u, v, w) \
VMRHF a, c, t \ // t = {a[0], c[0], a[1], c[1]}
VMRHF b, d, u \ // u = {b[0], d[0], b[1], d[1]}
VMRLF a, c, v \ // v = {a[2], c[2], a[3], c[3]}
VMRLF b, d, w \ // w = {b[2], d[2], b[3], d[3]}
VMRHF t, u, a \ // a = {a[0], b[0], c[0], d[0]}
VMRLF t, u, b \ // b = {a[1], b[1], c[1], d[1]}
VMRHF v, w, c \ // c = {a[2], b[2], c[2], d[2]}
VMRLF v, w, d // d = {a[3], b[3], c[3], d[3]}
// func xorKeyStreamVX(dst, src []byte, key *[8]uint32, nonce *[3]uint32, counter *uint32, buf *[256]byte, len *int)
TEXT ·xorKeyStreamVX(SB), NOSPLIT, $0
MOVD $·constants<>(SB), R1
MOVD dst+0(FP), R2 // R2=&dst[0]
LMG src+24(FP), R3, R4 // R3=&src[0] R4=len(src)
MOVD key+48(FP), R5 // R5=key
MOVD nonce+56(FP), R6 // R6=nonce
MOVD counter+64(FP), R7 // R7=counter
MOVD buf+72(FP), R8 // R8=buf
MOVD len+80(FP), R9 // R9=len
// load BSWAP and J0
VLM (R1), BSWAP, J0
// set up tail buffer
ADD $-1, R4, R12
MOVBZ R12, R12
CMPUBEQ R12, $255, aligned
MOVD R4, R1
AND $~255, R1
MOVD $(R3)(R1*1), R1
EXRL $·mvcSrcToBuf(SB), R12
MOVD $255, R0
SUB R12, R0
MOVD R0, (R9) // update len
aligned:
// setup
MOVD $95, R0
VLM (R5), KEY0, KEY1
VLL R0, (R6), NONCE
VZERO M0
VLEIB $7, $32, M0
VSRLB M0, NONCE, NONCE
// initialize counter values
VLREPF (R7), CTR
VZERO INC
VLEIF $1, $1, INC
VLEIF $2, $2, INC
VLEIF $3, $3, INC
VAF INC, CTR, CTR
VREPIF $4, INC
chacha:
VREPF $0, J0, X0
VREPF $1, J0, X1
VREPF $2, J0, X2
VREPF $3, J0, X3
VREPF $0, KEY0, X4
VREPF $1, KEY0, X5
VREPF $2, KEY0, X6
VREPF $3, KEY0, X7
VREPF $0, KEY1, X8
VREPF $1, KEY1, X9
VREPF $2, KEY1, X10
VREPF $3, KEY1, X11
VLR CTR, X12
VREPF $1, NONCE, X13
VREPF $2, NONCE, X14
VREPF $3, NONCE, X15
MOVD $(NUM_ROUNDS/2), R1
loop:
ROUND4(X0, X4, X12, X8, X1, X5, X13, X9, X2, X6, X14, X10, X3, X7, X15, X11)
ROUND4(X0, X5, X15, X10, X1, X6, X12, X11, X2, X7, X13, X8, X3, X4, X14, X9)
ADD $-1, R1
BNE loop
// decrement length
ADD $-256, R4
BLT tail
continue:
// rearrange vectors
SHUFFLE(X0, X1, X2, X3, M0, M1, M2, M3)
ADDV(J0, X0, X1, X2, X3)
SHUFFLE(X4, X5, X6, X7, M0, M1, M2, M3)
ADDV(KEY0, X4, X5, X6, X7)
SHUFFLE(X8, X9, X10, X11, M0, M1, M2, M3)
ADDV(KEY1, X8, X9, X10, X11)
VAF CTR, X12, X12
SHUFFLE(X12, X13, X14, X15, M0, M1, M2, M3)
ADDV(NONCE, X12, X13, X14, X15)
// increment counters
VAF INC, CTR, CTR
// xor keystream with plaintext
XORV(0*64, R2, R3, X0, X4, X8, X12)
XORV(1*64, R2, R3, X1, X5, X9, X13)
XORV(2*64, R2, R3, X2, X6, X10, X14)
XORV(3*64, R2, R3, X3, X7, X11, X15)