def create_volume(sys_id, vol_name, pool_name=None): """Issue a request to define a new volume :param sys_id: the unique identifier of the system :param vol_name: the name of the new volume :param pool_name: an optional pool name """ con = get_session() pool = get_pool_by_name(con, sys_id, pool_name) if pool is None: LOG.error('Unable to locate a valid pool to use!') raise NameError('No such pool!') LOG.info("Defining a volume on [%s] with name [%s] in pool [%s]." % (sys_id, vol_name, pool['name'])) data = {'name': vol_name, 'size': '1', 'poolId': pool['id']} result = con.post('http://{server}/devmgr/v2/storage-systems/{id}/volumes'.format( server=props.server, id=sys_id), data=json.dumps(data)) if result.status_code == 422: resp = result.json() LOG.warn("Volume creation failed: %s" % resp.get('errorMessage')) elif result.status_code == 200: LOG.info("Volume [%s] created successfully" % vol_name) LOG.debug(pformat(result.json())) else: LOG.error(result.text) result.raise_for_status()
def update_user(self, username, password, email=None): update_dict = {'password': password} if email: update_dict['email'] = email session = get_session() query = session.query(user_model.User).filter_by(name=username) query.update(update_dict) session.commit()
def get_user(self, username): query = get_session().query(user_model.User).filter_by(name=username) try: return query.one() except exc.NoResultFound: pass return None
def create_user(self, username, password, email=None): session = get_session() user = user_model.User() user.name = username user.password = password if email: user.email = email session.add(user) session.commit()
def add_company(companyinfo): try: session = get_session() model_company = convert_model("Company", companyinfo) session.add(model_company) session.commit() return True except Exception as ex: raise ex finally: session.close()
def add_user(admin_userinfo): try: session = get_session() model_user = convert_model("User", admin_userinfo) session.add(model_user) session.commit() return True except Exception as ex: raise ex finally: session.close()
def add_game_code(game_cod): """ :param userinfo: 字典,key必须和models.User匹配 :return: """ session = get_session() try: _ = verify_code(session, game_cod) if _ != 0: return False model_user = convert_model("GameCode", {"store_game_code": game_cod}) session.add(model_user) session.commit() return True except Exception as ex: return False finally: session.close()
def trigger_auto_support_bundle(operation_type, dispatch_type): # Get a connection connection = get_session() # Setup the request body with the desired operation and dispatch types # The operation type determines whether the bundle will be collected and availble # for local retrieval or if the bundle will be dispatched to the AutoSupport # backend server. The dispatch type indicates what type of bundle will be collected. # Refer to the Webservices API documentation for further information. request_data = { 'operationType': operation_type, 'dispatchType': dispatch_type } response_data = None try: LOG.info("Triggering an AutoSupport bundle with an operation type of [%s] and a dispatch type of [%s]." % (operation_type, dispatch_type)) result = connection.post('http://{server}/devmgr/v2/auto-support'.format(server=PROPS.server), data=json.dumps(request_data)) try: result.raise_for_status() LOG.info("Trigger AutoSupport bundle attempt succeeded") response_data = result.json() except requests.HTTPError as e: LOG.error("Trigger AutoSupport bundle attempt failed || http status code: %s" % str(e.response.status_code)) raise LOG.info("Retrieving job data for %s." % (response_data['jobId'])) result = connection.get('http://{server}/devmgr/v2/auto-support/jobs/{id}'.format(server=PROPS.server, id=response_data['jobId'])) try: result.raise_for_status() response_data = result.json() LOG.info("AutoSupport job retrieval request succeeded") LOG.info("Job data:\n%s" % str(response_data)) except requests.HTTPError as e: LOG.error("AutoSupport job retrieval request failed || http status code: %s" % str(e.response.status_code)) raise except Exception as e: LOG.error("Server connection failure") raise
def delete_user(self, username): session = get_session() session.query(user_model.User).filter_by(name=username).delete() session.commit()
def list_users(self): session = get_session() query = session.query(user_model.User) users = query.all() return users