Add power
This commit is contained in:
parent
723bf2ab30
commit
00703a3125
12
config.yaml
12
config.yaml
|
@ -18,6 +18,18 @@ options:
|
|||
default: /etc/nova/nova.conf
|
||||
type: string
|
||||
description: Full path to nova.conf
|
||||
power_user:
|
||||
type: string
|
||||
description: Username used to access hypervisor
|
||||
power_key:
|
||||
type: string
|
||||
description: SSH KEY used to accesss hypervisor
|
||||
power_repo:
|
||||
type: string
|
||||
description: RPM repository to deploy hypervisor
|
||||
power_hosts:
|
||||
type: string
|
||||
description: Hosts to deploy to.
|
||||
rabbit-user:
|
||||
default: nova
|
||||
type: string
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
from charmhelpers.fetch import (
|
||||
apt_install,
|
||||
filter_installed_packages
|
||||
)
|
||||
|
||||
try:
|
||||
from fabric.api import roles, task, run, sudo, local, cd, settings, prefix, put
|
||||
except ImportError:
|
||||
apt_install(filter_installed_packages(['fabric']),
|
||||
fatal=True)
|
||||
from fabric.api import roles, task, run, sudo, local, cd, settings, prefix, put
|
||||
|
||||
def yum_update():
|
||||
sudo('yum update -y')
|
||||
|
||||
def copy_file_as_root(src, dest):
|
||||
put(src, dest, use_sudo=True)
|
||||
|
||||
def yum_install(packages):
|
||||
sudo('yum install --skip-broken -y %s' % ' '.join(packages))
|
||||
|
||||
def restart_service(service):
|
||||
sudo('service openstack-nova-%s restart' %service)
|
||||
|
||||
def add_bridge():
|
||||
sudo('ovs-vsctl -- --may-exist add br-int')
|
|
@ -54,6 +54,12 @@ from nova_compute_utils import (
|
|||
fix_path_ownership
|
||||
)
|
||||
|
||||
from nova_compute_proxy import (
|
||||
configure_power,
|
||||
launch_power
|
||||
)
|
||||
|
||||
|
||||
from nova_compute_context import CEPH_SECRET_UUID
|
||||
|
||||
hooks = Hooks()
|
||||
|
@ -65,7 +71,7 @@ def install():
|
|||
execd_preinstall()
|
||||
configure_installation_source(config('openstack-origin'))
|
||||
apt_update()
|
||||
apt_install(determine_packages(), fatal=True)
|
||||
apt_install(['nova-common', 'libvirt-bin', 'fabric'], fatal=True)
|
||||
|
||||
|
||||
@hooks.hook('config-changed')
|
||||
|
@ -186,6 +192,7 @@ def compute_joined(rid=None):
|
|||
'nova_ssh_public_key': public_ssh_key(user='nova')
|
||||
}
|
||||
relation_set(relation_id=rid, **settings)
|
||||
launch_power()
|
||||
|
||||
|
||||
@hooks.hook('cloud-compute-relation-changed')
|
||||
|
@ -197,12 +204,13 @@ def compute_changed():
|
|||
import_authorized_keys()
|
||||
import_authorized_keys(user='nova', prefix='nova')
|
||||
import_keystone_ca_cert()
|
||||
configure_power()
|
||||
|
||||
|
||||
@hooks.hook('ceph-relation-joined')
|
||||
@restart_on_change(restart_map())
|
||||
def ceph_joined():
|
||||
apt_install(filter_installed_packages(['ceph-common']), fatal=True)
|
||||
log('Nothing to do here')
|
||||
|
||||
|
||||
@hooks.hook('ceph-relation-changed')
|
||||
|
|
|
@ -0,0 +1,136 @@
|
|||
import os
|
||||
import tempfile
|
||||
|
||||
from charmhelpers.core.hookenv import (
|
||||
unit_get,
|
||||
cached,
|
||||
charm_dir,
|
||||
log,
|
||||
config
|
||||
)
|
||||
|
||||
from charmhelpers.fetch import (
|
||||
apt_install,
|
||||
filter_installed_packages
|
||||
)
|
||||
|
||||
from charmhelpers.core.host import service_stop
|
||||
|
||||
from fabfile import (
|
||||
add_bridge,
|
||||
yum_update,
|
||||
copy_file_as_root,
|
||||
yum_install,
|
||||
restart_service
|
||||
)
|
||||
|
||||
try:
|
||||
import jinja2
|
||||
except ImportError:
|
||||
apt_install(filter_installed_packages(['python-jinja2']),
|
||||
fatal=True)
|
||||
import jinja2
|
||||
|
||||
try:
|
||||
from fabric.api import env
|
||||
from fabric.tasks import execute
|
||||
except ImportError:
|
||||
apt_install(filter_installed_packages(['fabric']),
|
||||
fatal=True)
|
||||
from fabric.api import env
|
||||
from fabric.tasks import execute
|
||||
|
||||
TEMPLATE_DIR = 'templates'
|
||||
|
||||
PACKAGES = ['openstack-nova-compute',
|
||||
'openstack-neutron',
|
||||
'openstack-neutron-openvswitch',
|
||||
'openstack-neutron-linuxbridge',
|
||||
'python-neutronclient',
|
||||
'ceilometer-compute-agent']
|
||||
|
||||
CONFIG_FILES = [
|
||||
'/etc/neutron/neutron.conf',
|
||||
'/etc/neutron/plugins/ml2/ml2_conf.ini',
|
||||
'/etc/nova/nova.conf',
|
||||
'/etc/ceilometer/ceilometer.conf']
|
||||
|
||||
SERVICES = ['libvirtd', 'compute', 'neutron']
|
||||
|
||||
def launch_power():
|
||||
log('Launcing power setup')
|
||||
_init_fabric()
|
||||
|
||||
def _setup_host():
|
||||
log('Setting up host')
|
||||
execute(yum_update)
|
||||
|
||||
def _setup_yum():
|
||||
log('Setup yum')
|
||||
context = {'yum_repo': config('power_repo')}
|
||||
|
||||
fd, filename = tempfile.mkstemp()
|
||||
with open(filename, 'w') as f:
|
||||
f.write(_render_template('yum.template', context))
|
||||
execute(copy_file_as_root, filename, '/etc/yum.repos.d/openstack-power.repo')
|
||||
|
||||
def _install_packages():
|
||||
execute(yum_install, PACKAGES)
|
||||
|
||||
_init_fabric()
|
||||
_setup_host()
|
||||
_setup_yum()
|
||||
_install_packages()
|
||||
|
||||
def configure_power():
|
||||
log('configure power')
|
||||
|
||||
def _copy_files():
|
||||
for file in CONFIG_FILES:
|
||||
execute(copy_file_as_root, file, file)
|
||||
|
||||
def _restart_services():
|
||||
for service in SERVICES:
|
||||
execute(restart_service, service)
|
||||
|
||||
def stop_service():
|
||||
services = ['neutron-openvswitch-agent',
|
||||
'openvswitch-service',
|
||||
'ceilometer-agent-compute']
|
||||
for service in service:
|
||||
service_stop(service)
|
||||
|
||||
def _add_bridge():
|
||||
execute(add_bridge)
|
||||
|
||||
_init_fabric()
|
||||
_copy_files()
|
||||
_restart_services()
|
||||
_stop_local_services()
|
||||
_add_bridge()
|
||||
|
||||
def _init_fabric():
|
||||
env.warn_only = True
|
||||
env.connection_attempts = 10
|
||||
env.timeout = 10
|
||||
env.user = config('power_user')
|
||||
env.key_filename= get_key()
|
||||
env.hosts = get_hosts()
|
||||
|
||||
def get_hosts():
|
||||
hosts_file = os.path.join(_charm_path(), config('power_hosts'))
|
||||
with open(hosts_file, 'r') as f:
|
||||
hosts = f.readlines()
|
||||
return hosts
|
||||
|
||||
def get_key():
|
||||
return os.path.join(_charm_path(), config('power_key'))
|
||||
|
||||
def _charm_path():
|
||||
return os.path.join(charm_dir(), 'files')
|
||||
|
||||
def _render_template(template_name, context, template_dir=TEMPLATE_DIR):
|
||||
templates = jinja2.Environment(
|
||||
loader=jinja2.FileSystemLoader(template_dir))
|
||||
template = templates.get_template(template_name)
|
||||
return template.render(context)
|
|
@ -51,19 +51,19 @@ NOVA_CONF = '%s/nova.conf' % NOVA_CONF_DIR
|
|||
|
||||
BASE_RESOURCE_MAP = {
|
||||
QEMU_CONF: {
|
||||
'services': ['libvirt-bin'],
|
||||
'services': [],
|
||||
'contexts': [],
|
||||
},
|
||||
LIBVIRTD_CONF: {
|
||||
'services': ['libvirt-bin'],
|
||||
'contexts': [NovaComputeLibvirtContext()],
|
||||
'services': [],
|
||||
'contexts': [],
|
||||
},
|
||||
LIBVIRT_BIN: {
|
||||
'services': ['libvirt-bin'],
|
||||
'contexts': [NovaComputeLibvirtContext()],
|
||||
'services': [],
|
||||
'contexts': [],
|
||||
},
|
||||
NOVA_CONF: {
|
||||
'services': ['nova-compute'],
|
||||
'services': [],
|
||||
'contexts': [context.AMQPContext(ssl_dir=NOVA_CONF_DIR),
|
||||
context.SharedDBContext(
|
||||
relation_prefix='nova', ssl_dir=NOVA_CONF_DIR),
|
||||
|
@ -376,7 +376,7 @@ def do_openstack_upgrade():
|
|||
]
|
||||
|
||||
apt_upgrade(options=dpkg_opts, fatal=True, dist=True)
|
||||
apt_install(determine_packages(), fatal=True)
|
||||
#apt_install(determine_packages(), fatal=True)
|
||||
|
||||
# Regenerate configs in full for new release
|
||||
configs = register_configs()
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
[openstack-pkvm]
|
||||
name=PowerKVM OpenStack local repository
|
||||
baseurl={{ yum_repo }}
|
||||
gpgcheck=0
|
Loading…
Reference in New Issue