Merge pull request #2 from gandelman-a/for-dan

Create native types for nova-manage subcommands 'admin' and 'project'
This commit is contained in:
Dan Bode 2011-06-03 11:38:04 -07:00
commit 3bc0c998df
13 changed files with 145 additions and 3 deletions

View File

@ -0,0 +1,16 @@
Puppet::Type.type(:nova_admin).provide(:default) do
desc "This is a default provider that does nothing. This allows us to install nova-manage on the same puppet run where we want to use it."
def create
return false
end
def destroy
return false
end
def exists?
fail('This is just the default provider for nova_admin, all it does is fail')
end
end

View File

@ -0,0 +1,20 @@
Puppet::Type.type(:nova_admin).provide(:nova_manage) do
desc "Manage nova admin user "
commands :nova_manage => 'nova-manage'
def exists?
nova_manage("user", "list").match(/^#{resource[:name]}$/)
end
def create
nova_manage("user", "admin", resource[:name])
end
def destroy
nova_manage("user", "delete", resource[:name])
end
end

View File

@ -0,0 +1,16 @@
Puppet::Type.type(:nova_project).provide(:default) do
desc "This is a default provider that does nothing. This allows us to install nova-manage on the same puppet run where we want to use it."
def create
return false
end
def destroy
return false
end
def exists?
fail('This is just the default provider for nova_project, all it does is fail')
end
end

View File

@ -0,0 +1,19 @@
Puppet::Type.type(:nova_project).provide(:nova_manage) do
desc "Manage nova project"
commands :nova_manage => 'nova-manage'
def exists?
nova_manage("project", "list").match(/^#{resource[:name]}$/)
end
def create
nova_manage("project", "create", resource[:name], resource[:owner])
end
def destroy
nova_manage("project", "delete", resource[:name])
end
end

View File

@ -0,0 +1,11 @@
Puppet::Type.newtype(:nova_admin) do
@doc = "Manage creation/deletion of nova admin users."
ensurable
newparam(:name) do
desc "The name of the admins."
end
end

View File

@ -0,0 +1,14 @@
Puppet::Type.newtype(:nova_project) do
@doc = "Manage creation/deletion of nova projects."
ensurable
newparam(:name) do
desc "The name of the project."
end
newparam(:owner) do
desc "Owner of this project."
end
end

View File

@ -21,11 +21,21 @@ class nova::canonical::all(
$state_path,
$lock_path,
$service_down_time,
$host
$host,
$admin_user = 'novaadmin',
$project_name = 'nova'
# they are only supporting libvirt for now
) {
class { 'nova::rabbitmq': }
# work around hostname bug, LP #653405
host { $hostname:
ip => $ipaddress,
host_aliases => $fqdn,
}
class { 'nova::rabbitmq':
require => Host[$hostname],
}
class { "nova":
logdir => $logdir,
@ -62,4 +72,9 @@ class nova::canonical::all(
user => $db_user,
host => $db_host,
}
nova::manage::admin { $admin_user: }
nova::manage::project { $project_name:
owner => $admin_user,
}
}

View File

@ -13,11 +13,18 @@ class nova::db(
tag => $zone,
}
exec { "initial-db-sync":
command => "/usr/bin/nova-manage db sync",
require => Package["nova-common"],
refreshonly => true,
}
mysql::db { $name:
user => $user,
password => $password,
host => $host,
# I may want to inject some sql
require => Class['mysql::server'],
notify => Exec["initial-db-sync"],
}
}

View File

@ -63,7 +63,10 @@ class nova(
group => 'nova',
mode => '0640',
}
exec { "nova-db-sync":
command => "/usr/bin/nova-manage db sync",
refreshonly => "true",
}
# query out the config for our db connection
if $sql_connection {
nova_config { 'sql_connection': value => $sql_connection }

View File

@ -0,0 +1,8 @@
define nova::manage::admin {
nova_admin{ $name:
ensure => present,
provider => 'nova_manage',
notify => Exec["nova-db-sync"],
require => Class["nova::db"],
}
}

View File

@ -0,0 +1,9 @@
define nova::manage::project ( $owner ) {
nova_project { $name:
ensure => present,
owner => $owner,
provider => 'nova_manage',
notify => Exec["nova-db-sync"],
require => [Class["nova::db"], Nova::Manage::Admin[$owner]],
}
}

View File

@ -5,5 +5,7 @@ class nova::rabbitmq {
service { 'rabbitmq-server':
ensure => running,
enable => true,
hasstatus => true,
require => Package["rabbitmq-server"],
}
}

View File

@ -28,4 +28,6 @@ class { 'nova::canonical::all':
service_down_time => '180000000',
host => $hostname,
db_password => 'password',
admin_user => 'admin',
project_name => 'novaproject',
}