Revision c9d0df87

View differences:

src/host/HostHook.cc
20 20

  
21 21
// -----------------------------------------------------------------------------
22 22
// -----------------------------------------------------------------------------
23
static void parse_host_arguments(Host *host, string& parsed)
24
{
25
    size_t  found;
26

  
27
    found = parsed.find("$HID");
28

  
29
    if ( found !=string::npos )
30
    {
31
        ostringstream oss;
32
        oss << host->get_oid();
33

  
34
        parsed.replace(found,4,oss.str());
35
    }
36

  
37
    found = parsed.find("$TEMPLATE");
38

  
39
    if ( found != string::npos )
40
    {
41
        string templ;
42
        parsed.replace(found,9,host->to_xml64(templ));
43
    }
44
}
45
// -----------------------------------------------------------------------------
46
// -----------------------------------------------------------------------------
23 47

  
24 48
void HostAllocateHook::do_hook(void *arg)
25 49
{
26 50
    Host *  host;
27 51

  
28 52
    string  parsed_args = args;
29
    size_t  found;
30 53

  
31 54
    host = static_cast<Host *>(arg);
32 55

  
......
34 57
    {
35 58
        return;
36 59
    }
37

  
38
    found = args.find("$HID");
39

  
40
    if ( found !=string::npos )
41
    {
42
        ostringstream oss;
43
        oss << host->get_oid();
44

  
45
        parsed_args.replace(found,4,oss.str());
46
    }
60
    
61
    parse_host_arguments(host,parsed_args);
47 62

  
48 63
    Nebula& ne                    = Nebula::instance();
49 64
    HookManager * hm              = ne.get_hm();
......
156 171
    if ( cur_state == this->state )
157 172
    {
158 173
        string  parsed_args = args;
159
        size_t  found;
160

  
161
        found = args.find("$HID");
162 174

  
163
        if ( found !=string::npos )
164
        {
165
            ostringstream oss;
166
            oss << host->get_oid();
167

  
168
            parsed_args.replace(found,4,oss.str());
169
        }
175
        parse_host_arguments(host,parsed_args);
170 176

  
171 177
        Nebula& ne        = Nebula::instance();
172 178
        HookManager * hm  = ne.get_hm();
src/vm/VirtualMachineHook.cc
21 21
// -----------------------------------------------------------------------------
22 22
// -----------------------------------------------------------------------------
23 23

  
24
static void parse_vm_arguments(VirtualMachine *vm, string& parsed)
25
{
26
    size_t  found;
27

  
28
    found = parsed.find("$VMID");
29

  
30
    if ( found !=string::npos )
31
    {
32
        ostringstream oss;
33
        oss << vm->get_oid();
34

  
35
        parsed.replace(found,5,oss.str());
36
    }
37

  
38
    found = parsed.find("$TEMPLATE");
39

  
40
    if ( found != string::npos )
41
    {
42
        string templ;
43
        parsed.replace(found,9,vm->to_xml64(templ));
44
    }
45
}
46

  
47
// -----------------------------------------------------------------------------
48
// -----------------------------------------------------------------------------
49

  
24 50
void VirtualMachineAllocateHook::do_hook(void *arg)
25 51
{
26 52
    VirtualMachine * vm;
27
    int              rc;
28
    string           parsed_args;
53
    string           parsed_args = args;
29 54

  
30 55
    vm = static_cast<VirtualMachine *>(arg);
31 56

  
......
34 59
        return;
35 60
    }
36 61

  
37
    rc = vm->parse_template_attribute(args, parsed_args);
62
    parse_vm_arguments(vm, parsed_args);
38 63

  
39
    if ( rc == 0)
40
    {
41
        Nebula& ne                    = Nebula::instance();
42
        HookManager * hm              = ne.get_hm();
43
        const HookManagerDriver * hmd = hm->get();
64
    Nebula& ne                    = Nebula::instance();
65
    HookManager * hm              = ne.get_hm();
66
    const HookManagerDriver * hmd = hm->get();
44 67

  
45
        if ( hmd != 0 )
46
        {
47
            hmd->execute(vm->get_oid(),name,cmd,parsed_args);
48
        }
68
    if ( hmd != 0 )
69
    {
70
        hmd->execute(vm->get_oid(),name,cmd,parsed_args);
49 71
    }
50 72
}
51 73

  
......
143 165

  
144 166
    if ( cur_lcm == lcm && cur_vm == this->vm )
145 167
    {
146
        string  parsed_args;
168
        string  parsed_args = args;
147 169

  
148
        if ( vm->parse_template_attribute(args, parsed_args) == 0)
149
        {
150
            Nebula& ne        = Nebula::instance();
151
            HookManager * hm  = ne.get_hm();
170
        parse_vm_arguments(vm,parsed_args);
171

  
172
        Nebula& ne        = Nebula::instance();
173
        HookManager * hm  = ne.get_hm();
152 174

  
153
            const HookManagerDriver * hmd = hm->get();
175
        const HookManagerDriver * hmd = hm->get();
154 176

  
155
            if ( hmd != 0 )
177
        if ( hmd != 0 )
178
        {
179
            if ( ! remote )
180
            {
181
                hmd->execute(vm->get_oid(),name,cmd,parsed_args);
182
            }
183
            else if ( vm->hasHistory() )
156 184
            {
157
                if ( ! remote )
158
                {
159
                    hmd->execute(vm->get_oid(),name,cmd,parsed_args);
160
                }
161
                else if ( vm->hasHistory() )
162
                {
163
                    hmd->execute(vm->get_oid(),
164
                         name,
165
                         vm->get_hostname(),
166
                         cmd,
167
                         parsed_args);
168
                }
185
                hmd->execute(vm->get_oid(),
186
                     name,
187
                     vm->get_hostname(),
188
                     cmd,
189
                     parsed_args);
169 190
            }
170 191
        }
171 192
    }

Also available in: Unified diff