Revision 1c4d369c

View differences:

include/VirtualMachine.h
23 23
#include "Image.h"
24 24
#include "Log.h"
25 25
#include "NebulaLog.h"
26
#include "NebulaUtil.h"
26 27

  
27 28
#include <time.h>
28 29
#include <set>
......
62 63
        UNDEPLOYED = 9
63 64
    };
64 65

  
66
    static int vm_state_from_str(string& st, VmState& state)
67
    {
68
        one_util::toupper(st);
69

  
70
        if ( st == "INIT" ) { state = INIT; }
71
        else if ( st == "PENDING" ) { state = PENDING; }
72
        else if ( st == "HOLD" ) { state = HOLD; }
73
        else if ( st == "ACTIVE" ) { state = ACTIVE; }
74
        else if ( st == "STOPPED" ) { state = STOPPED; }
75
        else if ( st == "SUSPENDED" ) { state = SUSPENDED; }
76
        else if ( st == "DONE" ) { state = DONE; }
77
        else if ( st == "FAILED" ) { state = FAILED; }
78
        else if ( st == "POWEROFF" ) { state = POWEROFF; }
79
        else if ( st == "UNDEPLOYED" ) { state = UNDEPLOYED; }
80
        else {return -1;}
81

  
82
        return 0;
83
    }
84

  
85
    static string& vm_state_to_str(string& st, VmState state)
86
    {
87
        switch (state)
88
        {
89
            case INIT      : st = "INIT"; break;
90
            case PENDING   : st = "PENDING"; break;
91
            case HOLD      : st = "HOLD"; break;
92
            case ACTIVE    : st = "ACTIVE"; break;
93
            case STOPPED   : st = "STOPPED"; break;
94
            case SUSPENDED : st = "SUSPENDED"; break;
95
            case DONE      : st = "DONE"; break;
96
            case FAILED    : st = "FAILED"; break;
97
            case POWEROFF  : st = "POWEROFF"; break;
98
            case UNDEPLOYED: st = "UNDEPLOYED"; break;
99
        }
100

  
101
        return st;
102
    }
103

  
65 104
    /**
66 105
     *  Virtual Machine state associated to the Life-cycle Manager
67 106
     */
......
102 141
        BOOT_UNDEPLOY       = 32
103 142
    };
104 143

  
144
    static int lcm_state_from_str(string& st, LcmState& state)
145
    {
146
        one_util::toupper(st);
147

  
148
        if ( st == "LCM_INIT" ){ state = LCM_INIT; }
149
        else if ( st == "PROLOG") { state = PROLOG; }
150
        else if ( st == "BOOT") { state = BOOT; }
151
        else if ( st == "RUNNING") { state = RUNNING; }
152
        else if ( st == "MIGRATE") { state = MIGRATE; }
153
        else if ( st == "SAVE_STOP") { state = SAVE_STOP; }
154
        else if ( st == "SAVE_SUSPEND") { state = SAVE_SUSPEND; }
155
        else if ( st == "SAVE_MIGRATE") { state = SAVE_MIGRATE; }
156
        else if ( st == "PROLOG_MIGRATE") { state = PROLOG_MIGRATE; }
157
        else if ( st == "PROLOG_RESUME") { state = PROLOG_RESUME; }
158
        else if ( st == "EPILOG_STOP") { state = EPILOG_STOP; }
159
        else if ( st == "EPILOG") { state = EPILOG; }
160
        else if ( st == "SHUTDOWN") { state = SHUTDOWN; }
161
        else if ( st == "CANCEL") { state = CANCEL; }
162
        else if ( st == "FAILURE") { state = FAILURE; }
163
        else if ( st == "CLEANUP_RESUBMIT") { state = CLEANUP_RESUBMIT; }
164
        else if ( st == "UNKNOWN") { state = UNKNOWN; }
165
        else if ( st == "HOTPLUG") { state = HOTPLUG; }
166
        else if ( st == "SHUTDOWN_POWEROFF") { state = SHUTDOWN_POWEROFF; }
167
        else if ( st == "BOOT_UNKNOWN") { state = BOOT_UNKNOWN; }
168
        else if ( st == "BOOT_POWEROFF") { state = BOOT_POWEROFF; }
169
        else if ( st == "BOOT_SUSPENDED") { state = BOOT_SUSPENDED; }
170
        else if ( st == "BOOT_STOPPED") { state = BOOT_STOPPED; }
171
        else if ( st == "CLEANUP_DELETE") { state = CLEANUP_DELETE; }
172
        else if ( st == "HOTPLUG_SNAPSHOT") { state = HOTPLUG_SNAPSHOT; }
173
        else if ( st == "HOTPLUG_NIC") { state = HOTPLUG_NIC; }
174
        else if ( st == "HOTPLUG_SAVEAS") { state = HOTPLUG_SAVEAS; }
175
        else if ( st == "HOTPLUG_SAVEAS_POWEROFF") { state = HOTPLUG_SAVEAS_POWEROFF; }
176
        else if ( st == "HOTPLUG_SAVEAS_SUSPENDED") { state = HOTPLUG_SAVEAS_SUSPENDED; }
177
        else if ( st == "SHUTDOWN_UNDEPLOY") { state = SHUTDOWN_UNDEPLOY; }
178
        else if ( st == "EPILOG_UNDEPLOY") { state = EPILOG_UNDEPLOY; }
179
        else if ( st == "PROLOG_UNDEPLOY") { state = PROLOG_UNDEPLOY; }
180
        else if ( st == "BOOT_UNDEPLOY") { state = BOOT_UNDEPLOY; }
181
        else {return -1;}
182

  
183
        return 0;
184
    }
185

  
186
    static string& lcm_state_to_str(string& st, LcmState& state)
187
    {
188
        switch (state)
189
        {
190
            case LCM_INIT: st = "LCM_INIT"; break;
191
            case PROLOG: st = "PROLOG"; break;
192
            case BOOT: st = "BOOT"; break;
193
            case RUNNING: st = "RUNNING"; break;
194
            case MIGRATE: st = "MIGRATE"; break;
195
            case SAVE_STOP: st = "SAVE_STOP"; break;
196
            case SAVE_SUSPEND: st = "SAVE_SUSPEND"; break;
197
            case SAVE_MIGRATE: st = "SAVE_MIGRATE"; break;
198
            case PROLOG_MIGRATE: st = "PROLOG_MIGRATE"; break;
199
            case PROLOG_RESUME: st = "PROLOG_RESUME"; break;
200
            case EPILOG_STOP: st = "EPILOG_STOP"; break;
201
            case EPILOG: st = "EPILOG"; break;
202
            case SHUTDOWN: st = "SHUTDOWN"; break;
203
            case CANCEL: st = "CANCEL"; break;
204
            case FAILURE: st = "FAILURE"; break;
205
            case CLEANUP_RESUBMIT: st = "CLEANUP_RESUBMIT"; break;
206
            case UNKNOWN: st = "UNKNOWN"; break;
207
            case HOTPLUG: st = "HOTPLUG"; break;
208
            case SHUTDOWN_POWEROFF: st = "SHUTDOWN_POWEROFF"; break;
209
            case BOOT_UNKNOWN: st = "BOOT_UNKNOWN"; break;
210
            case BOOT_POWEROFF: st = "BOOT_POWEROFF"; break;
211
            case BOOT_SUSPENDED: st = "BOOT_SUSPENDED"; break;
212
            case BOOT_STOPPED: st = "BOOT_STOPPED"; break;
213
            case CLEANUP_DELETE: st = "CLEANUP_DELETE"; break;
214
            case HOTPLUG_SNAPSHOT: st = "HOTPLUG_SNAPSHOT"; break;
215
            case HOTPLUG_NIC: st = "HOTPLUG_NIC"; break;
216
            case HOTPLUG_SAVEAS: st = "HOTPLUG_SAVEAS"; break;
217
            case HOTPLUG_SAVEAS_POWEROFF: st = "HOTPLUG_SAVEAS_POWEROFF"; break;
218
            case HOTPLUG_SAVEAS_SUSPENDED: st = "HOTPLUG_SAVEAS_SUSPENDED"; break;
219
            case SHUTDOWN_UNDEPLOY: st = "SHUTDOWN_UNDEPLOY"; break;
220
            case EPILOG_UNDEPLOY: st = "EPILOG_UNDEPLOY"; break;
221
            case PROLOG_UNDEPLOY: st = "PROLOG_UNDEPLOY"; break;
222
            case BOOT_UNDEPLOY: st = "BOOT_UNDEPLOY"; break;
223
        }
224

  
225
        return st;
226
    }
227

  
105 228
    // -------------------------------------------------------------------------
106 229
    // Log & Print
107 230
    // -------------------------------------------------------------------------
src/vm/VirtualMachinePool.cc
180 180

  
181 181
            state_hook = true;
182 182
        }
183
        else if ( on == "CUSTOM" )
184
        {
185
            VirtualMachineStateHook * hook;
186

  
187
            string lcm_str = vattr->vector_value("LCM_STATE");
188
            string vm_str  = vattr->vector_value("STATE");
189

  
190
            VirtualMachine::LcmState lcm_state;
191
            VirtualMachine::VmState vm_state;
192

  
193
            if ( VirtualMachine::lcm_state_from_str(lcm_str, lcm_state) != 0 )
194
            {
195
                ostringstream oss;
196
                oss << "Wrong LCM_STATE: "<< lcm_str <<". Hook not registered!";
197

  
198
                NebulaLog::log("VM",Log::WARNING,oss);
199
                continue;
200
            }
201

  
202
            if ( VirtualMachine::vm_state_from_str(vm_str, vm_state) != 0 )
203
            {
204
                ostringstream oss;
205
                oss << "Wrong STATE: "<< vm_str <<". Hook not registered!";
206

  
207
                NebulaLog::log("VM",Log::WARNING,oss);
208
                continue;
209
            }
210

  
211
            hook = new VirtualMachineStateHook(name, cmd, arg, remote,
212
                    lcm_state, vm_state);
213

  
214
            add_hook(hook);
215

  
216
            state_hook = true;
217
        }
183 218
        else
184 219
        {
185 220
            ostringstream oss;

Also available in: Unified diff