deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jvlcek <jvl...@redhat.com>
Subject Re: Replace datamapper with sequel
Date Thu, 17 Jan 2013 18:58:25 GMT
On 01/16/2013 04:41 AM, Michal Fojtik wrote:
> On 01/15, jvlcek wrote:
>
> Hi Joe,
>
> Thanks for trying and looking at this patch!
>
>> I did some minimal testing and response time seems faster.
>>
>> I tried creating a macine and machine_templates. I was not able
>> to create the machine_templates but that is very likely because I
>> was not doing it correctly. Can you please pass along an example
>> of how to create a machine_template?
> Sure, some sample MachineCreate XML/JSON files are already included
> in Deltacloud GIT repository (server/support/cimi), you can use them
> with the "curl" command:
>
> $ curl -d @support/cimi/machine_template.xml -H 'Content-Type: text/xml' \
>   --user 'mockuser:mockpassword' -X POST \
>   http://localhost:3001/cimi/machine_templates
>
> This should result into MachineTemplate creation. If you want to tweak
> attributes for new MachineTemplate, just edit 'machine_template.xml' file.
>
> That directory contains many other examples for entities we support.
> I mostly added them there while I was working on database stuff (for
> testing).
>
>> +  DATABASE_LOCATION = ENV['DATABASE_LOCATION'] ||
>> +    'sqlite://'+File.join('/', 'var', 'tmp',
>> "deltacloud-mock-#{ENV['USER']}", 'db.sqlite')
>>
>> -  DATABASE_LOCATION = ENV['DATABASE_LOCATION'] || File.join('/', 'var',
>> 'tmp', "deltacloud-mock-#{ENV['USER']}", 'db.sqlite')
>> +  def self.database(opts={})
>> +    opts[:logger] = ::Logger.new($stdout) if ENV['API_VERBOSE']
>> +    @db ||=  Sequel.connect(DATABASE_LOCATION, opts)
>> +  end
>>
>>
>> JoeV: Question/nit:
>> JoeV:
>> JoeV: Would it make more sense to allow DATABASE_LOCATION to specify
>> JoeV: the path to db.sqlite but still use "db.sqlite" at the end of the
>> path?
> The benefit for using 'full' path is that in some case you don't want to
> use sqlite as a database backend, but some other database (like postgres).
> In that case all you need to do is to set 'DATABASE_LOCATION' system env
> variable to something like: "postgres://...".
>
>> JoeV: Question/nit:
>> JoeV:
>> JoeV: Does sequel require the other files which "rake mock:fixtures:reset"
>> JoeV: populates in DATABASE_LOCATION or just "db.sqlite" ? If so:
>> JoeV: doesn't the Rakefile need to be updated to only populate
>> JoeV: DATABASE_LOCATION or just "db.sqlite" ?
> In some cases, like when you create a new Machine using the mock driver,
> Mock driver create YAML files and also add record to the database.
> To reset all this, you need to remove both mock YAML files and also the
> database file.
>
> The only complication could be situlation when you are using DB backend
> other than sqlite. In that case this rake task will of course don't rip
> off the database.
>
>
>> +    database.create_table?(:providers) {
>> +      primary_key :id
>> +
>> +      column :driver, :string, { :null => false }
>> +      column :url, :string
>> +      index [ :url, :driver ]
>> +    }
>> +
>> +    database.create_table?(:entities) {
>> +      primary_key :id
>> +      foreign_key :provider_id, :providers, { :index => true, :null =>
>> false }
>> +      column :created_at, :timestamp
>> +
>>
>> JoeV: Question/nit:
>> JoeV: Why the "?" postfix for create_table"?" ?
>> JoeV: Does it return true on success?
> According to Sequel rdoc, the 'create_table?' method will create the table
> only if the table does not already exists. Without '?' suffix Sequel will
> try (and fail) to create the table structure every time you start
> Deltacloud. If you have 'verbose' mode turned on (-V deltacloudd parameter)
> you will in that case see very nasty sqlite error :-)
>
> Now you will see something like 'CREATE TABLE IF DOES NOT EXISTS' or
> something similar :-)
>
>   -- Michal
>
>>


Thanks for the reply and explanations!

The curl for creating machine_templates
works like a charm!

Thanks,
  Joe

Mime
View raw message