SLikeNet  0.1.3
 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 
43  {
60  };
61 
64  {
91 
93  };
94 
97  {
98  public:
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 
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 
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 
370 
372  {
374  // SLNet::RakString stringInfo;
381  };
382 
384 
385  // RackspaceOperationType currentOperation;
386  // DataStructures::Queue<RackspaceOperation> nextOperationQueue;
387 
389  bool HasOperationOfType(RackspaceOperationType t);
390  unsigned int GetOperationOfTypeIndex(RackspaceOperationType t);
391 
401 
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