Skip to content

Commit

Permalink
Merge pull request #2131 from mkurek/cloud
Browse files Browse the repository at this point in the history
REP7: Cloud hosts in Ralph & OpenStack sync
  • Loading branch information
mkurek committed Dec 23, 2015
2 parents 49f57ea + 75d3adf commit 9f510f8
Show file tree
Hide file tree
Showing 25 changed files with 1,946 additions and 37 deletions.
60 changes: 60 additions & 0 deletions docs/installation.md
Expand Up @@ -217,3 +217,63 @@ During the process, script will report progress on every 100-th item loaded.
# Migration from Ralph 2

If you used Ralph 2 before and want to save all your data see [Migration from Ralph 2 guide](./data_migration.md#migration_ralph2)

# Synchronization with OpenStack

Ralph 3 supports one-way synchronization with OpenStack. It is possible to
download data from OpenStack including projects and instances. All the
synchronized data will be available in Ralph in read-only mode. It will be
possible only to change the _Service Environment_, _Tags_ and _Remarks_ fields.

**Note**: _Service Environment_ of a _CloudHost_ is inherited from a
_Cloud Project_ to which it belongs.

## Installation

To enable openstack_sync plugin you will have to install python requirements
by executing: ``pip install -r requirements/openstack.txt``

It is also necessary to add your _OpenStack_ instances configuration to your
local settings.
Example configuration should look as follows:
```python3
OPENSTACK_INSTANCES = [
{
'username': 'someuser',
'password': 'somepassword',
'tenant_name': 'admin',
'version': '2.0',
'auth_url': 'http://1.2.3.4:35357/v2.0/',
'tag': 'someinfo'
},
{
... another instance ...
}
]
```

``someuser:`` is an OpenStack user which has permissions to list all the
projects/tenants and instances

``tenant_name:`` project/tenant to which the user will authenticate

``version:`` version of OpenStack API. Currently only **API 2.x** is
supported

``auth_url:`` address, where OpenStack API is available

``tag:`` this is a tag that will be added to each _Cloud Projects_ and _Cloud
Hosts_ migrated from OpenStack

You can add multiple _OpenStack_ instances by adding another _python dict_ to
_OPENSTACK_INSTANCES_ list.

## How to execute

You can either run the script manually by executing: ``ralph openstack_sync``
or you can add it to _corntab_.

First execution will add all the _Cloud Projects_, _Cloud Hosts_ and _Cloud
Flavors_ from _OpenStack_ to _Ralph_. Following executions will add and modify
data as well as delete all the objects which no longer exists in configured
OpenStack Instances.
2 changes: 2 additions & 0 deletions requirements/openstack.txt
@@ -0,0 +1,2 @@
python-keystoneclient>=1.8.0
python-novaclient>=1.5
5 changes: 3 additions & 2 deletions src/ralph/admin/sitetrees.py
Expand Up @@ -89,14 +89,15 @@ def section(section_name, app, model):
children=[
section(_('Hardware'), 'data_center', 'DataCenterAsset'),
section(_('Racks'), 'data_center', 'Rack'),
section(_('Cloud projects'), 'data_center', 'CloudProject'),
section(_('Cloud projects'), 'virtual', 'CloudProject'),
section(_('Cloud hosts'), 'virtual', 'CloudHost'),
section(_('Data Centers'), 'data_center', 'DataCenter'),
section(_('Databases'), 'data_center', 'Database'),
section(_('Disk Shares'), 'data_center', 'DiskShare'),
section(_('Rack Accessories'), 'data_center', 'RackAccessory'),
section(_('Server Rooms'), 'data_center', 'ServerRoom'),
section(_('VIPs'), 'data_center', 'VIP'),
section(_('Virtual Servers'), 'data_center', 'VirtualServer'),
section(_('Virtual Servers'), 'virtual', 'VirtualServer'),
section(_('IP Addresses'), 'data_center', 'ipaddress'),
],
),
Expand Down
17 changes: 1 addition & 16 deletions src/ralph/data_center/admin.py
Expand Up @@ -27,12 +27,7 @@
RackAccessory,
ServerRoom
)
from ralph.data_center.models.virtual import (
CloudProject,
Database,
VIP,
VirtualServer
)
from ralph.data_center.models.virtual import Database, VIP
from ralph.data_center.views.ui import (
DataCenterAssetComponents,
DataCenterAssetSecurityInfo,
Expand Down Expand Up @@ -241,16 +236,6 @@ class VIPAdmin(RalphAdmin):
pass


@register(VirtualServer)
class VirtualServerAdmin(RalphAdmin):
pass


@register(CloudProject)
class CloudProjectAdmin(RalphAdmin):
pass


@register(Connection)
class ConnectionAdmin(RalphAdmin):

Expand Down
6 changes: 6 additions & 0 deletions src/ralph/data_center/api/serializers.py
Expand Up @@ -55,6 +55,12 @@ class Meta(SimpleRackSerializer.Meta):
exclude = ()


class DataCenterAssetSimpleSerializer(RalphAPISerializer):
class Meta:
model = DataCenterAsset
fields = ['hostname', 'tags', 'url']


class DataCenterAssetSerializer(AssetSerializer):
rack = SimpleRackSerializer()

Expand Down
23 changes: 23 additions & 0 deletions src/ralph/data_center/migrations/0005_auto_20151204_1714.py
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('supports', '0003_auto_20151204_1325'),
('licences', '0002_auto_20151204_1325'),
('assets', '0004_auto_20151204_0758'),
('data_center', '0004_auto_20151204_0758'),
]

operations = [
migrations.DeleteModel(
name='CloudProject',
),
migrations.DeleteModel(
name='VirtualServer',
),
]
4 changes: 0 additions & 4 deletions src/ralph/data_center/models/__init__.py
Expand Up @@ -26,15 +26,12 @@
ServerRoom,
)
from ralph.data_center.models.virtual import (
CloudProject,
Database,
VIP,
VirtualServer,
)

__all__ = [
'Accessory',
'CloudProject',
'Connection',
'ConnectionType',
'Database',
Expand All @@ -55,5 +52,4 @@
'RackOrientation',
'ServerRoom',
'VIP',
'VirtualServer',
]
15 changes: 0 additions & 15 deletions src/ralph/data_center/models/virtual.py
Expand Up @@ -20,18 +20,3 @@ class Meta:

def __str__(self):
return 'VIP: {}'.format(self.service_env)


class VirtualServer(BaseObject):
class Meta:
verbose_name = _('Virtual server (VM)')
verbose_name_plural = _('Virtual servers (VM)')

def __str__(self):
return 'VirtualServer: {}'.format(self.service_env)


class CloudProject(BaseObject):

def __str__(self):
return 'CloudProject: {}'.format(self.service_env)
3 changes: 3 additions & 0 deletions src/ralph/settings/base.py
Expand Up @@ -45,6 +45,7 @@ def os_env_true(var, default=''):
'ralph.data_importer',
'ralph.dc_view',
'ralph.reports',
'ralph.virtual',
'ralph.lib.transitions',
'ralph.lib.permissions',
'rest_framework',
Expand Down Expand Up @@ -267,3 +268,5 @@ def os_env_true(var, default=''):
# ]
MY_EQUIPMENT_LINKS = json.loads(os.environ.get('MY_EQUIPMENT_LINKS', '[]'))
MY_EQUIPMENT_REPORT_FAILURE_URL = os.environ.get('MY_EQUIPMENT_REPORT_FAILURE_URL', '') # noqa

OPENSTACK_INSTANCES = json.loads(os.environ.get('OPENSTACK_INSTANCES', '[]'))
1 change: 1 addition & 0 deletions src/ralph/urls/base.py
Expand Up @@ -15,6 +15,7 @@
'ralph.dc_view.urls.api',
'ralph.supports.api',
'ralph.security.api',
'ralph.virtual.api',
]))
# include router urls
# because we're using single router instance and urls are cached inside this
Expand Down
Empty file added src/ralph/virtual/__init__.py
Empty file.

0 comments on commit 9f510f8

Please sign in to comment.