Class: Deltacloud::Drivers::Condor::CondorDriver
- Inherits:
-
BaseDriver
- Object
- BaseDriver
- Deltacloud::Drivers::Condor::CondorDriver
show all
- Defined in:
- lib/deltacloud/drivers/condor/condor_driver.rb
Constant Summary
collapse
- CONDOR_MAPPER_DIR =
ENV['CONDOR_MAPPER_DIR'] || '/var/tmp'
Constants inherited
from BaseDriver
BaseDriver::MEMBER_SHOW_METHODS, BaseDriver::STATE_MACHINE_OPTS
Constants included
from Deltacloud
API_VERSION, CIMI_API_VERSION
Instance Method Summary
collapse
Methods inherited from BaseDriver
#address, #api_provider, #blob, #bucket, #catched_exceptions_list, #configured_providers, constraints, define_hardware_profile, define_instance_states, driver_name, feature, features, #filter_hardware_profiles, #filter_on, #find_hardware_profile, #firewall, #hardware_profile, hardware_profiles, #has_capability?, #has_feature?, has_feature?, #image, #instance, #instance_actions_for, instance_state_machine, #instance_state_machine, #key, #name, #realm, #storage_snapshot, #storage_volume, #supported_collections
Methods included from Deltacloud
[], config, configure, connect, database, default_frontend, drivers, enabled_frontends, frontend_required?, frontends, generate_routes, initialize_database, need_database?, new, require_frontend!
#collection_exists?, #collection_names, #collections
Methods included from Exceptions
exception_from_status, exceptions, included, logger, #safely
Instance Method Details
#create_instance(credentials, image_id, opts = {}) ⇒ Object
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/deltacloud/drivers/condor/condor_driver.rb', line 118
def create_instance(credentials, image_id, opts={})
user_data = opts[:user_data] ? Base64.decode64(opts[:user_data]) : nil
if user_data
config_server_address, vm_uuid, vm_otp = opts[:user_data].strip.split(';')
if vm_uuid.nil? and vm_otp.nil?
vm_uuid = config_server_address
config_server_address = nil
end
end
vm_uuid ||= UUIDTools::UUID.random_create.to_s
vm_otp ||= vm_uuid[0..7]
new_client(credentials) do |condor|
config_server_address ||= condor.ip_agent.address
image = images(credentials, :id => image_id).first
hardware_profile = hardware_profiles(credentials, :id => opts[:hwp_id] || 'small').first
instance = condor.launch_instance(image, hardware_profile, {
:name => opts[:name] || "i-#{Time.now.to_i}",
:config_server_address => config_server_address,
:uuid => vm_uuid,
:otp => vm_otp,
}).first
store(:uuid, vm_uuid, instance.id)
raise "Error: VM not launched" unless instance
instance(credentials, { :id => instance.id, :password => vm_otp })
end
end
|
#destroy_instance(credentials, instance_id) ⇒ Object
154
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/deltacloud/drivers/condor/condor_driver.rb', line 154
def destroy_instance(credentials, instance_id)
old_instance = instance(credentials, :id => instance_id)
new_client(credentials) do |condor|
condor.destroy_instance(instance_id)
remove_key(:uuid, instance_id)
remove_key(:mac, instance_id)
end
old_instance.state = 'PENDING'
old_instance.actions = instance_actions_for(old_instance.state),
old_instance
end
|
#hardware_profiles(credentials, opts = {}) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/deltacloud/drivers/condor/condor_driver.rb', line 46
def hardware_profiles(credentials, opts={})
results = []
new_client(credentials) do |condor|
results = condor.hardware_profiles.collect do |hwp|
HardwareProfile::new(hwp[:name]) do
architecture 'x86_64'
memory hwp[:memory]
cpu hwp[:cpus]
storage 100
end
end
end
filter_hardware_profiles(results, opts)
end
|
#images(credentials, opts = {}) ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/deltacloud/drivers/condor/condor_driver.rb', line 72
def images(credentials, opts={})
results = []
new_client(credentials) do |condor|
results = condor.images.collect do |image|
Image::new(
:id => Digest::SHA1.hexdigest(image.name).to_s,
:name => image.name.split(':').first,
:state => image.state || 'AVAILABLE',
:architecture => 'x86_64',
:owner_id => image.owner_id || 'unknown',
:description => image.description
)
end
end
filter_on( results, :id, opts )
end
|
#instances(credentials, opts = {}) ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/deltacloud/drivers/condor/condor_driver.rb', line 89
def instances(credentials, opts={})
results = []
new_client(credentials) do |condor|
results = condor.instances.collect do |instance|
vm_uuid = get_value(:uuid, instance.id)
ip_address = condor.ip_agent.find_ip_by_mac(vm_uuid)
Instance::new(
:id => instance.id,
:name => instance.name,
:realm_id => 'default',
:instance_profile => InstanceProfile::new(instance.instance_profile.name),
:image_id => instance.image_id,
:public_addresses => [ InstanceAddress.new(ip_address) ],
:private_addresses => [],
:owner_id => instance.owner_id,
:description => instance.name,
:architecture => 'x86_64',
:actions => instance_actions_for(instance.state),
:launch_time => instance.launch_time,
:username => 'root',
:password => opts[:password],
:state => instance.state
)
end
end
results = filter_on( results, :state, opts )
filter_on( results, :id, opts )
end
|
#realms(credentials, opts = {}) ⇒ Object
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/deltacloud/drivers/condor/condor_driver.rb', line 61
def realms(credentials, opts={})
[
Realm::new(
:id => 'default',
:name => 'Default Condor Realm',
:limit => :unlimited,
:state => 'AVAILABLE'
)
]
end
|
#valid_credentials?(credentials) ⇒ Boolean
175
176
177
178
179
180
|
# File 'lib/deltacloud/drivers/condor/condor_driver.rb', line 175
def valid_credentials?(credentials)
if ( credentials.user != @config[:username] ) or ( credentials.password != @config[:password] )
return false
end
return true
end
|