Class: InstancesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/instances_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#dispatch, #get_locales, #is_dcmgr?, #set_application, #set_locale

Instance Method Details

#createObject



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/instances_controller.rb', line 7

def create
  data = {
    :image_id => params[:image_id],
    :instance_spec_id => params[:instance_spec_id],
    :host_pool_id => params[:host_pool_id],
    :host_name => params[:host_name],
    :user_data => params[:user_data],
    :security_groups => params[:security_groups],
    :ssh_key => params[:ssh_key]
  }
  instance = DcmgrResource::Instance.create(params)
  render :json => instance
end

#indexObject



4
5
# File 'app/controllers/instances_controller.rb', line 4

def index
end

#listObject



21
22
23
24
25
26
27
28
# File 'app/controllers/instances_controller.rb', line 21

def list
  data = {
    :start => params[:start].to_i - 1,
    :limit => params[:limit]
  }
  instances = DcmgrResource::Instance.list(data)
  respond_with(instances[0],:to => [:json])
end

#rebootObject



45
46
47
48
49
50
51
52
# File 'app/controllers/instances_controller.rb', line 45

def reboot
  instance_ids = params[:ids]
  res = []
  instance_ids.each do |instance_id|
    res << DcmgrResource::Instance.reboot(instance_id)
  end
  render :json => res
end

#showObject



30
31
32
33
34
# File 'app/controllers/instances_controller.rb', line 30

def show
  instance_id = params[:id]
  detail = DcmgrResource::Instance.show(instance_id)
  respond_with(detail,:to => [:json])
end

#startObject



54
55
56
57
58
59
60
61
# File 'app/controllers/instances_controller.rb', line 54

def start
  instance_ids = params[:ids]
  res = []
  instance_ids.each do |instance_id|
    res << DcmgrResource::Instance.start(instance_id)
  end
  render :json => res
end

#stopObject



63
64
65
66
67
68
69
70
# File 'app/controllers/instances_controller.rb', line 63

def stop
  instance_ids = params[:ids]
  res = []
  instance_ids.each do |instance_id|
    res << DcmgrResource::Instance.stop(instance_id)
  end
  render :json => res
end

#terminateObject



36
37
38
39
40
41
42
43
# File 'app/controllers/instances_controller.rb', line 36

def terminate
  instance_ids = params[:ids]
  res = []
  instance_ids.each do |instance_id|
    res << DcmgrResource::Instance.destroy(instance_id)
  end
  render :json => res
end

#totalObject



72
73
74
75
76
77
78
79
# File 'app/controllers/instances_controller.rb', line 72

def total
 all_resource_count = DcmgrResource::Instance.total_resource
 all_resources = DcmgrResource::Instance.find(:all,:params => {:start => 0, :limit => all_resource_count})
 resources = all_resources[0].results
 terminated_resource_count = DcmgrResource::Instance.get_resource_state_count(resources, 'terminated')
 total = all_resource_count - terminated_resource_count
 render :json => total
end