Beispiel #1
0
 def handle(self, request, data):
     #
     data_values = data
     nodes = data["nodes"]
     del data["nodes"]
     #
     # Create Storage group
     try:
         resp = api.create_storagegroup(self.request, data)
         if 200 <= resp.status_code < 300:
             data = resp.json()
         else:
             error_message = "Unable to create group"
             raise ValueError(resp.text)
     except Exception as e:
         strobj = "[]"
         exceptions.handle(self.request, _(e.message))
     #
     # Assign storage nodes to storage group
     groupid = data["id"]
     groupid = str(groupid)
     count = 0
     for node in nodes:
         count = count + 1
         try:
             resp = api.associate_group_node(self.request, groupid, node)
             if 200 <= resp.status_code < 300:
                 pass
             else:
                 error_message = "Unable to associate group and storage node"
                 raise ValueError(resp.text)
         except Exception as e:
             strobj = "[]"
             exceptions.handle(self.request, _(e.message))
     #
     # Create Volume type
     try:
         # Remove any new lines in the public key
         volume_type = cinder.volume_type_create(request, data["name"])
         messages.success(request, _("Successfully created volume type: %s") % data["name"])
     except Exception as e:
         if getattr(e, "code", None) == 409:
             msg = _('Volume type name "%s" already ' "exists.") % data["name"]
             self._errors["name"] = self.error_class([msg])
         else:
             exceptions.handle(self.request, _("Unable to create volume type."))
     #
     # Creating extra specs
     dspecs = {}
     dspecs["key"] = "sds:storage_group_id"
     dspecs["value"] = groupid
     type_id = volume_type.id
     try:
         cinder.volume_type_extra_set(request, type_id, {dspecs["key"]: dspecs["value"]})
         msg = _('Created extra spec "%s".') % dspecs["key"]
         messages.success(request, msg)
     except Exception:
         exceptions.handle(request, _("Unable to create volume type extra spec."), redirect=redirect)
     return data_values
Beispiel #2
0
 def handle(self, request, data):
     #
     data_values = data
     nodes = data["nodes"]
     del data["nodes"]
     groupid = data["id"]
     groupid = str(groupid)
     #
     # Update Storage Group (Nodes can only be updated apart from other data at the moment)
     try:
         resp = api.update_storagegroup(self.request, groupid, data)
         if 200 <= resp.status_code < 300:
             data = resp.json()
         else:
             error_message = "Unable to update Storage Group"
             raise ValueError(resp.text)
     except Exception as e:
         strobj = "[]"
         exceptions.handle(self.request, _(e.message))
     #
     # Retrieve storage node list for the selected group
     data_nodes = []
     try:
         resp = api.list_groups_nodes(self.request, groupid)
         if resp.status_code == 200:
             data_nodes = resp.json()
         else:
             error_message = "Unable to retrieve Storage Nodes information."
             raise ValueError(error_message)
     except Exception as e:
         strobj = "[]"
         exceptions.handle(self.request, _(e.message))
     #
     # Disassociate storage nodes associated with the selected storage group
     count = 0
     for d in data_nodes:
         nodeid = d["id"]
         nodeid = str(nodeid)
         try:
             resp = api.disassociate_group_node(self.request, groupid, nodeid)
             if 200 <= resp.status_code < 300:
                 pass
             else:
                 error_message = "Unable to disassociate group and storage node"
                 raise ValueError(resp.text)
         except Exception as e:
             strobj = "[]"
             exceptions.handle(self.request, _(e.message))
     #
     # Assign storage nodes to storage group
     count = 0
     for node in nodes:
         count = count + 1
         try:
             resp = api.associate_group_node(self.request, groupid, node)
             if 200 <= resp.status_code < 300:
                 pass
             else:
                 error_message = "Unable to associate group and storage node"
                 raise ValueError(resp.text)
         except Exception as e:
             strobj = "[]"
             exceptions.handle(self.request, _(e.message))
     return data_values