Revision cd580714

View differences:

include/ExtendedAttribute.h
219 219
    /* ---------------------------------------------------------------------- */
220 220
    /**
221 221
     *  Adds a new VirtualMachine attribute to the set
222
     *    @param a the Extended attribute to add
223
     *    @param id of the new attribute
222 224
     */
223 225
    void add_attribute(ExtendedAttribute * a, int id)
224 226
    {
......
226 228
    }
227 229

  
228 230
    /**
231
     *  Deletes an attribute from the set
232
     *    @param id of the attribute
233
     *    @return the attribute removed or 0 if not found
234
     */
235
    ExtendedAttribute * delete_attribute(int id);
236

  
237
    /**
229 238
     *  Init the attribute set from a vector
230 239
     *    @param id_name with the ID of the attribute
231 240
     *    @param auto_ids automatically generate ids for the attributes
include/RequestManagerZone.h
67 67
/* -------------------------------------------------------------------------- */
68 68
/* -------------------------------------------------------------------------- */
69 69

  
70
/* ------------------------------------------------------------------------- */
71
/* ------------------------------------------------------------------------- */
72

  
73
class ZoneDeleteServer : public RequestManagerZone
74
{
75
public:
76
    ZoneDeleteServer():
77
        RequestManagerZone("ZoneDeleteServer", "Delete a server from zone",
78
                "A:sii"){};
79

  
80
    ~ZoneDeleteServer(){};
81

  
82
    void request_execute(xmlrpc_c::paramList const& _paramList,
83
                         RequestAttributes& att);
84
};
85

  
70 86
#endif
include/Zone.h
53 53
     *
54 54
     *    @return 0 on success, -1 otherwise
55 55
     */
56
    int add_servers(Template& tmpl, string& error);
56
    int add_server(Template& tmpl, string& error);
57

  
58
    /**
59
     *  Delete a server from this zone
60
     *    @param it of the SERVER
61
     *    @param error if any
62
     *
63
     *    @return 0 on success, -1 otherwise
64
     */
65
    int delete_server(int id, string& error);
57 66

  
58 67
private:
59 68
    // -------------------------------------------------------------------------
include/ZoneServer.h
168 168
        return 0;
169 169
    };
170 170

  
171
    ZoneServer * delete_server(int id)
172
    {
173
        return static_cast<ZoneServer *>(delete_attribute(id));
174
    };
175

  
176

  
171 177
protected:
172 178
    ExtendedAttribute * attribute_factory(VectorAttribute * va, int id) const
173 179
    {
src/cli/onezone
118 118

  
119 119
    end
120 120

  
121
    delserver_desc = <<-EOT.unindent
122
        Delete an OpenNebula server from this zone.
123
    EOT
124

  
125
    command :"server-del", delserver_desc, :zoneid, :serverid do
126
        helper.perform_action(args[0], options, "server deleted") do |o|
127
            o.delete_servers(args[1].to_i)
128
        end
129

  
130
    end
121 131
    update_desc = <<-EOT.unindent
122 132
        Update the template contents. If a path is not provided the editor will
123 133
        be launched to modify the current content.
src/common/ExtendedAttribute.cc
75 75
    }
76 76
};
77 77

  
78
/* -------------------------------------------------------------------------- */
79
/* -------------------------------------------------------------------------- */
80

  
81
ExtendedAttribute * ExtendedAttributeSet::delete_attribute(int id)
82
{
83
    std::map<int, ExtendedAttribute*>::iterator it = a_set.find(id);
84

  
85
    if ( it == a_set.end() )
86
    {
87
        return 0;
88
    }
89

  
90
    a_set.erase(it);
91

  
92
    return it->second;
93
}
94

  
src/oca/ruby/opennebula/zone.rb
29 29
            :update         => "zone.update",
30 30
            :rename         => "zone.rename",
31 31
            :delete         => "zone.delete",
32
            :addserver      => "zone.addserver"
32
            :addserver      => "zone.addserver",
33
            :delserver      => "zone.delserver"
33 34
        }
34 35

  
35 36
        # Creates a Zone description with just its identifier
......
115 116
        def add_servers(servers)
116 117
            return call(ZONE_METHODS[:addserver], @pe_id, servers)
117 118
        end
119

  
120
        # Delete servers from this Zone
121
        #
122
        # @param id [Int] Server ID
123
        #
124
        # @return [nil, OpenNebula::Error] nil in case of success, Error
125
        #   otherwise
126
        def delete_servers(server_id)
127
            return call(ZONE_METHODS[:delserver], @pe_id, server_id)
128
        end
118 129
    end
119 130
end
src/rm/RequestManager.cc
760 760
    xmlrpc_c::method * zone_delete_pt;
761 761
    xmlrpc_c::method * zone_rename_pt;
762 762
    xmlrpc_c::method * zone_addserver_pt;
763
    xmlrpc_c::method * zone_delserver_pt;
763 764

  
764 765
    if (nebula.is_federation_slave())
765 766
    {
......
768 769
        zone_delete_pt      = new RequestManagerProxy("one.zone.delete");
769 770
        zone_rename_pt      = new RequestManagerProxy("one.zone.rename");
770 771
        zone_addserver_pt   = new RequestManagerProxy("one.zone.addserver");
772
        zone_delserver_pt   = new RequestManagerProxy("one.zone.delserver");
771 773
    }
772 774
    else
773 775
    {
......
776 778
        zone_delete_pt      = new ZoneDelete();
777 779
        zone_rename_pt      = new ZoneRename();
778 780
        zone_addserver_pt   = new ZoneAddServer();
781
        zone_delserver_pt   = new ZoneDeleteServer();
779 782
    }
780 783

  
781 784
    xmlrpc_c::methodPtr zone_allocate(zone_allocate_pt);
......
783 786
    xmlrpc_c::methodPtr zone_delete(zone_delete_pt);
784 787
    xmlrpc_c::methodPtr zone_rename(zone_rename_pt);
785 788
    xmlrpc_c::methodPtr zone_addserver(zone_addserver_pt);
789
    xmlrpc_c::methodPtr zone_delserver(zone_delserver_pt);
786 790

  
787 791
    xmlrpc_c::methodPtr zone_info(new ZoneInfo());
788 792
    xmlrpc_c::methodPtr zonepool_info(new ZonePoolInfo());
......
794 798
    RequestManagerRegistry.addMethod("one.zone.rename",  zone_rename);
795 799

  
796 800
    RequestManagerRegistry.addMethod("one.zone.addserver", zone_addserver);
801
    RequestManagerRegistry.addMethod("one.zone.delserver", zone_delserver);
797 802

  
798 803
    RequestManagerRegistry.addMethod("one.zonepool.info",zonepool_info);
799 804

  
src/rm/RequestManagerZone.cc
55 55
        return;
56 56
    }
57 57

  
58
    if ( zone->add_servers(zs_tmpl, att.resp_msg) == -1 )
58
    if ( zone->add_server(zs_tmpl, att.resp_msg) == -1 )
59 59
    {
60 60
        failure_response(ACTION, att);
61 61

  
......
72 72
/* -------------------------------------------------------------------------- */
73 73
/* -------------------------------------------------------------------------- */
74 74

  
75
void ZoneDeleteServer::request_execute(xmlrpc_c::paramList const& paramList,
76
    RequestAttributes& att)
77
{
78
    int id    = xmlrpc_c::value_int(paramList.getInt(1));
79
    int zs_id = xmlrpc_c::value_int(paramList.getInt(2));
80

  
81
    string error_str;
82

  
83
    if ( basic_authorization(id, att) == false )
84
    {
85
        return;
86
    }
87

  
88
    Zone * zone = (static_cast<ZonePool *>(pool))->get(id, true);
89

  
90
    if ( zone == 0 )
91
    {
92
        att.resp_id = id;
93
        failure_response(NO_EXISTS, att);
94

  
95
        return;
96
    }
97

  
98
    if ( zone->delete_server(zs_id, att.resp_msg) == -1 )
99
    {
100
        failure_response(ACTION, att);
101
        zone->unlock();
102

  
103
        return;
104
    }
105

  
106
    pool->update(zone);
107

  
108
    zone->unlock();
109

  
110
    success_response(id, att);
111
}
112

  
113
/* -------------------------------------------------------------------------- */
114
/* -------------------------------------------------------------------------- */
115

  
src/zone/Zone.cc
300 300
/* -------------------------------------------------------------------------- */
301 301
/* -------------------------------------------------------------------------- */
302 302

  
303
int Zone::add_servers(Template& tmpl, string& error)
303
int Zone::add_server(Template& tmpl, string& error)
304 304
{
305 305
    vector<VectorAttribute *> vs;
306 306
    vector<VectorAttribute *>::iterator it;
......
326 326
    return 0;
327 327
}
328 328

  
329
int Zone::delete_server(int id, string& error)
330
{
331
    ZoneServer * zs;
332

  
333
    zs = servers->delete_server(id);
334

  
335
    if ( zs == 0 )
336
    {
337
        error = "SERVER not found in zone";
338
        return -1;
339
    }
340

  
341
    delete servers_template.remove(zs->vector_attribute());
342

  
343
    delete zs;
344

  
345
    return 0;
346
}

Also available in: Unified diff