def _execute_reqest(self, method, **kw): log.debug("[XSP] execute %s(%s)" % (method, kw)) xsi = tools.create_xsi_tool_for_account( self.ds.get_server(), self.ds.get_user_data()) try: func = getattr(xsi, method) args = [] _kwargs = False for a in self.REQUESTS[method].arguments: if a.type == 'bool': self.ds.set_user_prop(a.name, {"checked" : "on" if kw.get(a.name) else "off"}) kw[a.name] = bool(kw.get(a.name) and kw[a.name] in ['on']) else: assert a.name in kw, "missing argument %s" % a.name self.ds.set_user_prop(a.name, utils.xml_string(kw[a.name])) if a.encode: kw[a.name] = base64.b64encode(kw[a.name]) if a.optional and kw[a.name] == '': kw[a.name] = a.value if a.pos > -1: args.insert(a.pos, kw[a.name]) else: _kwargs = True log.info("[XSP] call %s with %s and %s" % (method, args, kw)) res = func(*args, **kw) if _kwargs else func(*args) except AttributeError as ae: flash('Please set xsi user settings', 'error') except AssertionError as ae: flash('XSI call failed: %s' % ae, 'error') self.base_dict["output"] = "%s" % ae return self.base_dict self.base_dict["output"] = "%s" % utils.xml_string(res) return self.base_dict
def _execute_reqest(self, method, **kw): oci = tools.create_oci_tool(username=self.sc.get_admin_username(), password=self.sc.get_admin_password(), server=self.sc.get_server()) try: func = getattr(oci, method) args = [] _kwargs = False for a in self.REQUESTS[method].arguments: if a.type == 'bool': self.sc.set_user_prop( a.name, {"checked": "on" if kw.get(a.name) else "off"}) kw[a.name] = bool(kw.get(a.name) and kw[a.name] in ['on']) else: assert a.name in kw, "missing argument %s" % a.name self.sc.set_user_prop(a.name, utils.xml_string(kw[a.name])) if a.encode: kw[a.name] = base64.b64encode(kw[a.name]) if a.optional and kw[a.name] == '': kw[a.name] = a.value if a.pos > -1: args.insert(a.pos, kw[a.name]) else: _kwargs = True log.info("Call %s with %s and %s" % (method, args, kw)) res = func(*args, **kw) if _kwargs else func(*args) except AttributeError as ae: flash('Please set xsi user settings', 'error') except AssertionError as ae: flash('OCI call failed: %s' % ae, 'error') self.base_dict["output"] = "%s" % ae return self.base_dict self.base_dict["output"] = "OCI Command: \n%s\n" \ "OCI Response:\n%s\n" % (oci.oci_command, utils.xml_string(res)) return self.base_dict
def get_user_prop(self, name, default=''): if name in ["deviceName", "fileContent" ] and name not in self.user_data.keys(): try: xsi = tools.create_xsi_tool_for_account( DBSession.query(Setting).filter_by( name="oci_root").one().value, self.user_data) if name == "deviceName": self.user_data["deviceName"] = xsi.get_device_name_by_type( self.get_device_type()) if name == "fileContent": self.user_data["fileContent"] = utils.xml_string( xsi.get_dm_config(deviceType=self.get_device_type())) except Exception as e: log.error("failed to get '%s'. %s" % (name, e)) return self.user_data.get(name, default)
def get_user_prop(self, name, default=''): log.debug("[DataStorage] get_user_prop %s default='%s'" % (name, default)) user_data = request.identity["userdata"] if name in ["deviceName", "fileContent" ] and name not in user_data.keys(): try: xsi = tools.create_xsi_tool_for_account( user_data["server"], user_data) if name == "deviceName": user_data["deviceName"] = xsi.get_device_name_by_type( self.get_device_type()) if name == "fileContent": user_data["fileContent"] = utils.xml_string( xsi.get_dm_config(deviceType=self.get_device_type())) except Exception as e: log.error("[DataStorage] failed to get '%s'. %s" % (name, e)) log.debug("[DataStorage] get_user_prop return %s" % user_data.get(name, default)) return user_data.get(name, default)