コード例 #1
0
ファイル: tags.py プロジェクト: ocni-dtu/maas
def evaluate_tag(
    system_id,
    nodes,
    tag_name,
    tag_definition,
    tag_nsmap,
    credentials,
    maas_url,
):
    """Evaluate `tag_definition` against this cluster's nodes' details.

    :param system_id: System ID for the rack controller.
    :param nodes: List of nodes to evaluate.
    :param tag_name: The name of the tag, used for logging.
    :param tag_definition: The XPath expression of the tag.
    :param tag_nsmap: The namespace map as used by LXML's ETree library.
    :param credentials: A 3-tuple of OAuth credentials.
    :param maas_url: URL of the MAAS API.
    """
    client = MAASClient(
        auth=MAASOAuth(*credentials),
        dispatcher=MAASDispatcher(),
        base_url=maas_url,
    )
    process_node_tags(
        rack_id=system_id,
        nodes=nodes,
        tag_name=tag_name,
        tag_definition=tag_definition,
        tag_nsmap=tag_nsmap,
        client=client,
    )
コード例 #2
0
ファイル: boot_images.py プロジェクト: cloudbase/maas
def submit(maas_url, api_credentials, images):
    """Submit images to server."""
    MAASClient(MAASOAuth(*api_credentials), MAASDispatcher(),
               maas_url).post('api/1.0/boot-images/',
                              'report_boot_images',
                              nodegroup=get_cluster_uuid(),
                              images=json.dumps(images))
コード例 #3
0
def evaluate_tag(
    system_id,
    nodes,
    tag_name,
    tag_definition,
    tag_nsmap,
    credentials,
    maas_url,
):
    """Evaluate `tag_definition` against this cluster's nodes' details.

    :param system_id: System ID for the rack controller.
    :param nodes: List of nodes to evaluate.
    :param tag_name: The name of the tag, used for logging.
    :param tag_definition: The XPath expression of the tag.
    :param tag_nsmap: The namespace map as used by LXML's ETree library.
    :param credentials: A 3-tuple of OAuth credentials.
    :param maas_url: URL of the MAAS API.
    """
    # Turn off proxy detection, since the rack should talk directly to
    # the region, even if a system-wide proxy is configured.
    client = MAASClient(
        auth=MAASOAuth(*credentials),
        dispatcher=MAASDispatcher(autodetect_proxies=False),
        base_url=maas_url,
    )
    process_node_tags(
        rack_id=system_id,
        nodes=nodes,
        tag_name=tag_name,
        tag_definition=tag_definition,
        tag_nsmap=tag_nsmap,
        client=client,
    )
コード例 #4
0
ファイル: test_maas_client.py プロジェクト: cloudbase/maas
def make_client(root=None, result=None):
    """Create a MAASClient."""
    if root is None:
        root = make_url()
    auth = MAASOAuth(factory.getRandomString(), factory.getRandomString(),
                     factory.getRandomString())
    return MAASClient(auth, FakeDispatcher(result=result), root)
コード例 #5
0
def make_client(root=None, result=None):
    """Create a MAASClient."""
    if root is None:
        root = factory.make_simple_http_url(path=factory.make_name("path") +
                                            "/")
    auth = MAASOAuth(factory.make_string(), factory.make_string(),
                     factory.make_string())
    return MAASClient(auth, FakeDispatcher(result=result), root)
コード例 #6
0
 def __init__(self, api_key=None, url=maas_url):
     if api_key == None:
         self.api_key = self.get_api_key()
     else:
         self.api_key = api_key
     self.auth = MAASOAuth(*self.api_key.split(':'))
     self.url = url
     self.client = MAASClient(self.auth, MAASDispatcher(), self.url)
コード例 #7
0
ファイル: detect.py プロジェクト: cloudbase/maas
def update_region_controller(knowledge, interface, server):
    """Update the region controller with the status of the probe.

    :param knowledge: dictionary of server info
    :param interface: name of interface, e.g. eth0
    :param server: IP address of detected DHCP server, or None
    """
    api_path = 'api/1.0/nodegroups/%s/interfaces/%s/' % (
        knowledge['nodegroup_uuid'], interface)
    oauth = MAASOAuth(*knowledge['api_credentials'])
    client = MAASClient(oauth, MAASDispatcher(), knowledge['maas_url'])
    if server is None:
        server = ''
    process_request(client.put, api_path, foreign_dhcp_ip=server)
コード例 #8
0
def create_node(mac, arch, power_type, power_parameters):
    api_credentials = get_recorded_api_credentials()
    if api_credentials is None:
        raise Exception('Not creating node: no API key yet.')
    client = MAASClient(MAASOAuth(*api_credentials), MAASDispatcher(),
                        get_maas_url())

    data = {
        'op': 'new',
        'architecture': arch,
        'power_type': power_type,
        'power_parameters': power_parameters,
        'mac_addresses': mac
    }
    return client.post('/api/1.0/nodes/', data)
コード例 #9
0
def get_cached_knowledge():
    """Get all the information that we need to know, or raise an error.

    :return: (client, nodegroup_uuid)
    """
    api_credentials = get_recorded_api_credentials()
    if api_credentials is None:
        logger.error("Not updating tags: don't have API key yet.")
        return None, None
    nodegroup_uuid = get_recorded_nodegroup_uuid()
    if nodegroup_uuid is None:
        logger.error("Not updating tags: don't have UUID yet.")
        return None, None
    client = MAASClient(MAASOAuth(*api_credentials), MAASDispatcher(),
                        get_maas_url())
    return client, nodegroup_uuid
コード例 #10
0
def _getclient(url=u'http://localhost/MAAS/api/1.0/'):
    '''
  Use the MAAS apiclient to aquire a session with the Maas API
  :param url:
    How to connect to the Maas server. As we require the Maas tools
    installed on the executing machine, this can be the localhost by default.

  :return:
    A MAASClient object
  '''
    global _mclient
    if _mclient is None:
        consumer_key, token, secret = key('root').split(':', 3)
        auth = MAASOAuth(consumer_key, token, secret)
        dispatch = MAASDispatcher()
        _mclient = MAASClient(auth, dispatch, url)

    return _mclient
コード例 #11
0
ファイル: detect.py プロジェクト: cloudbase/maas
def determine_cluster_interfaces(knowledge):
    """Given server knowledge, determine network interfaces on this cluster.

    :return: a list of tuples of (interface name, ip) for all interfaces.

    :note: this uses an API call and not local probing because the
        region controller has the definitive and final say in what does and
        doesn't exist.
    """
    api_path = 'api/1.0/nodegroups/%s/interfaces' % knowledge['nodegroup_uuid']
    oauth = MAASOAuth(*knowledge['api_credentials'])
    client = MAASClient(oauth, MAASDispatcher(), knowledge['maas_url'])
    interfaces = process_request(client.get, api_path, 'list')
    if interfaces is None:
        return None

    interface_names = sorted((interface['interface'], interface['ip'])
                             for interface in interfaces
                             if interface['interface'] != '')
    return interface_names
コード例 #12
0
ファイル: leases.py プロジェクト: cloudbase/maas
def send_leases(leases):
    """Send lease updates to the server API."""
    # Items that the server must have sent us before we can do this.
    knowledge = {
        'maas_url': get_maas_url(),
        'api_credentials': get_recorded_api_credentials(),
        'nodegroup_uuid': get_recorded_nodegroup_uuid(),
    }
    if None in knowledge.values():
        # The MAAS server hasn't sent us enough information for us to do
        # this yet.  Leave it for another time.
        logger.info(
            "Not sending DHCP leases to server: not all required knowledge "
            "received from server yet.  "
            "Missing: %s" % ', '.join(list_missing_items(knowledge)))
        return

    api_path = 'api/1.0/nodegroups/%s/' % knowledge['nodegroup_uuid']
    oauth = MAASOAuth(*knowledge['api_credentials'])
    MAASClient(oauth, MAASDispatcher(),
               knowledge['maas_url']).post(api_path,
                                           'update_leases',
                                           leases=json.dumps(leases))
コード例 #13
0
def _auth(**connection_args):
    '''
    Set up maas credentials

    Only intended to be used within maas-enabled modules
    '''

    prefix = "maas."

    # look in connection_args first, then default to config file
    def get(key, default=None):
        return connection_args.get(
            'connection_' + key, __salt__['config.get'](prefix + key, default))

    api_token = get('token')
    api_url = get('url', 'https://localhost/')

    LOG.debug("MAAS url: " + api_url)
    LOG.debug("MAAS token: " + api_token)
    auth = MAASOAuth(*api_token.split(":"))
    dispatcher = MAASDispatcher()
    client = MAASClient(auth, dispatcher, api_url)

    return client
コード例 #14
0
ファイル: api.py プロジェクト: cloudbase/maas
 def sign(uri, headers, credentials):
     """Sign the URI and headers."""
     auth = MAASOAuth(*credentials)
     auth.sign_request(uri, headers)
コード例 #15
0
def get_client(url, creds):
    [consumer_key, token, secret] = creds.split(':')
    auth = MAASOAuth(consumer_key=consumer_key,
                     resource_token=token,
                     resource_secret=secret)
    return MAASClient(auth, MAASDispatcher(), url)
コード例 #16
0
 def test_sign_request_adds_header(self):
     headers = {}
     auth = MAASOAuth("consumer_key", "resource_token", "resource_secret")
     auth.sign_request("http://example.com/", headers)
     self.assertIn("Authorization", headers)
コード例 #17
0
 def _connect(self):
     if not self.conn:
         auth = MAASOAuth(*self.maas_api_key.split(':'))
         dispatcher = MAASDispatcher()
         self.maas_client = MAASClient(auth, dispatcher, self.maas_url)
         self.conn = True
コード例 #18
0
 def sign(uri, headers, credentials):
     """Sign the URI and headers."""
     auth = MAASOAuth(*credentials)
     auth.sign_request(uri, headers)
コード例 #19
0
ファイル: maas.py プロジェクト: graywen24/for-ess-a3
def _getclient(url=u'http://localhost/MAAS/api/1.0/'):
    consumer_key, token, secret = key('root').split(':', 3)
    auth = MAASOAuth(consumer_key, token, secret)
    dispatch = MAASDispatcher()
    client = MAASClient(auth, dispatch, url)
    return client
コード例 #20
0
ファイル: test_maas_client.py プロジェクト: cloudbase/maas
 def test_sign_request_adds_header(self):
     headers = {}
     auth = MAASOAuth('consumer_key', 'resource_token', 'resource_secret')
     auth.sign_request('http://example.com/', headers)
     self.assertIn('Authorization', headers)
コード例 #21
0
ファイル: test_maas_client.py プロジェクト: cloudbase/maas
 def test_sign_request_adds_header(self):
     headers = {}
     auth = MAASOAuth('consumer_key', 'resource_token', 'resource_secret')
     auth.sign_request('http://example.com/', headers)
     self.assertIn('Authorization', headers)