SLikeNet 0.1.3

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Rackspace.h
Go to the documentation of this file.
1 /*
2 * Original work: Copyright (c) 2014, Oculus VR, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * RakNet License.txt file in the licenses directory of this source tree. An additional grant
7 * of patent rights can be found in the RakNet Patents.txt file in the same directory.
8 *
9 *
10 * Modified work: Copyright (c) 2017, SLikeSoft UG (haftungsbeschränkt)
11 *
12 * This source code was modified by SLikeSoft. Modifications are licensed under the MIT-style
13 * license found in the license.txt file in the root directory of this source tree.
14 */
15
19
20
21 #include "NativeFeatureIncludes.h"
22
23 #if _RAKNET_SUPPORT_Rackspace==1 && _RAKNET_SUPPORT_TCPInterface==1
24
25 #include "Export.h"
26 #include "DS_List.h"
27 #include "types.h"
28 #include "DS_Queue.h"
29 #include "string.h"
30
31 #ifndef __RACKSPACE_H
32 #define __RACKSPACE_H
33
34 namespace SLNet
35 {
36
37 class TCPInterface;
38 struct Packet;
39
42 enum RackspaceEventType
43 {
44 RET_Success_200,
45 RET_Success_201,
46 RET_Success_202,
47 RET_Success_203,
48 RET_Success_204,
49 RET_Cloud_Servers_Fault_500,
50 RET_Service_Unavailable_503,
51 RET_Unauthorized_401,
52 RET_Bad_Request_400,
53 RET_Over_Limit_413,
54 RET_Bad_Media_Type_415,
55 RET_Item_Not_Found_404,
56 RET_Build_In_Progress_409,
57 RET_Resize_Not_Allowed_403,
58 RET_Connection_Closed_Without_Reponse,
59 RET_Unknown_Failure,
60 };
61
63 enum RackspaceOperationType
64 {
65 RO_CONNECT_AND_AUTHENTICATE,
66 RO_LIST_SERVERS,
67 RO_LIST_SERVERS_WITH_DETAILS,
68 RO_CREATE_SERVER,
69 RO_GET_SERVER_DETAILS,
70 RO_UPDATE_SERVER_NAME_OR_PASSWORD,
71 RO_DELETE_SERVER,
72 RO_LIST_SERVER_ADDRESSES,
73 RO_SHARE_SERVER_ADDRESS,
74 RO_DELETE_SERVER_ADDRESS,
75 RO_REBOOT_SERVER,
76 RO_REBUILD_SERVER,
77 RO_RESIZE_SERVER,
78 RO_CONFIRM_RESIZED_SERVER,
79 RO_REVERT_RESIZED_SERVER,
80 RO_LIST_FLAVORS,
81 RO_GET_FLAVOR_DETAILS,
82 RO_LIST_IMAGES,
83 RO_CREATE_IMAGE,
84 RO_GET_IMAGE_DETAILS,
85 RO_DELETE_IMAGE,
86 RO_LIST_SHARED_IP_GROUPS,
87 RO_LIST_SHARED_IP_GROUPS_WITH_DETAILS,
88 RO_CREATE_SHARED_IP_GROUP,
89 RO_GET_SHARED_IP_GROUP_DETAILS,
90 RO_DELETE_SHARED_IP_GROUP,
91
92 RO_NONE,
93 };
94
96 class RAK_DLL_EXPORT Rackspace2EventCallback
97 {
98 public:
99 Rackspace2EventCallback() {}
100 virtual ~Rackspace2EventCallback() {}
101 virtual void OnAuthenticationResult(RackspaceEventType eventType, const char *htmlAdditionalInfo)=0;
102 virtual void OnListServersResult(RackspaceEventType eventType, const char *htmlAdditionalInfo)=0;
103 virtual void OnListServersWithDetailsResult(RackspaceEventType eventType, const char *htmlAdditionalInfo)=0;
104 virtual void OnCreateServerResult(RackspaceEventType eventType, const char *htmlAdditionalInfo)=0;
105 virtual void OnGetServerDetails(RackspaceEventType eventType, const char *htmlAdditionalInfo)=0;
106 virtual void OnUpdateServerNameOrPassword(RackspaceEventType eventType, const char *htmlAdditionalInfo)=0;
107 virtual void OnDeleteServer(RackspaceEventType eventType, const char *htmlAdditionalInfo)=0;
108 virtual void OnListServerAddresses(RackspaceEventType eventType, const char *htmlAdditionalInfo)=0;
109 virtual void OnShareServerAddress(RackspaceEventType eventType, const char *htmlAdditionalInfo)=0;
110 virtual void OnDeleteServerAddress(RackspaceEventType eventType, const char *htmlAdditionalInfo)=0;
111 virtual void OnRebootServer(RackspaceEventType eventType, const char *htmlAdditionalInfo)=0;
112 virtual void OnRebuildServer(RackspaceEventType eventType, const char *htmlAdditionalInfo)=0;
113 virtual void OnResizeServer(RackspaceEventType eventType, const char *htmlAdditionalInfo)=0;
114 virtual void OnConfirmResizedServer(RackspaceEventType eventType, const char *htmlAdditionalInfo)=0;
115 virtual void OnRevertResizedServer(RackspaceEventType eventType, const char *htmlAdditionalInfo)=0;
116 virtual void OnListFlavorsResult(RackspaceEventType eventType, const char *htmlAdditionalInfo)=0;
117 virtual void OnGetFlavorDetailsResult(RackspaceEventType eventType, const char *htmlAdditionalInfo)=0;
118 virtual void OnListImagesResult(RackspaceEventType eventType, const char *htmlAdditionalInfo)=0;
119 virtual void OnCreateImageResult(RackspaceEventType eventType, const char *htmlAdditionalInfo)=0;
120 virtual void OnGetImageDetailsResult(RackspaceEventType eventType, const char *htmlAdditionalInfo)=0;
121 virtual void OnDeleteImageResult(RackspaceEventType eventType, const char *htmlAdditionalInfo)=0;
122 virtual void OnListSharedIPGroups(RackspaceEventType eventType, const char *htmlAdditionalInfo)=0;
123 virtual void OnListSharedIPGroupsWithDetails(RackspaceEventType eventType, const char *htmlAdditionalInfo)=0;
124 virtual void OnCreateSharedIPGroup(RackspaceEventType eventType, const char *htmlAdditionalInfo)=0;
125 virtual void OnGetSharedIPGroupDetails(RackspaceEventType eventType, const char *htmlAdditionalInfo)=0;
126 virtual void OnDeleteSharedIPGroup(RackspaceEventType eventType, const char *htmlAdditionalInfo)=0;
127
128 virtual void OnConnectionAttemptFailure(RackspaceOperationType operationType, const char *url)=0;
129 };
130
132 class RAK_DLL_EXPORT RackspaceEventCallback_Default : public Rackspace2EventCallback
133 {
134 public:
135 virtual void ExecuteDefault(const char *callbackName, RackspaceEventType eventType, const char *htmlAdditionalInfo) {(void) callbackName; (void) eventType; (void) htmlAdditionalInfo;}
136
137 virtual void OnAuthenticationResult(RackspaceEventType eventType, const char *htmlAdditionalInfo) {ExecuteDefault("OnAuthenticationResult", eventType, htmlAdditionalInfo);}
138 virtual void OnListServersResult(RackspaceEventType eventType, const char *htmlAdditionalInfo) {ExecuteDefault("OnListServersResult", eventType, htmlAdditionalInfo);}
139 virtual void OnListServersWithDetailsResult(RackspaceEventType eventType, const char *htmlAdditionalInfo) {ExecuteDefault("OnListServersWithDetailsResult", eventType, htmlAdditionalInfo);}
140 virtual void OnCreateServerResult(RackspaceEventType eventType, const char *htmlAdditionalInfo) {ExecuteDefault("OnCreateServerResult", eventType, htmlAdditionalInfo);}
141 virtual void OnGetServerDetails(RackspaceEventType eventType, const char *htmlAdditionalInfo) {ExecuteDefault("OnGetServerDetails", eventType, htmlAdditionalInfo);}
142 virtual void OnUpdateServerNameOrPassword(RackspaceEventType eventType, const char *htmlAdditionalInfo) {ExecuteDefault("OnUpdateServerNameOrPassword", eventType, htmlAdditionalInfo);}
143 virtual void OnDeleteServer(RackspaceEventType eventType, const char *htmlAdditionalInfo) {ExecuteDefault("OnDeleteServer", eventType, htmlAdditionalInfo);}
144 virtual void OnListServerAddresses(RackspaceEventType eventType, const char *htmlAdditionalInfo) {ExecuteDefault("OnListServerAddresses", eventType, htmlAdditionalInfo);}
145 virtual void OnShareServerAddress(RackspaceEventType eventType, const char *htmlAdditionalInfo) {ExecuteDefault("OnShareServerAddress", eventType, htmlAdditionalInfo);}
146 virtual void OnDeleteServerAddress(RackspaceEventType eventType, const char *htmlAdditionalInfo) {ExecuteDefault("OnDeleteServerAddress", eventType, htmlAdditionalInfo);}
147 virtual void OnRebootServer(RackspaceEventType eventType, const char *htmlAdditionalInfo) {ExecuteDefault("OnRebootServer", eventType, htmlAdditionalInfo);}
148 virtual void OnRebuildServer(RackspaceEventType eventType, const char *htmlAdditionalInfo) {ExecuteDefault("OnRebuildServer", eventType, htmlAdditionalInfo);}
149 virtual void OnResizeServer(RackspaceEventType eventType, const char *htmlAdditionalInfo) {ExecuteDefault("OnResizeServer", eventType, htmlAdditionalInfo);}
150 virtual void OnConfirmResizedServer(RackspaceEventType eventType, const char *htmlAdditionalInfo) {ExecuteDefault("OnConfirmResizedServer", eventType, htmlAdditionalInfo);}
151 virtual void OnRevertResizedServer(RackspaceEventType eventType, const char *htmlAdditionalInfo) {ExecuteDefault("OnRevertResizedServer", eventType, htmlAdditionalInfo);}
152 virtual void OnListFlavorsResult(RackspaceEventType eventType, const char *htmlAdditionalInfo) {ExecuteDefault("OnListFlavorsResult", eventType, htmlAdditionalInfo);}
153 virtual void OnGetFlavorDetailsResult(RackspaceEventType eventType, const char *htmlAdditionalInfo) {ExecuteDefault("OnGetFlavorDetailsResult", eventType, htmlAdditionalInfo);}
154 virtual void OnListImagesResult(RackspaceEventType eventType, const char *htmlAdditionalInfo) {ExecuteDefault("OnListImagesResult", eventType, htmlAdditionalInfo);}
155 virtual void OnCreateImageResult(RackspaceEventType eventType, const char *htmlAdditionalInfo) {ExecuteDefault("OnCreateImageResult", eventType, htmlAdditionalInfo);}
156 virtual void OnGetImageDetailsResult(RackspaceEventType eventType, const char *htmlAdditionalInfo) {ExecuteDefault("OnGetImageDetailsResult", eventType, htmlAdditionalInfo);}
157 virtual void OnDeleteImageResult(RackspaceEventType eventType, const char *htmlAdditionalInfo) {ExecuteDefault("OnDeleteImageResult", eventType, htmlAdditionalInfo);}
158 virtual void OnListSharedIPGroups(RackspaceEventType eventType, const char *htmlAdditionalInfo) {ExecuteDefault("OnListSharedIPGroups", eventType, htmlAdditionalInfo);}
159 virtual void OnListSharedIPGroupsWithDetails(RackspaceEventType eventType, const char *htmlAdditionalInfo) {ExecuteDefault("OnListSharedIPGroupsWithDetails", eventType, htmlAdditionalInfo);}
160 virtual void OnCreateSharedIPGroup(RackspaceEventType eventType, const char *htmlAdditionalInfo) {ExecuteDefault("OnCreateSharedIPGroup", eventType, htmlAdditionalInfo);}
161 virtual void OnGetSharedIPGroupDetails(RackspaceEventType eventType, const char *htmlAdditionalInfo) {ExecuteDefault("OnGetSharedIPGroupDetails", eventType, htmlAdditionalInfo);}
162 virtual void OnDeleteSharedIPGroup(RackspaceEventType eventType, const char *htmlAdditionalInfo) {ExecuteDefault("OnDeleteSharedIPGroup", eventType, htmlAdditionalInfo);}
163
164 virtual void OnConnectionAttemptFailure(RackspaceOperationType operationType, const char *url) {(void) operationType; (void) url;}
165 };
166
171 class RAK_DLL_EXPORT Rackspace
172 {
173 public:
174 Rackspace();
175 ~Rackspace();
176
186 SystemAddress Authenticate(TCPInterface *_tcpInterface, const char *_authenticationURL, const char *_rackspaceCloudUsername, const char *_apiAccessKey);
187
191 void ListServers(void);
192
197 void ListServersWithDetails(void);
198
211 void CreateServer(SLNet::RakString name, SLNet::RakString imageId, SLNet::RakString flavorId);
212
217 void GetServerDetails(SLNet::RakString serverId);
218
225 void UpdateServerNameOrPassword(SLNet::RakString serverId, SLNet::RakString newName, SLNet::RakString newPassword);
226
231 void DeleteServer(SLNet::RakString serverId);
232
237 void ListServerAddresses(SLNet::RakString serverId);
238
244 void ShareServerAddress(SLNet::RakString serverId, SLNet::RakString ipAddress);
245
251 void DeleteServerAddress(SLNet::RakString serverId, SLNet::RakString ipAddress);
252
258 void RebootServer(SLNet::RakString serverId, SLNet::RakString rebootType);
259
265 void RebuildServer(SLNet::RakString serverId, SLNet::RakString imageId);
266
273 void ResizeServer(SLNet::RakString serverId, SLNet::RakString flavorId);
274
280 void ConfirmResizedServer(SLNet::RakString serverId);
281
287 void RevertResizedServer(SLNet::RakString serverId);
288
292 void ListFlavors(void);
293
299 void GetFlavorDetails(SLNet::RakString flavorId);
300
305 void ListImages(void);
306
313 void CreateImage(SLNet::RakString serverId, SLNet::RakString imageName);
314
320 void GetImageDetails(SLNet::RakString imageId);
321
327 void DeleteImage(SLNet::RakString imageId);
328
332 void ListSharedIPGroups(void);
333
337 void ListSharedIPGroupsWithDetails(void);
338
339 // I don't know what this does
340 void CreateSharedIPGroup(SLNet::RakString name, SLNet::RakString optionalServerId);
341 // I don't know what this does
342 void GetSharedIPGroupDetails(SLNet::RakString groupId);
343 // I don't know what this does
344 void DeleteSharedIPGroup(SLNet::RakString groupId);
345
348 void AddEventCallback(Rackspace2EventCallback *callback);
351 void RemoveEventCallback(Rackspace2EventCallback *callback);
353 void ClearEventCallbacks(void);
354
356 void OnReceive(Packet *packet);
357
359 void OnClosedConnection(SystemAddress systemAddress);
360
362 static const char * EventTypeToString(RackspaceEventType eventType);
363
366 void AddOperation(RackspaceOperationType type, SLNet::RakString httpCommand, SLNet::RakString operation, SLNet::RakString xml);
367 protected:
368
369 DataStructures::List<Rackspace2EventCallback*> eventCallbacks;
370
371 struct RackspaceOperation
372 {
373 RackspaceOperationType type;
374 // SLNet::RakString stringInfo;
375 SystemAddress connectionAddress;
376 bool isPendingAuthentication;
377 SLNet::RakString incomingStream;
378 SLNet::RakString httpCommand;
379 SLNet::RakString operation;
380 SLNet::RakString xml;
381 };
382
383 TCPInterface *tcpInterface;
384
385 // RackspaceOperationType currentOperation;
386 // DataStructures::Queue<RackspaceOperation> nextOperationQueue;
387
388 DataStructures::List<RackspaceOperation> operations;
389 bool HasOperationOfType(RackspaceOperationType t);
390 unsigned int GetOperationOfTypeIndex(RackspaceOperationType t);
391
392 SLNet::RakString serverManagementURL;
393 SLNet::RakString serverManagementDomain;
394 SLNet::RakString serverManagementPath;
395 SLNet::RakString storageURL;
396 SLNet::RakString storageDomain;
397 SLNet::RakString storagePath;
398 SLNet::RakString cdnManagementURL;
399 SLNet::RakString cdnManagementDomain;
400 SLNet::RakString cdnManagementPath;
401
402 SLNet::RakString storageToken;
403 SLNet::RakString authToken;
404 SLNet::RakString rackspaceCloudUsername;
405 SLNet::RakString apiAccessKey;
406
407 bool ExecuteOperation(RackspaceOperation &ro);
408 void ReadLine(const char *data, const char *stringStart, SLNet::RakString &output);
409 bool ConnectToServerManagementDomain(RackspaceOperation &ro);
410
411
412 };
413
414 } // namespace SLNet
415
416 #endif // __RACKSPACE_API_H
417
418 #endif // _RAKNET_SUPPORT_Rackspace