Skip to content

Commit

Permalink
ISSUE-2824 Adding user_data to rackspace provider
Browse files Browse the repository at this point in the history
I tried to follow the style of this patch:
xtoddx@24e4bae

So you can actually submit user_data encoded or not
  • Loading branch information
Yann Hamon authored and Yann Hamon committed Apr 7, 2014
1 parent a194336 commit e335084
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 12 additions & 0 deletions lib/fog/rackspace/models/compute_v2/server.rb
Expand Up @@ -117,6 +117,11 @@ class Server < Fog::Compute::Server
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/config_drive_ext.html
attribute :config_drive

# @!attribute [rw] user_data
# @return [Boolean] User-data
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/config_drive_ext.html
attribute :user_data_encoded

# @!attribute [r] bandwidth
# @return [Array] The amount of bandwidth used for the specified audit period.
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/ch_extensions.html#bandwidth_extension
Expand Down Expand Up @@ -183,6 +188,12 @@ def metadata=(hash={})
metadata.from_hash(hash)
end

# Set user data
# @param [String] User data
def user_data=(ascii_userdata)
self.user_data_encoded = [ascii_userdata].pack('m')
end

# Returns the key pair based on the key_name of the server
# @return [KeyPair]
# @note The key_pair/key_name is used to specify the keypair used for server creation. It is not populated by cloud servers.
Expand Down Expand Up @@ -246,6 +257,7 @@ def create(options)
modified_options[:metadata] = metadata.to_hash unless @metadata.nil?
modified_options[:personality] = personality unless personality.nil?
modified_options[:config_drive] = config_drive unless config_drive.nil?
modified_options[:user_data] = user_data_encoded unless user_data_encoded.nil?
modified_options[:key_name] ||= attributes[:key_name]

if modified_options[:networks]
Expand Down
6 changes: 4 additions & 2 deletions lib/fog/rackspace/requests/compute_v2/create_server.rb
Expand Up @@ -30,6 +30,8 @@ class Real
# * networks [Array]:
# * [Hash]:
# * uuid [String] - uuid of attached network
# * config_drive [Boolean]: Wether to use a config drive or not
# * user_data [String]: User data for cloud init
# @raise [Fog::Compute::RackspaceV2::NotFound] - HTTP 404
# @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400
# @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500
Expand Down Expand Up @@ -57,8 +59,8 @@ def create_server(name, image_id, flavor_id, min_count, max_count, options = {})
data['server']['OS-DCF:diskConfig'] = options[:disk_config] unless options[:disk_config].nil?
data['server']['metadata'] = options[:metadata] unless options[:metadata].nil?
data['server']['personality'] = options[:personality] unless options[:personality].nil?
data['server']['config_drive'] = options[:config_drive] unless
options[:config_drive].nil?
data['server']['config_drive'] = options[:config_drive] unless options[:config_drive].nil?
data['server']['user_data'] = options[:user_data] unless options[:user_data].nil?
data['server']['networks'] = options[:networks] || [
{ :uuid => '00000000-0000-0000-0000-000000000000' },
{ :uuid => '11111111-1111-1111-1111-111111111111' }
Expand Down

1 comment on commit e335084

@justinclift
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. Having user_data available through Ruby for Rackspace would be useful for people.

Any chance of writing some doc updates + example for the Rackspace library too, so other people know they can do this? 😄

Please sign in to comment.