0009-Feature-785-Add-lease-remove-lease-support-in-Sunsto.patch

add lease / rm lease options - Hector Sanjuan, 09/01/2011 12:53 AM

Download (9.28 KB)

View differences:

src/sunstone/models/OpenNebulaJSON/VirtualNetworkJSON.rb
42 42
            end
43 43

  
44 44
            rc = case action_hash['perform']
45
                 when "addleases" then self.addleases(action_hash['params'])
46
                 when "rmleases" then self.rmleases(action_hash['params'])
45 47
                 when "publish"   then self.publish
46 48
                 when "unpublish" then self.unpublish
47 49
                 when "chown"     then self.chown(action_hash['params'])
......
52 54
            end
53 55
        end
54 56

  
57
        def addleases(params=Hash.new)
58
            super(params['ip'],params['mac'])
59
        end
60

  
61
        def rmleases(params=Hash.new)
62
            super(params['ip'])
63
        end
64

  
55 65
        def chown(params=Hash.new)
56 66
            super(params['owner_id'].to_i,params['group_id'].to_i)
57 67
        end
src/sunstone/public/js/opennebula.js
834 834
            });
835 835
        },
836 836

  
837
        "addleases" : function(params){
838
            var callback = params.success;
839
            var callback_error = params.error;
840
            var id = params.data.id;
841
            var obj  = params.data.extra_param;
842

  
843
            var method = "addleases";
844
            var action = OpenNebula.Helper.action(method,obj);
845
            var resource = OpenNebula.Network.resource;
846
            var request = OpenNebula.Helper.request(resource,method, [id,obj]);
847

  
848
            $.ajax({
849
                url: "vnet/" + id + "/action",
850
                type: "POST",
851
                data: JSON.stringify(action),
852
                success: function()
853
                {
854
                    if (callback)
855
                    {
856
                        callback(request);
857
                    }
858
                },
859
                error: function(response)
860
                {
861
                    if(callback_error)
862
                    {
863
                        callback_error(request, OpenNebula.Error(response));
864
                    }
865
                }
866
            });
867
        },
868

  
869
        "rmleases" : function(params){
870
            var callback = params.success;
871
            var callback_error = params.error;
872
            var id = params.data.id;
873
            var obj  = params.data.extra_param;
874

  
875
            var method = "rmleases";
876
            var action = OpenNebula.Helper.action(method,obj);
877
            var resource = OpenNebula.Network.resource;
878
            var request = OpenNebula.Helper.request(resource,method, [id,obj]);
879

  
880
            $.ajax({
881
                url: "vnet/" + id + "/action",
882
                type: "POST",
883
                data: JSON.stringify(action),
884
                success: function()
885
                {
886
                    if (callback)
887
                    {
888
                        callback(request);
889
                    }
890
                },
891
                error: function(response)
892
                {
893
                    if(callback_error)
894
                    {
895
                        callback_error(request, OpenNebula.Error(response));
896
                    }
897
                }
898
            });
899
        },
900

  
837 901
        "chown" : function(params){
838 902
            OpenNebula.Helper.chown(params,OpenNebula.Network.resource,"vnet");
839 903
        },
src/sunstone/public/js/plugins/vnets-tab.js
124 124
var vnetworks_select="";
125 125
var dataTable_vNetworks;
126 126
var $create_vn_dialog;
127
var $lease_vn_dialog;
127 128

  
128 129
//Setup actions
129 130

  
......
205 206
        notify: true
206 207
    },
207 208

  
209
    "Network.addleases" : {
210
        type: "single",
211
        call: OpenNebula.Network.addleases,
212
        callback: vnShow,
213
        error: onError,
214
        notify: true
215
    },
216

  
217
    "Network.rmleases" : {
218
        type: "single",
219
        call: OpenNebula.Network.rmleases,
220
        callback: vnShow,
221
        error: onError,
222
        notify: true
223
    },
224

  
225
    "Network.modifyleases" : {
226
        type: "custom",
227
        call: function(action,obj){
228
            nodes = getSelectedNodes(dataTable_vNetworks);
229
            $.each(nodes,function(){
230
                Sunstone.runAction(action,this,obj);
231
            });
232
        }
233
    },
234

  
235
    "Network.addleases_dialog" : {
236
        type: "custom",
237
        call: popUpAddLeaseDialog
238
    },
239

  
240
    "Network.rmleases_dialog" : {
241
        type: "custom",
242
        call: popUpRemoveLeaseDialog
243
    },
244

  
208 245
    "Network.chown" : {
209 246
        type: "multiple",
210 247
        call: OpenNebula.Network.chown,
......
263 300
        condition: mustBeAdmin,
264 301
    },
265 302

  
303
    "action_list" : {
304
        type: "select",
305
        actions: {
306
            "Network.addleases_dialog" : {
307
                type: "action",
308
                text: "Add lease"
309
            },
310
            "Network.rmleases_dialog" : {
311
                type: "action",
312
                text: "Remove lease"
313
            }
314
        }
315
    },
316

  
266 317
    "Network.delete" : {
267 318
        type: "action",
268 319
        text: "Delete"
......
585 636
    $create_vn_dialog.dialog('open');
586 637
}
587 638

  
639
function setupAddRemoveLeaseDialog() {
640
    dialogs_context.append('<div title="Lease management" id="lease_vn_dialog"></div>');
641
    $lease_vn_dialog = $('#lease_vn_dialog',dialogs_context)
642

  
643
    var dialog = $lease_vn_dialog;
644

  
645
    dialog.html(
646
        '<form id="lease_vn_form" action="javascript:alert(\'js error!\');">\
647
           <fieldset>\
648
           <div>Please specify:</div>\
649
           <label for="add_lease_ip">Lease IP:</label>\
650
           <input type="text" name="add_lease_ip" id="add_lease_ip" /><br />\
651
           <label id="add_lease_mac_label" for="add_lease_mac">Lease MAC:</label>\
652
           <input type="text" name="add_lease_mac" id="add_lease_mac" />\
653
           </select>\
654
           </fieldset>\
655
           <fieldset>\
656
           <div class="form_buttons">\
657
              <button id="lease_vn_proceed" class="" value="">OK</button>\
658
              <button class="confirm_cancel" value="">Cancel</button>\
659
           </div>\
660
           </fieldset>\
661
         </form>'
662
    );
663

  
664
    //Prepare the jquery-ui dialog. Set style options here.
665
    dialog.dialog({
666
        autoOpen: false,
667
        modal: true,
668
        width: 410,
669
        height: 220
670
    });
671

  
672
    $('button',dialog).button();
673

  
674
    $('#lease_vn_form',dialog).submit(function(){
675
        var ip = $('#add_lease_ip',this).val();
676
        var mac = $('#add_lease_mac',this).val();
677

  
678
        var obj = {ip: ip, mac: mac};
679

  
680
        if (!mac.length) { delete obj.mac; };
681

  
682
        Sunstone.runAction("Network.modifyleases",
683
                           $('#lease_vn_proceed',this).val(),
684
                           obj);
685
        $lease_vn_dialog.dialog('close');
686
        return false;
687
    });
688
}
689

  
690
function popUpAddLeaseDialog() {
691
    $lease_vn_dialog.dialog("option","title","Add lease");
692
    $('#add_lease_mac',$lease_vn_dialog).show();
693
    $('#add_lease_mac_label',$lease_vn_dialog).show();
694
    $('#lease_vn_proceed',$lease_vn_dialog).val("Network.addleases");
695
    $lease_vn_dialog.dialog("open");
696
}
697

  
698
function popUpRemoveLeaseDialog() {
699
    $lease_vn_dialog.dialog("option","title","Remove lease");
700
    $('#add_lease_mac',$lease_vn_dialog).hide();
701
    $('#add_lease_mac_label',$lease_vn_dialog).hide();
702
    $('#lease_vn_proceed',$lease_vn_dialog).val("Network.rmleases");
703
    $lease_vn_dialog.dialog("open");
704
}
705

  
588 706
function setVNetAutorefresh() {
589 707
    setInterval(function(){
590 708
        var checked = $('input:checked',dataTable_vNetworks.fnGetNodes());
......
620 738
    Sunstone.runAction("Network.list");
621 739

  
622 740
    setupCreateVNetDialog();
741
    setupAddRemoveLeaseDialog();
623 742
    setVNetAutorefresh();
624 743

  
625 744
    initCheckAllBoxes(dataTable_vNetworks);
src/sunstone/public/js/sunstone-util.js
184 184
    } else {
185 185
        msg += action_text + ": " + args;
186 186
    };
187
    if (extra_param) {
187
    if (extra_param && extra_param.constructor != Object) {
188 188
        msg += " >> " + extra_param;
189 189
    };
190 190

  
191
-