Esempio n. 1
0
    def __init__(self,
                 host='127.0.0.1',
                 port=4646,
                 timeout=5,
                 region=None,
                 version='v1',
                 verify=False,
                 cert=()):
        self.host = host
        self.port = port
        self.timeout = timeout
        self.version = version
        self.verify = verify
        self.cert = cert

        self.requester = api.Requester(host, port, timeout, version, verify,
                                       cert)

        self._jobs = api.Jobs(self.requester)
        self._job = api.Job(self.requester)
        self._nodes = api.Nodes(self.requester)
        self._node = api.Node(self.requester)
        self._allocations = api.Allocations(self.requester)
        self._allocation = api.Allocation(self.requester)
        self._evaluations = api.Evaluations(self.requester)
        self._evaluation = api.Evaluation(self.requester)
        self._agent = api.Agent(self.requester)
        self._client = api.Client(self.requester)
        self._deployments = api.Deployments(self.requester)
        self._deployment = api.Deployment(self.requester)
        self._regions = api.Regions(self.requester)
        self._status = api.Status(self.requester)
        self._system = api.System(self.requester)
        self._operator = api.Operator(self.requester)
        self._validate = api.Validate(self.requester)
Esempio n. 2
0
    def __init__(self, host='127.0.0.1', secure=False, port=4646, namespace=None,
        token=None, timeout=5, region=None, version='v1', verify=False, cert=()):
        """ Nomad api client

          https://github.com/jrxFive/python-nomad/

           optional arguments:
            - host (defaults 127.0.0.1), string ip or name of the nomad api server/agent that will be used.
            - port (defaults 4646), integer port that will be used to connect.
            - secure (defaults False), define if the protocol is secured or not (https or http)
            - version (defaults v1), vesion of the api of nomad.
            - verify (defaults False), verify the certificate when tls/ssl is enabled
                                at nomad.
            - cert (defaults empty), cert, or key and cert file to validate the certificate
                                configured at nomad.
            - region (defaults None), version of the region to use. It will be used then
                                regions of the current agent of the connection.
            - namespace (defaults to None), Specifies the enterpise namespace that will
                                be use to deploy or to ask info to nomad.
            - token (defaults to None), Specifies to append ACL token to the headers to
                                make authentication on secured based nomad environemnts.
           returns: Nomad api client object

           raises:
             - nomad.api.exceptions.BaseNomadException
             - nomad.api.exceptions.URLNotFoundNomadException
             - nomad.api.exceptions.URLNotAuthorizedNomadException
        """
        self.host = host
        self.secure = secure
        self.port = port
        self.timeout = timeout
        self.version = version
        self.verify = verify
        self.cert = cert

        self.requester = api.Requester(self.get_uri(), port, namespace, token,
                                       timeout, version, verify, cert)

        self._jobs = api.Jobs(self.requester)
        self._job = api.Job(self.requester)
        self._nodes = api.Nodes(self.requester)
        self._node = api.Node(self.requester)
        self._allocations = api.Allocations(self.requester)
        self._allocation = api.Allocation(self.requester)
        self._evaluations = api.Evaluations(self.requester)
        self._evaluation = api.Evaluation(self.requester)
        self._agent = api.Agent(self.requester)
        self._client = api.Client(self.requester)
        self._deployments = api.Deployments(self.requester)
        self._deployment = api.Deployment(self.requester)
        self._regions = api.Regions(self.requester)
        self._status = api.Status(self.requester)
        self._system = api.System(self.requester)
        self._operator = api.Operator(self.requester)
        self._validate = api.Validate(self.requester)
        self._namespaces = api.Namespaces(self.requester)
        self._namespace = api.Namespace(self.requester)
        self._acl = api.Acl(self.requester)
        self._sentinel = api.Sentinel(self.requester)
Esempio n. 3
0
    def __init__(self,
                 host='127.0.0.1',
                 secure=False,
                 port=4646,
                 address=os.getenv('NOMAD_ADDR', None),
                 namespace=os.getenv('NOMAD_NAMESPACE', None),
                 token=os.getenv('NOMAD_TOKEN', None),
                 vaulttoken=os.getenv('VAULT_TOKEN', None),
                 timeout=5,
                 region=os.getenv('NOMAD_REGION', None),
                 version='v1',
                 verify=False,
                 cert=()):
        """ Nomad api client

          https://github.com/jrxFive/python-nomad/

           optional arguments:
            - host (defaults 127.0.0.1), string ip or name of the nomad api server/agent that will be used.
            - port (defaults 4646), integer port that will be used to connect.
            - secure (defaults False), define if the protocol is secured or not (https or http)
            - version (defaults v1), vesion of the api of nomad.
            - verify (defaults False), verify the certificate when tls/ssl is enabled
                                at nomad.
            - cert (defaults empty), cert, or key and cert file to validate the certificate
                                configured at nomad.
            - region (defaults None), version of the region to use. It will be used then
                                regions of the current agent of the connection.
            - namespace (defaults to None), Specifies the enterpise namespace that will
                                be use to deploy or to ask info to nomad.
            - token (defaults to None), Specifies to append ACL token to the headers to
                                make authentication on secured based nomad environemnts.
            - vaulttoken (defaults to None), Specifies to append ACL token to the job and
                                make authentication on environemnts with allow_unantenticated = false, where
                                you must to send a valid vault token for policies.
           returns: Nomad api client object

           raises:
             - nomad.api.exceptions.BaseNomadException
             - nomad.api.exceptions.URLNotFoundNomadException
             - nomad.api.exceptions.URLNotAuthorizedNomadException
        """
        self.host = host
        self.secure = secure
        self.port = port
        self.address = address
        self.region = region
        self.timeout = timeout
        self.version = version
        self.token = token
        self.vaulttoken = vaulttoken
        self.verify = verify
        self.cert = cert
        self.__namespace = namespace

        self.requester_settings = {
            "address": self.address,
            "uri": self.get_uri(),
            "port": self.port,
            "namespace": self.__namespace,
            "token": self.token,
            "vaulttoken": self.vaulttoken,
            "timeout": self.timeout,
            "version": self.version,
            "verify": self.verify,
            "cert": self.cert,
            "region": self.region
        }

        self._jobs = api.Jobs(**self.requester_settings)
        self._job = api.Job(**self.requester_settings)
        self._nodes = api.Nodes(**self.requester_settings)
        self._node = api.Node(**self.requester_settings)
        self._allocations = api.Allocations(**self.requester_settings)
        self._allocation = api.Allocation(**self.requester_settings)
        self._evaluations = api.Evaluations(**self.requester_settings)
        self._evaluation = api.Evaluation(**self.requester_settings)
        self._agent = api.Agent(**self.requester_settings)
        self._client = api.Client(**self.requester_settings)
        self._deployments = api.Deployments(**self.requester_settings)
        self._deployment = api.Deployment(**self.requester_settings)
        self._regions = api.Regions(**self.requester_settings)
        self._status = api.Status(**self.requester_settings)
        self._system = api.System(**self.requester_settings)
        self._operator = api.Operator(**self.requester_settings)
        self._validate = api.Validate(**self.requester_settings)
        self._namespaces = api.Namespaces(**self.requester_settings)
        self._namespace = api.Namespace(**self.requester_settings)
        self._acl = api.Acl(**self.requester_settings)
        self._sentinel = api.Sentinel(**self.requester_settings)
        self._metrics = api.Metrics(**self.requester_settings)