mirror of
https://github.com/ansible/awx.git
synced 2026-03-22 11:25:08 -02:30
Insights project api side integration
* Extend scm credential type to support username and password for redhat portal accounts * Update project update playbook to work with remote insights server
This commit is contained in:
24
awx/main/migrations/0036_v311_insights.py
Normal file
24
awx/main/migrations/0036_v311_insights.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('main', '0035_v310_remove_tower_settings'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='project',
|
||||||
|
name='scm_type',
|
||||||
|
field=models.CharField(default=b'', choices=[(b'', 'Manual'), (b'git', 'Git'), (b'hg', 'Mercurial'), (b'svn', 'Subversion'), (b'insights', 'Red Hat Insights')], max_length=8, blank=True, help_text='Specifies the source control system used to store the project.', verbose_name='SCM Type'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='projectupdate',
|
||||||
|
name='scm_type',
|
||||||
|
field=models.CharField(default=b'', choices=[(b'', 'Manual'), (b'git', 'Git'), (b'hg', 'Mercurial'), (b'svn', 'Subversion'), (b'insights', 'Red Hat Insights')], max_length=8, blank=True, help_text='Specifies the source control system used to store the project.', verbose_name='SCM Type'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -43,6 +43,7 @@ class ProjectOptions(models.Model):
|
|||||||
('git', _('Git')),
|
('git', _('Git')),
|
||||||
('hg', _('Mercurial')),
|
('hg', _('Mercurial')),
|
||||||
('svn', _('Subversion')),
|
('svn', _('Subversion')),
|
||||||
|
('insights', _('Red Hat Insights')),
|
||||||
]
|
]
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
@@ -120,6 +121,8 @@ class ProjectOptions(models.Model):
|
|||||||
return self.scm_type or ''
|
return self.scm_type or ''
|
||||||
|
|
||||||
def clean_scm_url(self):
|
def clean_scm_url(self):
|
||||||
|
if self.scm_type == 'insights':
|
||||||
|
self.scm_url = settings.INSIGHTS_URL_BASE
|
||||||
scm_url = unicode(self.scm_url or '')
|
scm_url = unicode(self.scm_url or '')
|
||||||
if not self.scm_type:
|
if not self.scm_type:
|
||||||
return ''
|
return ''
|
||||||
@@ -139,8 +142,10 @@ class ProjectOptions(models.Model):
|
|||||||
cred = self.credential
|
cred = self.credential
|
||||||
if cred:
|
if cred:
|
||||||
if cred.kind != 'scm':
|
if cred.kind != 'scm':
|
||||||
raise ValidationError(_("Credential kind must be 'scm'."))
|
raise ValidationError(_("Credential kind must be either 'scm'."))
|
||||||
try:
|
try:
|
||||||
|
if self.scm_type == 'insights':
|
||||||
|
self.scm_url = settings.INSIGHTS_URL_BASE
|
||||||
scm_url = update_scm_url(self.scm_type, self.scm_url,
|
scm_url = update_scm_url(self.scm_type, self.scm_url,
|
||||||
check_special_cases=False)
|
check_special_cases=False)
|
||||||
scm_url_parts = urlparse.urlsplit(scm_url)
|
scm_url_parts = urlparse.urlsplit(scm_url)
|
||||||
|
|||||||
@@ -1189,6 +1189,9 @@ class RunProjectUpdate(BaseTask):
|
|||||||
scm_username = False
|
scm_username = False
|
||||||
elif scm_url_parts.scheme.endswith('ssh'):
|
elif scm_url_parts.scheme.endswith('ssh'):
|
||||||
scm_password = False
|
scm_password = False
|
||||||
|
elif scm_type == 'insights':
|
||||||
|
extra_vars['scm_username'] = scm_username
|
||||||
|
extra_vars['scm_password'] = scm_password
|
||||||
scm_url = update_scm_url(scm_type, scm_url, scm_username,
|
scm_url = update_scm_url(scm_type, scm_url, scm_username,
|
||||||
scm_password, scp_format=True)
|
scm_password, scp_format=True)
|
||||||
else:
|
else:
|
||||||
@@ -1218,6 +1221,7 @@ class RunProjectUpdate(BaseTask):
|
|||||||
scm_branch = project_update.scm_branch or {'hg': 'tip'}.get(project_update.scm_type, 'HEAD')
|
scm_branch = project_update.scm_branch or {'hg': 'tip'}.get(project_update.scm_type, 'HEAD')
|
||||||
extra_vars.update({
|
extra_vars.update({
|
||||||
'project_path': project_update.get_project_path(check_if_exists=False),
|
'project_path': project_update.get_project_path(check_if_exists=False),
|
||||||
|
'insights_url': settings.INSIGHTS_URL_BASE,
|
||||||
'scm_type': project_update.scm_type,
|
'scm_type': project_update.scm_type,
|
||||||
'scm_url': scm_url,
|
'scm_url': scm_url,
|
||||||
'scm_branch': scm_branch,
|
'scm_branch': scm_branch,
|
||||||
|
|||||||
@@ -261,7 +261,7 @@ def update_scm_url(scm_type, url, username=True, password=True,
|
|||||||
# git: https://www.kernel.org/pub/software/scm/git/docs/git-clone.html#URLS
|
# git: https://www.kernel.org/pub/software/scm/git/docs/git-clone.html#URLS
|
||||||
# hg: http://www.selenic.com/mercurial/hg.1.html#url-paths
|
# hg: http://www.selenic.com/mercurial/hg.1.html#url-paths
|
||||||
# svn: http://svnbook.red-bean.com/en/1.7/svn-book.html#svn.advanced.reposurls
|
# svn: http://svnbook.red-bean.com/en/1.7/svn-book.html#svn.advanced.reposurls
|
||||||
if scm_type not in ('git', 'hg', 'svn'):
|
if scm_type not in ('git', 'hg', 'svn', 'insights'):
|
||||||
raise ValueError(_('Unsupported SCM type "%s"') % str(scm_type))
|
raise ValueError(_('Unsupported SCM type "%s"') % str(scm_type))
|
||||||
if not url.strip():
|
if not url.strip():
|
||||||
return ''
|
return ''
|
||||||
@@ -307,6 +307,7 @@ def update_scm_url(scm_type, url, username=True, password=True,
|
|||||||
'git': ('ssh', 'git', 'git+ssh', 'http', 'https', 'ftp', 'ftps', 'file'),
|
'git': ('ssh', 'git', 'git+ssh', 'http', 'https', 'ftp', 'ftps', 'file'),
|
||||||
'hg': ('http', 'https', 'ssh', 'file'),
|
'hg': ('http', 'https', 'ssh', 'file'),
|
||||||
'svn': ('http', 'https', 'svn', 'svn+ssh', 'file'),
|
'svn': ('http', 'https', 'svn', 'svn+ssh', 'file'),
|
||||||
|
'insights': ('http', 'https')
|
||||||
}
|
}
|
||||||
if parts.scheme not in scm_type_schemes.get(scm_type, ()):
|
if parts.scheme not in scm_type_schemes.get(scm_type, ()):
|
||||||
raise ValueError(_('Unsupported %s URL') % scm_type)
|
raise ValueError(_('Unsupported %s URL') % scm_type)
|
||||||
@@ -342,7 +343,7 @@ def update_scm_url(scm_type, url, username=True, password=True,
|
|||||||
#raise ValueError('Password not supported for SSH with Mercurial.')
|
#raise ValueError('Password not supported for SSH with Mercurial.')
|
||||||
netloc_password = ''
|
netloc_password = ''
|
||||||
|
|
||||||
if netloc_username and parts.scheme != 'file':
|
if netloc_username and parts.scheme != 'file' and scm_type != "insights":
|
||||||
netloc = u':'.join([urllib.quote(x) for x in (netloc_username, netloc_password) if x])
|
netloc = u':'.join([urllib.quote(x) for x in (netloc_username, netloc_password) if x])
|
||||||
else:
|
else:
|
||||||
netloc = u''
|
netloc = u''
|
||||||
|
|||||||
@@ -105,6 +105,32 @@
|
|||||||
scm_version: "{{ scm_result['after'] }}"
|
scm_version: "{{ scm_result['after'] }}"
|
||||||
when: "'after' in scm_result"
|
when: "'after' in scm_result"
|
||||||
|
|
||||||
|
- name: update project using insights
|
||||||
|
uri:
|
||||||
|
url: "{{insights_url}}/r/insights/v1/maintenance"
|
||||||
|
user: "{{scm_username|quote}}"
|
||||||
|
password: "{{scm_password|quote}}"
|
||||||
|
force_basic_auth: yes
|
||||||
|
when: scm_type == 'insights'
|
||||||
|
register: insights_output
|
||||||
|
|
||||||
|
- name: Ensure the project directory is present
|
||||||
|
file:
|
||||||
|
dest: "{{project_path|quote}}"
|
||||||
|
state: directory
|
||||||
|
when: scm_type == 'insights'
|
||||||
|
|
||||||
|
- name: Fetch Insights Playbook
|
||||||
|
get_url:
|
||||||
|
url: "{{insights_url}}/r/insights/v3/maintenance/{{item.maintenance_id}}/playbook"
|
||||||
|
dest: "{{project_path|quote}}/{{item.maintenance_id}}.yml"
|
||||||
|
url_username: "{{scm_username|quote}}"
|
||||||
|
url_password: "{{scm_password|quote}}"
|
||||||
|
force_basic_auth: yes
|
||||||
|
when: scm_type == 'insights'
|
||||||
|
with_items: "{{insights_output.json}}"
|
||||||
|
failed_when: false
|
||||||
|
|
||||||
- name: detect requirements.yml
|
- name: detect requirements.yml
|
||||||
stat: path={{project_path|quote}}/roles/requirements.yml
|
stat: path={{project_path|quote}}/roles/requirements.yml
|
||||||
register: doesRequirementsExist
|
register: doesRequirementsExist
|
||||||
|
|||||||
@@ -862,6 +862,8 @@ TOWER_ADMIN_ALERTS = True
|
|||||||
# Note: This setting may be overridden by database settings.
|
# Note: This setting may be overridden by database settings.
|
||||||
TOWER_URL_BASE = "https://towerhost"
|
TOWER_URL_BASE = "https://towerhost"
|
||||||
|
|
||||||
|
INSIGHTS_URL_BASE = "https://access.redhat.com"
|
||||||
|
|
||||||
TOWER_SETTINGS_MANIFEST = {}
|
TOWER_SETTINGS_MANIFEST = {}
|
||||||
|
|
||||||
LOG_AGGREGATOR_ENABLED = False
|
LOG_AGGREGATOR_ENABLED = False
|
||||||
|
|||||||
Reference in New Issue
Block a user