/
1004-cern-python-django-horizon-windows-powershell.patch
141 lines (132 loc) · 6.01 KB
/
1004-cern-python-django-horizon-windows-powershell.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
From: Jose Castro Leon <jose.castro.leon@cern.ch>
Date: Fri, 21 Feb 2014 08:11:00 +0200
Subject: [PATCH] CERN Add powershell shell script for windows clients
---
--- a/openstack_dashboard/static/dashboard/less/horizon.less 2013-11-29 14:49:55.000000000 +0100
+++ b/openstack_dashboard/static/dashboard/less/horizon.less 2013-11-29 15:14:43.000000000 +0100
@@ -600,6 +600,10 @@
.btn-icon(-91px, -19px);
}
+ a.btn-windows {
+ .btn-icon(5px, 6px, "/static/bootstrap/img/windows.png");
+ }
+
a.btn-upload {
.btn-icon(-283px, -92px);
}
--- a/openstack_dashboard/dashboards/project/access_and_security/api_access/tables.py 2013-11-29 15:19:28.000000000 +0100
+++ b/openstack_dashboard/dashboards/project/access_and_security/api_access/tables.py 2013-11-29 15:21:24.000000000 +0100
@@ -45,6 +45,14 @@
url = "horizon:project:access_and_security:api_access:openrc"
+class DownloadPS(tables.LinkAction):
+ name = "download_ps"
+ verbose_name = _("Download PowerShell RC")
+ verbose_name_plural = _("Download PowerShell RC")
+ classes = ("btn-windows",)
+ url = "horizon:project:access_and_security:api_access:ps"
+
+
class EndpointsTable(tables.DataTable):
api_name = tables.Column('type',
verbose_name=_("Service"),
@@ -56,4 +64,4 @@
name = "endpoints"
verbose_name = _("API Endpoints")
multi_select = False
- table_actions = (DownloadOpenRC, DownloadEC2,)
+ table_actions = (DownloadOpenRC, DownloadEC2, DownloadPS)
--- a/openstack_dashboard/dashboards/project/access_and_security/api_access/urls.py 2013-11-29 15:23:14.000000000 +0100
+++ b/openstack_dashboard/dashboards/project/access_and_security/api_access/urls.py 2013-11-29 15:23:41.000000000 +0100
@@ -28,4 +28,5 @@
urlpatterns = patterns('',
url(r'^ec2/$', views.download_ec2_bundle, name='ec2'),
url(r'^openrc/$', views.download_rc_file, name='openrc'),
+ url(r'^ps/$', views.download_ps_file, name='ps'),
)
--- a/openstack_dashboard/dashboards/project/access_and_security/api_access/views.py 2013-11-29 15:24:08.000000000 +0100
+++ b/openstack_dashboard/dashboards/project/access_and_security/api_access/views.py 2013-11-29 15:25:00.000000000 +0100
@@ -28,7 +28,7 @@
from horizon import messages
from openstack_dashboard import api
-
+from openstack_dashboard import settings
LOG = logging.getLogger(__name__)
@@ -133,3 +133,35 @@
LOG.exception("Exception in DownloadOpenRCForm.")
messages.error(request, _('Error Downloading RC File: %s') % e)
return shortcuts.redirect(request.build_absolute_uri())
+
+def download_ps_file(request):
+ tenant_id = request.user.tenant_id
+ tenant_name = request.user.tenant_name
+
+ template = 'project/access_and_security/api_access/openstack.ps.template'
+
+ try:
+ keystone_url = api.base.url_for(request,
+ 'identity',
+ endpoint_type='publicURL')
+
+ context = {'user': request.user,
+ 'auth_url': keystone_url,
+ 'tenant_id': tenant_id,
+ 'cachain_url': settings.CACHAIN_URL,
+ 'tenant_name': tenant_name}
+
+ response = shortcuts.render(request,
+ template,
+ context,
+ content_type="text/plain")
+ response['Content-Disposition'] = ('attachment; '
+ 'filename=%s.ps1'
+ % tenant_name)
+ response['Content-Length'] = str(len(response.content))
+ return response
+
+ except Exception, e:
+ LOG.exception("Exception in DownloadPSForm.")
+ messages.error(request, _('Error Downloading PS File: %s') % e)
+ return shortcuts.redirect(request.build_absolute_uri())
--- a/openstack_dashboard/settings.py 2013-11-29 15:28:03.000000000 +0100
+++ b/openstack_dashboard/settings.py 2013-11-29 15:28:12.000000000 +0100
@@ -53,6 +53,7 @@
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.abspath(os.path.join(ROOT_PATH, '..', 'static'))
STATIC_URL = '/static/'
+CACHAIN_URL = '/static/ca.pem'
ROOT_URLCONF = 'openstack_dashboard.urls'
diff --git a/openstack_dashboard/dashboards/project/access_and_security/templates/access_and_security/api_access/openstack.ps.template b/openstack_dashboard/dashboards/project/access_and_security/templates/access_and_security/api_access/openstack.ps.template
new file mode 100644
index 0000000..b7f8545
--- /dev/null
+++ b/openstack_dashboard/dashboards/project/access_and_security/templates/access_and_security/api_access/openstack.ps.template
@@ -0,0 +1,29 @@
+# With the addition of Keystone, to use an openstack cloud you should
+# authenticate against keystone, which returns a **Token** and **Service
+# Catalog**. The catalog contains the endpoint for all services the
+# user/tenant has access to - including nova, glance, keystone, swift.
+#
+# *NOTE*: Using the 2.0 *auth api* does not mean that compute api is 2.0. We
+# will use the 1.1 *compute api*
+$env:OS_AUTH_URL="{{ auth_url }}"
+
+# With the addition of Keystone we have standardized on the term **tenant**
+# as the entity that owns the resources.
+$env:OS_TENANT_ID="{{ tenant_id }}"
+$env:OS_TENANT_NAME="{{ tenant_name }}"
+
+# CERN SSL Validation CA Chain
+$PSScriptRoot = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition
+$env:OS_CACERT = Join-Path $PSScriptRoot "ca.pem"
+if (-not $(Test-Path $env:OS_CACERT)) {
+ $wc = New-Object System.Net.Webclient
+ $wc.DownloadFile('{{ cachain_url }}', $env:OS_CACERT)
+}
+
+# In addition to the owning entity (tenant), openstack stores the entity
+# performing the action as the **user**.
+$env:OS_USERNAME="{{ user.username }}"
+
+# With Keystone you pass the keystone password.
+$Password = Read-Host -assecurestring "Please enter your OpenStack password"
+$env:OS_PASSWORD = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password))