Class: Deltacloud::Drivers::Rackspace::RackspaceDriver

Inherits:
BaseDriver
  • Object
show all
Defined in:
lib/deltacloud/drivers/rackspace/rackspace_driver.rb

Instance Method Summary collapse

Methods inherited from BaseDriver

#blob, #bucket, #catched_exceptions_list, declare_feature, define_hardware_profile, define_instance_states, feature, feature_decl_for, feature_decls, #features, features, #filter_hardware_profiles, #filter_on, #find_hardware_profile, #hardware_profile, hardware_profiles, #has_collection?, #image, #instance, #instance_actions_for, instance_state_machine, #instance_state_machine, #realm, #start_instance, #storage_snapshot, #storage_snapshots, #storage_volume, #storage_volumes

Instance Method Details

#blob_data(credentials, bucket_id, blob_id, opts) ⇒ Object

- Blob data -



224
225
226
227
228
229
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 224

def blob_data(credentials, bucket_id, blob_id, opts)
  cf = cloudfiles_client(credentials)
  cf.container(bucket_id).object(blob_id).data_stream do |chunk|
    yield chunk
  end
end

#blobs(credentials, opts) ⇒ Object

– Blobs –



208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 208

def blobs(credentials, opts)
  cf = cloudfiles_client(credentials)
  blobs = []
  safely do
    cf_container = cf.container(opts['bucket'])
    cf_container.objects.each do |object_name|
      blobs << convert_object(cf_container.object(object_name))
    end
  end
  blobs = filter_on(blobs, :id, opts)
  blobs
end

#buckets(credentials, opts) ⇒ Object

– Buckets –



169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 169

def buckets(credentials, opts)
  bucket_list = []
  cf = cloudfiles_client(credentials)
  safely do
    cf.containers.each do |container_name|
      current = cf.container(container_name)
      bucket_list << convert_container(current)
    end #containers.each
  end #safely
  bucket_list = filter_on(bucket_list, :id, opts)
  bucket_list
end

#create_bucket(credentials, name, opts) ⇒ Object

– Create Bucket –



185
186
187
188
189
190
191
192
193
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 185

def create_bucket(credentials, name, opts)
  bucket = nil
  cf = cloudfiles_client(credentials)
  safely do
    new_bucket = cf.create_container(name)
    bucket = convert_container(new_bucket)
  end
  bucket
end

#create_instance(credentials, image_id, opts) ⇒ Object

create instance. Default to flavor 1 - really need a name though… In rackspace, all flavors work with all images.



111
112
113
114
115
116
117
118
119
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 111

def create_instance(credentials, image_id, opts)
  racks = new_client( credentials )
  hwp_id = opts[:hwp_id] || 1
  name = Time.now.to_s
  if (opts[:name]) then name = opts[:name] end
  safely do
    return convert_srv_to_instance(racks.start_server(image_id, hwp_id, name))
  end
end

#delete_bucket(credentials, name, opts) ⇒ Object

– Delete Bucket –



198
199
200
201
202
203
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 198

def delete_bucket(credentials, name, opts)
  cf = cloudfiles_client(credentials)
  safely do
    cf.delete_container(name)
  end
end

#destroy_instance(credentials, id) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 94

def destroy_instance(credentials, id)
  racks = new_client(credentials)
  safely do
    racks.delete_server(id)
  end
  Instance.new( {
    :id => id,
    :state => "STOPPED",
    :actions => instance_actions_for( "STOPPED" ),
  } )
end

#hardware_profiles(credentials, opts = nil) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 35

def hardware_profiles(credentials, opts = nil)
  racks = new_client( credentials )
  results=""
  safely do
    results = racks.list_flavors.map do |flav|
      HardwareProfile.new(flav["id"].to_s) do
        architecture 'x86_64'
        memory flav["ram"].to_i
        storage flav["disk"].to_i
      end
    end
  end
  filter_hardware_profiles(results, opts)
end

#images(credentials, opts = nil) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 50

def images(credentials, opts=nil)
  racks = new_client( credentials )
  results=""
  safely do
    results = racks.list_images.map do |img|
      Image.new( {
                   :id=>img["id"].to_s,
                   :name=>img["name"],
                   :description => img["name"] + " " + img["status"] + "",
                   :owner_id=>"root",
                   :architecture=>'x86_64'
                 } )
    end
  end
  results.sort_by{|e| [e.description]}
  results = filter_on( results, :id, opts )
  results
end

#instances(credentials, opts = nil) ⇒ Object

Instances



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 124

def instances(credentials, opts=nil)
  racks = new_client(credentials)
  instances = []
  safely do
    if (opts.nil?)
      instances = racks.list_servers.map do |srv|
        convert_srv_to_instance(srv)
      end
    else
      instances << convert_srv_to_instance(racks.load_server_details(opts[:id]))
    end
  end
  instances = filter_on( instances, :id, opts )
  instances = filter_on( instances, :state, opts )
  instances
end

#realms(credentials, opts = nil) ⇒ Object

rackspace does not at this stage have realms… its all US/TX, all the time (at least at time of writing)



70
71
72
73
74
75
76
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 70

def realms(credentials, opts=nil)
  [Realm.new( {
    :id=>"us",
    :name=>"United States",
    :state=> "AVAILABLE"
  } )]
end

#reboot_instance(credentials, id) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 78

def reboot_instance(credentials, id)
  racks = new_client(credentials)
  safely do
    racks.reboot_server(id)
  end
  Instance.new( {
    :id => id,
    :state => "RUNNING",
    :actions => instance_actions_for( "RUNNING" ),
  } )
end

#stop_instance(credentials, id) ⇒ Object



90
91
92
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 90

def stop_instance(credentials, id)
  destroy_instance(credentials, id)
end

#supported_collectionsObject



31
32
33
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 31

def supported_collections
  DEFAULT_COLLECTIONS + [ :buckets ]
end

#valid_credentials?(credentials) ⇒ Boolean

Returns:

  • (Boolean)


141
142
143
144
145
146
147
148
# File 'lib/deltacloud/drivers/rackspace/rackspace_driver.rb', line 141

def valid_credentials?(credentials)
  begin
    new_client(credentials)
  rescue
    return false
  end
  true
end