1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
package remoteconsoles
import (
"github.com/gophercloud/gophercloud"
)
// ConsoleProtocol represents valid remote console protocol.
// It can be used to create a remote console with one of the pre-defined protocol.
type ConsoleProtocol string
const (
// ConsoleProtocolVNC represents the VNC console protocol.
ConsoleProtocolVNC ConsoleProtocol = "vnc"
// ConsoleProtocolSPICE represents the SPICE console protocol.
ConsoleProtocolSPICE ConsoleProtocol = "spice"
// ConsoleProtocolRDP represents the RDP console protocol.
ConsoleProtocolRDP ConsoleProtocol = "rdp"
// ConsoleProtocolSerial represents the Serial console protocol.
ConsoleProtocolSerial ConsoleProtocol = "serial"
// ConsoleProtocolMKS represents the MKS console protocol.
ConsoleProtocolMKS ConsoleProtocol = "mks"
)
// ConsoleType represents valid remote console type.
// It can be used to create a remote console with one of the pre-defined type.
type ConsoleType string
const (
// ConsoleTypeNoVNC represents the VNC console type.
ConsoleTypeNoVNC ConsoleType = "novnc"
// ConsoleTypeXVPVNC represents the XVP VNC console type.
ConsoleTypeXVPVNC ConsoleType = "xvpvnc"
// ConsoleTypeRDPHTML5 represents the RDP HTML5 console type.
ConsoleTypeRDPHTML5 ConsoleType = "rdp-html5"
// ConsoleTypeSPICEHTML5 represents the SPICE HTML5 console type.
ConsoleTypeSPICEHTML5 ConsoleType = "spice-html5"
// ConsoleTypeSerial represents the Serial console type.
ConsoleTypeSerial ConsoleType = "serial"
// ConsoleTypeWebMKS represents the Web MKS console type.
ConsoleTypeWebMKS ConsoleType = "webmks"
)
// CreateOptsBuilder allows to add additional parameters to the Create request.
type CreateOptsBuilder interface {
ToRemoteConsoleCreateMap() (map[string]interface{}, error)
}
// CreateOpts specifies parameters to the Create request.
type CreateOpts struct {
// Protocol specifies the protocol of a new remote console.
Protocol ConsoleProtocol `json:"protocol" required:"true"`
// Type specifies the type of a new remote console.
Type ConsoleType `json:"type" required:"true"`
}
// ToRemoteConsoleCreateMap builds a request body from the CreateOpts.
func (opts CreateOpts) ToRemoteConsoleCreateMap() (map[string]interface{}, error) {
return gophercloud.BuildRequestBody(opts, "remote_console")
}
// Create requests the creation of a new remote console on the specified server.
func Create(client *gophercloud.ServiceClient, serverID string, opts CreateOptsBuilder) (r CreateResult) {
reqBody, err := opts.ToRemoteConsoleCreateMap()
if err != nil {
r.Err = err
return
}
resp, err := client.Post(createURL(client, serverID), reqBody, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200},
})
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}
|