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