+ if getattr(settings, 'SWIFT_SHOW_RADOSGW_KEYS', False):
+ table_actions = (ShowKeys, CreateContainer, DeleteContainer)
+ else:
+ table_actions = (CreateContainer, DeleteContainer)
2. /horizon/dashboards/nova/containers/urls.py
Django MVC 中的 controller 設定檔,呼叫 ShowKey 的 action。
+ url(r'^show/$', ShowKeysView.as_view(), name='show_keys'),
3. /horizon/dashboards/nova/templates/nova/containers/_showkeys.html
Django MVC 中的 view,設定 ShowKey 的左邊是一個表格,右邊為說明文字。
+<div class="left">
+ <fieldset>
+ {% include "horizon/common/_form_fields.html" %}
+ </fieldset>
+</div>
+<div class="right">
+ <h3>{% trans "Description" %}:</h3>
2
新版的 OpenStack Folsom Swift 也提供了 swift3 middleware 來讓 Swift 對外提供相容於 Amazon S3 API 的物件儲存服務。
3
一種使用 FUSE 開發的檔案系統。可以使用 Amazon S3 協定來將遠端的 S3 服務掛載到本機資料夾,
任何對該資料夾的讀寫操作即會反映到遠端的伺服器上,類似現在流行的 Dropbox 服務。
+ <p>{% trans "We also support the Amazon ® AWS S3 com-patible service. If you want to try a fresh, the Access Key & Se-cret Key are shown in the left side. Moreover, you can also mount a bucket as lo-cal drive by Gladinet ® or other clients use S3 API. Notice! Dash-board still *NOT* support directory in bucket, so you can't see the files in di-rectory which is uploaded from S3 API." %}</p>
+</div>
+{% endblock %}
+
+{% block modal-footer %}
+ <a href="{% url horizon:nova:containers:index %}" class="btn btn-primary pull-right">{% trans "Back" %}</a>
+{% endblock %}
4. /horizon/dashboards/nova/containers/forms.py
View 的左半部用表單的方式呈現,因此需在這邊定義有哪些欄位。
+class ShowKeys(forms.SelfHandlingForm):
+ def __init__(self, *args, **kwargs):
+ helpStr = "Ctrl+C Copy to Clipboard"
+ self.fields['apoint'] = forms.CharField(
+ initial=accessPoint, label='Access Point', help_text=helpStr) + self.fields['access'] = forms.CharField(
+ initial=user["keys"][0]["access_key"], + label='Access Key ID', help_text=helpStr) + self.fields['secret'] = forms.CharField(
+ initial=user["keys"][0]["secret_key"].replace('\\',''), + label='Secret key', help_text=helpStr)
+ self.fields['apoint'].widget.attrs['onClick'] = \ + self.fields['access'].widget.attrs['onClick'] = \ + self.fields['secret'].widget.attrs['onClick'] = \ + 'Javascript:this.focus();this.select();'
5. /horizon/locale/zh_TW/LC_MESSAGES/django.po
Django 的多語系支援,撰寫關於 ShowKey 的繁體中文說明文件。
+msgstr ""
件 (如"buck1/file1")。
但不幸的是,目前版本 (Essex 穩定分支) 的 Dashboard 還不支援顯示 bucket/container 內的資料夾,因此這邊針對名稱裡有斜線的物件暫時先過濾掉不顯示在 Dashboard 上,
讓 Dashboard 只能顯示容器內第一層的所有物件,但並不會影響到其他使用 S3 服務的
+ return s[u'name'].find('/') == -1 +
+def swift_filter_names(s):
+ return s.find('/') == -1
def swift_get_objects(request, container_name, prefix=None, marker=None):
objects = container.get_objects(prefix=prefix, marker=marker, limit=limit + 1)
+ # This branch doesn't support to show objects which have
+ # '/' in their names now (object is a directory or files in directorys) + # but ceph rados supports that, so the objects may be upload to
+ # container by s3 api. Therefore, just filter out objects like that.
+ objects._objects = filter(swift_filter_objects, objects._objects) + objects._names = filter(swift_filter_names, objects._names)
規格列表的內容修正
一般 Dashboard 預設的虛擬機規格 (flavor) 是只有 m1.tiny 的主磁碟為 0GB,其他規 格為 10GB,但是在啟動新虛擬機時的規格檢查,0GB 其實是不檢查,就是可以開啟任
在使用者要啟動虛擬機時,改成顯示暫用 (ephemeral) 磁碟大小供使用者選擇。
class LaunchView(forms.ModalFormView):
flavors = api.flavor_list(self.request) flavor_list = [(flavor.id, display % {
"name": flavor.name,
"vcpus": flavor.vcpus, - "disk": flavor.disk,
+ "disk": getattr(flavor, "OS-FLV-EXT-DATA:ephemeral"),
"ram": flavor.ram})
2. /horizon/dashboards/nova/instances_and_volumes/instances/tables.py
將" 執行個體 & 容量" 的首頁改成顯示暫用磁碟的大小,方便使用者掌握專案的空 間使用情形。
def get_size(instance):
if hasattr(instance, "full_flavor"):
- size_string = _("%(RAM)s RAM | %(VCPU)s VCPU | %(disk)s Disk") + size_string = _("%(RAM)s RAM | %(VCPU)s VCPU | %(disk)s Disk(vdb)")
vals = {'RAM': sizeformat.mbformat(instance.full_flavor.ram), 'VCPU': instance.full_flavor.vcpus,
- 'disk': sizeformat.diskgbformat(instance.full_flavor.disk)}
+ 'disk': sizeformat.diskgbformat(
+ getattr(instance.full_flavor, 'OS-FLV-EXT-DATA:ephemeral'))}
return size_string % vals return _("Not available")
專案的配額與已使用空間的顯示
+ containers = swift_api(request).get_all_containers(10000,None) + except Exception:
+ containers = None + for container in containers:
+ size += container.size_used + return size
2. /horizon/api/nova.py
再來將該專案的磁碟使用量 (gigabytes) 改成計算暫用磁碟以及物件儲存的部分。
def tenant_quota_usages(request):
usages = {'instances': {'flavor_fields': [], 'used': len(instances)}, 'cores': {'flavor_fields': ['vcpus'], 'used': 0},
- 'gigabytes': {'used': 0,
- 'flavor_fields': [
- 'disk',
- 'OS-FLV-EXT-DATA:ephemeral']},
+ 'gigabytes': {'used':
+ swift_get_total_size(request)/1024/1024/1024,
+ 'flavor_fields': ['OS-FLV-EXT-DATA:ephemeral']},
'ram': {'flavor_fields': ['ram'], 'used': 0},
'floating_ips': {'flavor_fields': [], 'used': len(floating_ips)}}
3. /horizon/dashboards/nova/images_and_snapshots/images/views.py
在啟動新虛擬機的過程中判斷是否有任何的使用量超過原先的配額,有的話將標 示為不允許啟動。
class LaunchView(forms.ModalFormView):
try:
context['usages'] = api.tenant_quota_usages(self.request) + for usage in context['usages']:
+ if usage != "floating_ips" and context['usages'][usage]['available'] <= 0:
+ context['usages']['disabled'] = 'disabled=disabled'
+ break
+ context['usages'].setdefault('disabled', '') except:
- <strong>{% trans "Disk" %}
- <span>({{ usages.gigabytes.used }} {% trans "GB" %})</span>
- </strong>
+ <strong>{% trans "Disk" %}+{% trans "Containers" %}
+ <span>({{ usages.gigabytes.used }} {% trans "GB" %})</span>
+ </strong>
<p>{{ usages.gigabytes.available|quota:"GB" }}</p>
</div>
...
{% block modal-footer %}
- <input class="btn btn-primary pull-right"
- type="submit" value="{% trans "Launch Instance" %}" />
+ <input class="btn btn-primary pull-right" {{ usages.disabled }}
+ type="submit" value="{% trans "Launch Instance" %}" />
{% endblock %}