Class: VagrantPlugins::Skytap::API::Environment
Constant Summary
collapse
- RESOURCE_ROOT =
'/configurations'
Constants included
from Busyable
Busyable::WAIT_ITERATION_PERIOD, Busyable::WAIT_TIMEOUT
Instance Attribute Summary collapse
Attributes inherited from Resource
#attrs, #env
Class Method Summary
collapse
Instance Method Summary
collapse
#busy?, #poweroff!, #running?, #runstate, #set_runstate, #stop!, #stopped?, #suspend!, #wait_for_runstate, #wait_until_ready
Methods included from Busyable
#retry_while_resource_busy, #update_with_retry
Methods inherited from Resource
#reload, resource_name, #url
#get_api_attribute, included
Constructor Details
#initialize(attrs, env) ⇒ Environment
Returns a new instance of Environment.
55
56
57
58
|
# File 'lib/vagrant-skytap/api/environment.rb', line 55
def initialize(attrs, env)
super
@provider_config = env[:machine].provider_config
end
|
Instance Attribute Details
Returns the value of attribute networks.
51
52
53
|
# File 'lib/vagrant-skytap/api/environment.rb', line 51
def networks
@networks
end
|
#provider_config ⇒ Object
Returns the value of attribute provider_config.
50
51
52
|
# File 'lib/vagrant-skytap/api/environment.rb', line 50
def provider_config
@provider_config
end
|
Returns the value of attribute vms.
51
52
53
|
# File 'lib/vagrant-skytap/api/environment.rb', line 51
def vms
@vms
end
|
Class Method Details
.check_vm_before_adding(env, vm) ⇒ Object
44
45
46
|
# File 'lib/vagrant-skytap/api/environment.rb', line 44
def check_vm_before_adding(env, vm)
raise Errors::SourceVmNotStopped, name: env[:machine].name, url: vm.url unless vm.stopped?
end
|
.create!(env, vm_url) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/vagrant-skytap/api/environment.rb', line 19
def create!(env, vm_url)
vm = Vm.fetch(env, vm_url)
check_vm_before_adding(env, vm)
args = {vm_ids: [vm.id]}.tap do |ret|
if vm.from_template?
ret[:template_id] = vm.template_id
else
ret[:configuration_id] = vm.configuration_id
end
end
resp = env[:api_client].post(RESOURCE_ROOT, JSON.dump(args))
new(JSON.load(resp.body), env)
end
|
.fetch(env, url) ⇒ Object
35
36
37
38
|
# File 'lib/vagrant-skytap/api/environment.rb', line 35
def fetch(env, url)
resp = env[:api_client].get(url)
new(JSON.load(resp.body), env)
end
|
.properties(env) ⇒ Object
40
41
42
|
# File 'lib/vagrant-skytap/api/environment.rb', line 40
def properties(env)
EnvironmentProperties.read(env[:machine].env.local_data_path)
end
|
Instance Method Details
#add_vm(vm_url) ⇒ Object
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/vagrant-skytap/api/environment.rb', line 112
def add_vm(vm_url)
vm = Vm.fetch(env, vm_url)
check_vm_before_adding(env, vm)
vm_ids = vms.collect(&:id)
args = {vm_ids: [vm.id]}.tap do |ret|
if vm.from_template?
ret[:template_id] = vm.template_id
else
ret[:merge_configuration] = vm.configuration_id
end
end
update_with_retry(args)
new_vm_ids = vms.collect(&:id) - vm_ids
get_vm_by_id(new_vm_ids.last)
end
|
#check_vm_before_adding(env, vm) ⇒ Object
130
131
132
133
|
# File 'lib/vagrant-skytap/api/environment.rb', line 130
def check_vm_before_adding(env, vm)
raise Errors::RegionMismatch, environment_region: region, vm_region: vm.region unless vm.region == region
self.class.check_vm_before_adding(env, vm)
end
|
#create_publish_set(attrs = {}) ⇒ Object
135
136
137
138
|
# File 'lib/vagrant-skytap/api/environment.rb', line 135
def create_publish_set(attrs={})
resp = api_client.post("#{url}/publish_sets", JSON.dump(attrs))
PublishSet.new(JSON.load(resp.body), self, env)
end
|
#current_vm ⇒ Object
74
75
76
|
# File 'lib/vagrant-skytap/api/environment.rb', line 74
def current_vm
vms.find(&:current_machine?)
end
|
105
106
107
108
109
110
|
# File 'lib/vagrant-skytap/api/environment.rb', line 105
def delete
retry_while_resource_busy do
api_client.delete(url)
break
end
end
|
#get_vm_by_id(id) ⇒ Object
70
71
72
|
# File 'lib/vagrant-skytap/api/environment.rb', line 70
def get_vm_by_id(id)
get_vms_by_id([id]).first
end
|
#get_vms_by_id(ids = []) ⇒ Object
66
67
68
|
# File 'lib/vagrant-skytap/api/environment.rb', line 66
def get_vms_by_id(ids=[])
vms.select{|vm| ids.include?(vm.id)}
end
|
#properties ⇒ Object
140
141
142
|
# File 'lib/vagrant-skytap/api/environment.rb', line 140
def properties
@properties ||= EnvironmentProperties.new(env[:machine].env.local_data_path)
end
|
#publish_sets ⇒ Object
84
85
86
87
88
|
# File 'lib/vagrant-skytap/api/environment.rb', line 84
def publish_sets
@publish_sets ||= (get_api_attribute('publish_sets') || []).collect do |ps_attrs|
PublishSet.new(ps_attrs, self, env)
end
end
|
#refresh(attrs) ⇒ Object
94
95
96
97
98
99
|
# File 'lib/vagrant-skytap/api/environment.rb', line 94
def refresh(attrs)
@vms = nil
@networks = nil
@publish_sets = nil
super
end
|
90
91
92
|
# File 'lib/vagrant-skytap/api/environment.rb', line 90
def region
get_api_attribute('region')
end
|
#run!(vm_ids = nil) ⇒ Object
101
102
103
|
# File 'lib/vagrant-skytap/api/environment.rb', line 101
def run!(vm_ids = nil)
set_runstate :running, vm_ids: vm_ids
end
|