native types for nova-manage'd users and projects

This commit is contained in:
Adam Gandelman 2011-06-02 21:01:25 -07:00
parent a23e793cc2
commit a325487629
11 changed files with 126 additions and 2 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,13 @@
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,7 +21,9 @@ 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
) {
@ -62,4 +64,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

@ -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

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