def get(self, farm_id: int = None, farm_name: str = None) -> Farm: """ get the detail of a farm :param farm_id: ID of the farm to retrieve :type farm_id: int, optional :param farm_name: Name of the farm to retrieve, if you use name the client loops over all farm and match on the name. Be carefull using this in performance critical code path :type farm_name: str, optional :raises NotFound: if no farm with the specified ID or name if found :raises Input: if farm_id and farm_name are None :return: Farm object :rtype: Farm """ if farm_name: for farm in self.iter(): if farm.name == farm_name: return farm else: raise NotFound(f"Could not find farm with name {farm_name}") elif not farm_id: raise Input("farms.get requires at least farm_id or farm_name") resp = self._session.get(f"{self._url}/{farm_id}") return Farm.from_dict(resp.json())
def setUpClass(cls): if not j.sals.process.is_installed("restic"): raise NotFound(f"restic not installed") # configure the main directory to run all tests cls.main_dir = tempfile.TemporaryDirectory() cls.info( f"The main temp directory created successfully with path {cls.main_dir.name}" ) # create two restic clients to use in all tests cls.restic_client_names = [ f"{cls.random_name()}_client1", f"{cls.random_name()}_client2" ] cls._create_restic_repos() cls.info( f"The random restic test clients created successfully with names: {cls.restic_client_names}" )
def nodes_search(self, farm_id=None, country=None, city=None, cru=None, sru=None, mru=None, hru=None, farm_name=None): """ Args: farm_id: (Default value = None) country: (Default value = None) city: (Default value = None) cru: (Default value = None) sru: (Default value = None) mru: (Default value = None) hru: (Default value = None) farm_name: (Default value = None) Returns: """ if farm_name: farms = self._farms.list(name=farm_name) if len(farms) != 1: raise NotFound(f"Could not find farm with name {farm_name}") farm_id = farms[0].id return self._nodes.list(farm_id=farm_id, country=country, city=city, cru=cru, sru=sru, mru=mru, hru=hru)
def _check_install(self, binary): if subprocess.call(["which", binary], stdout=subprocess.DEVNULL): raise NotFound(f"{binary} not installed")
def setUpClass(cls): if not j.sals.process.is_installed("restic"): raise NotFound(f"restic not installed")