novajoin/join.py
def create(self, req, body=None):
        """Generate the OTP, register it with IPA

        Options passed in but as yet-unused are and user-data.
        """
        if not body:
            LOG.error('No body in create request')
            raise base.Fault(webob.exc.HTTPBadRequest())

        instance_id = body.get('instance-id')
        image_id = body.get('image-id')
        project_id = body.get('project-id')
        hostname = body.get('hostname')
        metadata = body.get('metadata', {})

        if not instance_id:
            LOG.error('No instance-id in request')
            raise base.Fault(webob.exc.HTTPBadRequest())

        if not hostname:
            LOG.error('No hostname in request')
            raise base.Fault(webob.exc.HTTPBadRequest())

        if not image_id:
            LOG.error('No image-id in request')
            raise base.Fault(webob.exc.HTTPBadRequest())

        if not project_id:
            LOG.error('No project-id in request')
            raise base.Fault(webob.exc.HTTPBadRequest())

        enroll = metadata.get('ipa_enroll', '')

        if enroll.lower() != 'true':
            LOG.debug('IPA enrollment not requested in instance creation')

        context = req.environ.get('novajoin.context')
        image_service = get_default_image_service()
        image_metadata = {}
        try:
            image = image_service.show(context, image_id)
        except (exception.ImageNotFound, exception.ImageNotAuthorized) as e:
            msg = 'Failed to get image: %s' % e
            LOG.error(msg)
            raise base.Fault(webob.exc.HTTPBadRequest(explanation=msg))
        else:
            image_metadata = image.get('properties', {})

        # Check the image metadata to see if enrollment was requested
        if enroll.lower() != 'true':
            enroll = image_metadata.get('ipa_enroll', '')
            if enroll.lower() != 'true':
                LOG.debug('IPA enrollment not requested in image')
                return {}
            else:
                LOG.debug('IPA enrollment requested in image')
        else:
            LOG.debug('IPA enrollment requested as property')

        # Ensure this instance exists in nova and retrieve the
        # name of the user that requested it.
        instance = get_instance(instance_id)
        if instance is None:
            msg = 'No such instance-id, %s' % instance_id
            LOG.error(msg)
            raise base.Fault(webob.exc.HTTPBadRequest(explanation=msg))

        # TODO(rcritten): Eventually may check the user for permission
        # as well using:
        # user = keystone_client.get_user_name(instance.user_id)

        hostclass = metadata.get('ipa_hostclass')
        if hostclass:
            project_name = keystone_client.get_project_name(project_id)
            allowed_hostclass = self._get_allowed_hostclass(project_name)
            LOG.debug('hostclass %s, allowed_classes %s' %
                      (hostclass, allowed_hostclass))
            if (hostclass not in allowed_hostclass and
                    '*' not in allowed_hostclass):
                msg = "Not allowed to add to hostclass '%s'" % hostclass
                LOG.error(msg)
                raise base.Fault(webob.exc.HTTPForbidden(explanation=msg))

        data = {}

        ipaotp = uuid.uuid4().hex

        data['ipaotp'] = ipaotp
        try:
            domain = CONF.domain
        except cfg.NoSuchOptError:
            domain = 'test'

        try:
            project_subdomain = CONF.project_subdomain
        except cfg.NoSuchOptError:
            hostname = '%s.%s' % (hostname, domain)
        else:
            if project_subdomain:
                LOG.warn('Project subdomain is experimental')
                hostname = '%s.%s.%s' % (hostname,
                                         project_name, domain)
            else:
                hostname = '%s.%s' % (hostname, domain)

        data['hostname'] = hostname

        try:
            res = self.ipaclient.add_host(data['hostname'], ipaotp,
                                          metadata, image_metadata)
            if not res:
                # OTP was not added to host, don't return one
                del data['ipaotp']
        except Exception as e:  # pylint: disable=broad-except
            LOG.error('adding host failed %s', e)
            LOG.error(traceback.format_exc())

        return data
Generate the OTP, register it with IPA

        Options passed in but as yet-unused are and user-data.
        
Generate the OTP, register it with IPA
Options passed in but as yet-unused are and user-data.
Generate the OTP register it with IPA Options passed in but as yet - unused are and user - data .
def create(self, req, body=None):
        if not body:
            LOG.error('No body in create request')
            raise base.Fault(webob.exc.HTTPBadRequest())
        instance_id = body.get('instance-id')
        image_id = body.get('image-id')
        project_id = body.get('project-id')
        hostname = body.get('hostname')
        metadata = body.get('metadata', {})
        if not instance_id:
            LOG.error('No instance-id in request')
            raise base.Fault(webob.exc.HTTPBadRequest())
        if not hostname:
            LOG.error('No hostname in request')
            raise base.Fault(webob.exc.HTTPBadRequest())
        if not image_id:
            LOG.error('No image-id in request')
            raise base.Fault(webob.exc.HTTPBadRequest())
        if not project_id:
            LOG.error('No project-id in request')
            raise base.Fault(webob.exc.HTTPBadRequest())
        enroll = metadata.get('ipa_enroll', '')
        if enroll.lower() != 'true':
            LOG.debug('IPA enrollment not requested in instance creation')
        context = req.environ.get('novajoin.context')
        image_service = get_default_image_service()
        image_metadata = {}
        try:
            image = image_service.show(context, image_id)
        except (exception.ImageNotFound, exception.ImageNotAuthorized) as e:
            msg = 'Failed to get image: %s' % e
            LOG.error(msg)
            raise base.Fault(webob.exc.HTTPBadRequest(explanation=msg))
        else:
            image_metadata = image.get('properties', {})
        if enroll.lower() != 'true':
            enroll = image_metadata.get('ipa_enroll', '')
            if enroll.lower() != 'true':
                LOG.debug('IPA enrollment not requested in image')
                return {}
            else:
                LOG.debug('IPA enrollment requested in image')
        else:
            LOG.debug('IPA enrollment requested as property')
        instance = get_instance(instance_id)
        if instance is None:
            msg = 'No such instance-id, %s' % instance_id
            LOG.error(msg)
            raise base.Fault(webob.exc.HTTPBadRequest(explanation=msg))
        hostclass = metadata.get('ipa_hostclass')
        if hostclass:
            project_name = keystone_client.get_project_name(project_id)
            allowed_hostclass = self._get_allowed_hostclass(project_name)
            LOG.debug('hostclass %s, allowed_classes %s' %
                      (hostclass, allowed_hostclass))
            if (hostclass not in allowed_hostclass and
                    '*' not in allowed_hostclass):
                msg = "Not allowed to add to hostclass '%s'" % hostclass
                LOG.error(msg)
                raise base.Fault(webob.exc.HTTPForbidden(explanation=msg))
        data = {}
        ipaotp = uuid.uuid4().hex
        data['ipaotp'] = ipaotp
        try:
            domain = CONF.domain
        except cfg.NoSuchOptError:
            domain = 'test'
        try:
            project_subdomain = CONF.project_subdomain
        except cfg.NoSuchOptError:
            hostname = '%s.%s' % (hostname, domain)
        else:
            if project_subdomain:
                LOG.warn('Project subdomain is experimental')
                hostname = '%s.%s.%s' % (hostname,
                                         project_name, domain)
            else:
                hostname = '%s.%s' % (hostname, domain)
        data['hostname'] = hostname
        try:
            res = self.ipaclient.add_host(data['hostname'], ipaotp,
                                          metadata, image_metadata)
            if not res:
                del data['ipaotp']
        except Exception as e:  
            LOG.error('adding host failed %s', e)
            LOG.error(traceback.format_exc())
        return data
def create ( self , req , body = None ) : if not body : LOG . error ( 'No body in create request' ) raise base . Fault ( webob . exc . HTTPBadRequest ( ) ) instance_id = body . get ( 'instance-id' ) image_id = body . get ( 'image-id' ) project_id = body . get ( 'project-id' ) hostname = body . get ( 'hostname' ) metadata = body . get ( 'metadata' , { } ) if not instance_id : LOG . error ( 'No instance-id in request' ) raise base . Fault ( webob . exc . HTTPBadRequest ( ) ) if not hostname : LOG . error ( 'No hostname in request' ) raise base . Fault ( webob . exc . HTTPBadRequest ( ) ) if not image_id : LOG . error ( 'No image-id in request' ) raise base . Fault ( webob . exc . HTTPBadRequest ( ) ) if not project_id : LOG . error ( 'No project-id in request' ) raise base . Fault ( webob . exc . HTTPBadRequest ( ) ) enroll = metadata . get ( 'ipa_enroll' , '' ) if enroll . lower ( ) != 'true' : LOG . debug ( 'IPA enrollment not requested in instance creation' ) context = req . environ . get ( 'novajoin.context' ) image_service = get_default_image_service ( ) image_metadata = { } try : image = image_service . show ( context , image_id ) except ( exception . ImageNotFound , exception . ImageNotAuthorized ) as e : msg = 'Failed to get image: %s' % e LOG . error ( msg ) raise base . Fault ( webob . exc . HTTPBadRequest ( explanation = msg ) ) else : image_metadata = image . get ( 'properties' , { } ) if enroll . lower ( ) != 'true' : enroll = image_metadata . get ( 'ipa_enroll' , '' ) if enroll . lower ( ) != 'true' : LOG . debug ( 'IPA enrollment not requested in image' ) return { } else : LOG . debug ( 'IPA enrollment requested in image' ) else : LOG . debug ( 'IPA enrollment requested as property' ) instance = get_instance ( instance_id ) if instance is None : msg = 'No such instance-id, %s' % instance_id LOG . error ( msg ) raise base . Fault ( webob . exc . HTTPBadRequest ( explanation = msg ) ) hostclass = metadata . get ( 'ipa_hostclass' ) if hostclass : project_name = keystone_client . get_project_name ( project_id ) allowed_hostclass = self . _get_allowed_hostclass ( project_name ) LOG . debug ( 'hostclass %s, allowed_classes %s' % ( hostclass , allowed_hostclass ) ) if ( hostclass not in allowed_hostclass and '*' not in allowed_hostclass ) : msg = "Not allowed to add to hostclass '%s'" % hostclass LOG . error ( msg ) raise base . Fault ( webob . exc . HTTPForbidden ( explanation = msg ) ) data = { } ipaotp = uuid . uuid4 ( ) . hex data [ 'ipaotp' ] = ipaotp try : domain = CONF . domain except cfg . NoSuchOptError : domain = 'test' try : project_subdomain = CONF . project_subdomain except cfg . NoSuchOptError : hostname = '%s.%s' % ( hostname , domain ) else : if project_subdomain : LOG . warn ( 'Project subdomain is experimental' ) hostname = '%s.%s.%s' % ( hostname , project_name , domain ) else : hostname = '%s.%s' % ( hostname , domain ) data [ 'hostname' ] = hostname try : res = self . ipaclient . add_host ( data [ 'hostname' ] , ipaotp , metadata , image_metadata ) if not res : del data [ 'ipaotp' ] except Exception as e : LOG . error ( 'adding host failed %s' , e ) LOG . error ( traceback . format_exc ( ) ) return data
Generate the OTP, register it with IPA
Options passed in but as yet-unused are and user-data.
Generate the OTP register it with IPA Options passed in but as yet - unused are and user - data .
"""Generate the OTP, register it with IPA

        Options passed in but as yet-unused are and user-data.
        """ # Check the image metadata to see if enrollment was requested # Ensure this instance exists in nova and retrieve the # name of the user that requested it. # TODO(rcritten): Eventually may check the user for permission # as well using: # user = keystone_client.get_user_name(instance.user_id) # OTP was not added to host, don't return one # pylint: disable=broad-except
self
req
body