← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~smoser/maas/ephemeral-enlist into lp:maas

 

Scott Moser has proposed merging lp:~smoser/maas/ephemeral-enlist into lp:maas.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~smoser/maas/ephemeral-enlist/+merge/117993

make enlistment use ephemeral environment via enlistment metadata service

The overall goal of these changes is to get enlistment done in the
ephemeral environment rather than from the netboot ISO.  This is done by
adding an enlistment datasource for cloud-init.

The "default" profile (which currently does enlistment) will be passed a
'url=' value that points to the rendered cloud-config content instructing
cloud-init to use the maas provided metadata service.

Then, the same path is taken by cloud-init as is done in the commissioning
environment, except for the fact that the metadata service that provides
the user-data will not require oauth.

Both cobbler and non-cobbler paths have been updated.


I have envisioned here that commissioning and enlistment are largely
different from the maas api server perspective.  Ie the url= parameter
on the "enlist" profile and on the "commission" profile will be different.
The source of that is that the environments do differ in that
 a.) commisioning has a valid node associated with the requests
 b.) commissioning has oauth tokens, enlistment cannot reasonably be authed.

These *could* be merged into one metadata service, but I've not done that
here, and think it not unreasonable to keep them separate.


-- 
https://code.launchpad.net/~smoser/maas/ephemeral-enlist/+merge/117993
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~smoser/maas/ephemeral-enlist into lp:maas.
=== modified file 'contrib/preseeds/maas-enlist.preseed'
--- contrib/preseeds/maas-enlist.preseed	2012-04-10 22:48:56 +0000
+++ contrib/preseeds/maas-enlist.preseed	2012-08-02 21:06:19 +0000
@@ -1,6 +1,10 @@
-d-i preseed/early_command string anna-install maas-enlist-udeb
-d-i maas-enlist/skip-maas-discover boolean true
-d-i maas-enlist/maas-server-address string @@server@@
-d-i maas-enlist/host-name string
+#cloud-config
+datasource:
+  MAAS:
+    timeout : 50
+    max_wait : 120
+    # there are no default values for metadata_url or oauth credentials
+    # If no credentials are present, non-authed attempts will be made.
+    metadata_url: http://@@server@@/MAAS/metadata/enlist
 
-$SNIPPET('maas_proxy')
+output: {all: '| tee -a /var/log/cloud-init-output.log'}

=== modified file 'contrib/preseeds_v2/enlist'
--- contrib/preseeds_v2/enlist	2012-06-19 16:01:07 +0000
+++ contrib/preseeds_v2/enlist	2012-08-02 21:06:19 +0000
@@ -1,9 +1,10 @@
-d-i preseed/early_command string anna-install maas-enlist-udeb
-d-i maas-enlist/skip-maas-discover boolean true
-d-i maas-enlist/maas-server-address string {{server_host}}
-d-i maas-enlist/host-name string
+#cloud-config
+datasource:
+  MAAS:
+    timeout : 50
+    max_wait : 120
+    # there are no default values for metadata_url or oauth credentials
+    # If no credentials are present, non-authed attempts will be made.
+    metadata_url: http://{{server_host}}/MAAS/metadata/enlist
 
-d-i     mirror/country string manual
-d-i     mirror/http/hostname string archive.ubuntu.com
-d-i     mirror/http/directory string /ubuntu
-d-i     mirror/http/proxy string http://{{server_host}}:8000/
+output: {all: '| tee -a /var/log/cloud-init-output.log'}

=== added file 'contrib/preseeds_v2/enlist_userdata'
--- contrib/preseeds_v2/enlist_userdata	1970-01-01 00:00:00 +0000
+++ contrib/preseeds_v2/enlist_userdata	2012-08-02 21:06:19 +0000
@@ -0,0 +1,11 @@
+#cloud-config
+
+# could/should set local mirror here or proxy here
+# apt_proxy: http://{{server_host}}:8000/
+# apt_proxy: http://{{server_host}}:8000/
+packages: [ maas-enlist ]
+output: {all: '| tee -a /var/log/cloud-init-output.log'}
+runcmd:
+ - [ maas-enlist, --serverurl, {{server_host}}, --interface, eth0 ]
+
+## the interface above needs probably to be done by 'auto'

=== modified file 'scripts/maas-import-isos'
--- scripts/maas-import-isos	2012-04-17 13:29:20 +0000
+++ scripts/maas-import-isos	2012-08-02 21:06:19 +0000
@@ -109,9 +109,9 @@
 
         # Check what release to use as parent profile
         if [ `echo $STABLE "precise" | awk '{ print ($1 >= $2) ? "True" : "False" }'` = True ]; then
-                PARENT_PROFILE="$STABLE-i386"
+                PARENT_PROFILE="maas-$STABLE-i386-commissioning"
         else
-                PARENT_PROFILE="$DEVEL-i386"
+                PARENT_PROFILE="maas-$DEVEL-i386-commissioning"
         fi
 
         # Add enlist profile

=== modified file 'src/maasserver/enum.py'
--- src/maasserver/enum.py	2012-06-25 13:40:20 +0000
+++ src/maasserver/enum.py	2012-08-02 21:06:19 +0000
@@ -122,3 +122,4 @@
     DEFAULT = ''
     COMMISSIONING = 'commissioning'
     ENLIST = 'enlist'
+    ENLIST_USERDATA = 'enlist_userdata'

=== modified file 'src/maasserver/preseed.py'
--- src/maasserver/preseed.py	2012-06-21 20:56:18 +0000
+++ src/maasserver/preseed.py	2012-08-02 21:06:19 +0000
@@ -43,6 +43,14 @@
     """
     return render_preseed(None, PRESEED_TYPE.ENLIST)
 
+def get_enlist_userdata():
+    """Return the enlistment preseed.
+
+    :return: The rendered enlistment user-data string.
+    :rtype: basestring.
+    """
+    return render_preseed(None, PRESEED_TYPE.ENLIST_USERDATA)
+
 
 # XXX: rvb 2012-06-21 bug=1013146:  'precise' is hardcoded here.
 def get_preseed(node, release="precise"):

=== modified file 'src/metadataserver/api.py'
--- src/metadataserver/api.py	2012-06-25 07:40:56 +0000
+++ src/metadataserver/api.py	2012-08-02 21:06:19 +0000
@@ -44,6 +44,7 @@
     )
 from maasserver.preseed import (
     get_enlist_preseed,
+    get_enlist_userdata,
     get_preseed,
     )
 from metadataserver.models import (
@@ -328,6 +329,45 @@
             raise MAASAPINotFound("No user data available for this node.")
 
 
+class EnlistMetaDataHandler(BaseHandler):
+    """this has to handle the 'meta-data' portion of the meta-data api
+    for enlistment only.  It should mimic the read-only portion
+    of /VersionIndexHandler"""
+
+    allowed_methods = ('GET',)
+
+    data = {
+        'instance-id': 'i-maas-enlistment',
+        'local-hostname': "maas-enlisting-node",
+    }
+
+    def read(self, request, version, item=None):
+        check_version(version)
+
+        # Requesting the list of attributes, not any particular attribute.
+        if item is None or len(item) == 0:
+            return make_list_response(sorted(self.data.keys()))
+
+        if item not in self.data:
+            raise MAASAPINotFound("Unknown metadata attribute: %s" % item)
+
+        return make_text_response(self.data[item])
+
+
+class EnlistUserDataHandler(BaseHandler):
+    """User-data for the enlistment environment"""
+
+    def read(self, request, version):
+        check_version(version)
+        return HttpResponse(get_enlist_userdata(), mimetype="text/plain")
+
+class EnlistVersionIndexHandler(BaseHandler):
+    allowed_methods = ('GET',)
+    fields = ('meta-data', 'user-data')
+
+    def read(self, request, version):
+        return make_list_response(sorted(self.fields))
+
 @api_operations
 class AnonMetaDataHandler(VersionIndexHandler):
     """Anonymous metadata."""

=== modified file 'src/metadataserver/urls.py'
--- src/metadataserver/urls.py	2012-08-02 11:10:18 +0000
+++ src/metadataserver/urls.py	2012-08-02 21:06:19 +0000
@@ -21,6 +21,9 @@
 from maasserver.api_auth import api_auth
 from metadataserver.api import (
     AnonMetaDataHandler,
+    EnlistMetaDataHandler,
+    EnlistUserDataHandler,
+    EnlistVersionIndexHandler,
     IndexHandler,
     MetaDataHandler,
     UserDataHandler,
@@ -44,6 +47,11 @@
 user_data_by_mac_handler = Resource(UserDataHandler)
 version_index_by_mac_handler = Resource(VersionIndexHandler)
 
+# Handlers for the anonymous enlistment metadata service
+enlist_meta_data_handler = Resource(EnlistMetaDataHandler)
+enlist_user_data_handler = Resource(EnlistUserDataHandler)
+enlist_index_handler = Resource(IndexHandler)
+enlist_version_index_handler = Resource(EnlistVersionIndexHandler)
 
 # Normal metadata access, available to a node querying its own metadata.
 node_patterns = patterns(
@@ -107,8 +115,24 @@
         name='metadata-version-by-mac'),
     )
 
+# Anonymous enlistment entry point
+enlist_metadata_patterns = patterns(
+    '',
+    url(
+        r'enlist/(?P<version>[^/]+)/meta-data/(?P<item>.*)$',
+        enlist_meta_data_handler,
+        name='enlist-metadata-meta-data'),
+    url(
+        r'enlist/(?P<version>[^/]+)/user-data$', enlist_user_data_handler,
+        name='enlist-metadata-user-data'),
+    url(
+        r'enlist/(?P<version>[^/]+)[/]*$', enlist_version_index_handler,
+        name='enlist-version'),
+    url(r'enlist[/]*$', enlist_index_handler, name='enlist'),
+    )
+
 
 # URL patterns.  The anonymous patterns are listed first because they're
 # so recognizable: there's no chance of a regular metadata access being
 # mistaken for one of these based on URL pattern match.
-urlpatterns = by_id_patterns + by_mac_patterns + node_patterns
+urlpatterns = enlist_metadata_patterns + by_id_patterns + by_mac_patterns + node_patterns


Follow ups