Ejemplo n.º 1
0
 def __init__(self):
     super(HyperNodeAPI, self).__init__()
     target = messaging.Target(topic='hypernode-hypernode-update',
                               version='1.0',
                               exchange='hypernode')
     serializer = objects_base.NovaObjectSerializer()
     self.client = rpc.get_client(target, serializer=serializer)
     self.client.timeout = HyperNodeAPI.plug_retry_timeout
     self.context = context.get_admin_context()
     self.hn_installer = HyperNodeInstaller()
Ejemplo n.º 2
0
 def __init__(self):
     super(HyperNodeAPI, self).__init__()
     target = messaging.Target(topic='hypernode-hypernode-update',
                               version='1.0',
                               exchange='hypernode')
     serializer = objects_base.NovaObjectSerializer()
     self.client = rpc.get_client(target, serializer=serializer)
     self.client.timeout = HyperNodeAPI.plug_retry_timeout
     self.context = context.get_admin_context()
     self.hn_installer = HyperNodeInstaller()
Ejemplo n.º 3
0
class HyperNodeAPI(object):
    """Client side of the Hyper Node RPC API
    """
    plug_retries_max = cfg.CONF.hypernode_api.plug_retries_max
    plug_retry_timeout = cfg.CONF.hypernode_api.plug_retry_timeout

    def __init__(self):
        super(HyperNodeAPI, self).__init__()
        target = messaging.Target(topic='hypernode-hypernode-update',
                                  version='1.0',
                                  exchange='hypernode')
        serializer = objects_base.NovaObjectSerializer()
        self.client = rpc.get_client(target, serializer=serializer)
        self.client.timeout = HyperNodeAPI.plug_retry_timeout
        self.context = context.get_admin_context()
        self.hn_installer = HyperNodeInstaller()

    def choose_hn(self):
        """
        selects the HyperNode to be used

        :rtype: :class:`HyperNodeInstallerState`
        """

        hn_state = self.hn_installer.start_install(
            hn_cidr_block=cfg.CONF.hypernode_api.cidr_hns,
            tunnel_bearing_subnet_id=cfg.CONF.hypernode_api.subnet_tunnel_bearing,
            vpngw_ip=cfg.CONF.hypernode_api.ip_vpngw,
            internal_base_subnet_id=cfg.CONF.hypernode_api.subnet_internal_base,
            tenant_id=None)

        return hn_state

    def plug(self, instance_id, vif, provider_ip):
        """
        waits for the HyperNode to be ready and connects the instance

        :param instance_id: 
        :type instance_id: ``str``
        :param vif: 
        :type vif: ``str``
        :param provider_ip: 
        :type provider_ip: ``str``
        :rtype: ``bool``
        :raises: MessagingTimeout, RemoteError, MessageDeliveryFailure
        """
        count = 1
        LOG.debug('HyperNodeAPI:plug - plug %s, %s, %s' %
                  (str(instance_id), str(vif), str(provider_ip)))
        while True:
            try:
                self.client.call(self.context, 'plug',
                                 instance_id=instance_id,
                                 vif=vif,
                                 provider_ip=provider_ip)
                LOG.debug('HyperNodeAPI:plug - plug returned')
                return True
            except (MessagingTimeout, RemoteError, MessageDeliveryFailure) as e:
                LOG.debug('HyperNodeAPI:plug - encountered an exception: %s' %
                          (str(e),))
                count += 1
                if count > HyperNodeAPI.plug_retries_max:
                    LOG.debug('HyperNodeAPI:plug - Max retries exceeded,'
                              'raising exception')
                    if e is MessagingTimeout:
                        raise HyperNodeAPIException(
                            'Timeout occured while communicating with '
                            'the new HyperNode')
                    else:
                        raise HyperNodeAPIException(
                            'Unknown error while communicating with '
                            'the new HyperNode')
        
    def unplug(self, vif):
        """
        Disconnects an instance

        :param vif: 
        :type vif: ``str``
        :rtype: ``bool``
        """
        try:
            return self.client.call(self.context,
                                    'unplug',
                                    vif=vif)
        except Exception as e:
            LOG.error('Unplug return error:%s' % (str(e),))
            return None
Ejemplo n.º 4
0
class HyperNodeAPI(object):
    """Client side of the Hyper Node RPC API
    """
    plug_retries_max = cfg.CONF.hypernode_api.plug_retries_max
    plug_retry_timeout = cfg.CONF.hypernode_api.plug_retry_timeout

    def __init__(self):
        super(HyperNodeAPI, self).__init__()
        target = messaging.Target(topic='hypernode-hypernode-update',
                                  version='1.0',
                                  exchange='hypernode')
        serializer = objects_base.NovaObjectSerializer()
        self.client = rpc.get_client(target, serializer=serializer)
        self.client.timeout = HyperNodeAPI.plug_retry_timeout
        self.context = context.get_admin_context()
        self.hn_installer = HyperNodeInstaller()

    def choose_hn(self):
        """
        selects the HyperNode to be used

        :rtype: :class:`HyperNodeInstallerState`
        """

        hn_state = self.hn_installer.start_install(
            hn_cidr_block=cfg.CONF.hypernode_api.cidr_hns,
            tunnel_bearing_subnet_id=cfg.CONF.hypernode_api.
            subnet_tunnel_bearing,
            vpngw_ip=cfg.CONF.hypernode_api.ip_vpngw,
            internal_base_subnet_id=cfg.CONF.hypernode_api.
            subnet_internal_base,
            tenant_id=None)

        return hn_state

    def plug(self, instance_id, vif, provider_ip):
        """
        waits for the HyperNode to be ready and connects the instance

        :param instance_id: 
        :type instance_id: ``str``
        :param vif: 
        :type vif: ``str``
        :param provider_ip: 
        :type provider_ip: ``str``
        :rtype: ``bool``
        :raises: MessagingTimeout, RemoteError, MessageDeliveryFailure
        """
        count = 1
        LOG.debug('HyperNodeAPI:plug - plug %s, %s, %s' %
                  (str(instance_id), str(vif), str(provider_ip)))
        while True:
            try:
                self.client.call(self.context,
                                 'plug',
                                 instance_id=instance_id,
                                 vif=vif,
                                 provider_ip=provider_ip)
                LOG.debug('HyperNodeAPI:plug - plug returned')
                return True
            except (MessagingTimeout, RemoteError,
                    MessageDeliveryFailure) as e:
                LOG.debug('HyperNodeAPI:plug - encountered an exception: %s' %
                          (str(e), ))
                count += 1
                if count > HyperNodeAPI.plug_retries_max:
                    LOG.debug('HyperNodeAPI:plug - Max retries exceeded,'
                              'raising exception')
                    if e is MessagingTimeout:
                        raise HyperNodeAPIException(
                            'Timeout occured while communicating with '
                            'the new HyperNode')
                    else:
                        raise HyperNodeAPIException(
                            'Unknown error while communicating with '
                            'the new HyperNode')

    def unplug(self, vif):
        """
        Disconnects an instance

        :param vif: 
        :type vif: ``str``
        :rtype: ``bool``
        """
        try:
            return self.client.call(self.context, 'unplug', vif=vif)
        except Exception as e:
            LOG.error('Unplug return error:%s' % (str(e), ))
            return None