Exemplo n.º 1
0
 def register_with_dns(self):
     if get_cloudlet_instance().dns_enabled:
         # Register with DNS. If we are in bridged mode, we need to set up a specific record to the new IP address.
         dns_server = cloudlet_dns.CloudletDNS(
             get_cloudlet_instance().data_folder)
         if self.network_mode == 'bridged':
             dns_server.register_svm(self.fqdn, self.ip_address)
         else:
             dns_server.register_svm(self.fqdn)
Exemplo n.º 2
0
def generate_migration_device_credentials(device_id, connection_id, svm_id):
    print 'Preparing credentials and cloudlet information.'
    device_credentials = PairedDeviceDataBundle()
    try:
        # Get the new credentials for the device on the current deployment.
        print 'Generating credentials for device that will migrate to our cloudlet.'
        deployment = Deployment.get_instance()
        device_type = 'mobile'
        device_keys = deployment.pair_device(device_id, connection_id, device_type)

        # Configure the associated instance.
        paired_device = PairedDevice.by_id(device_id)
        paired_device.instance = svm_id
        paired_device.save()

        # Bundle the credentials for a newly paired device.
        print 'Bundling credentials for device.'
        device_credentials.auth_password = device_keys.auth_password
        device_credentials.server_public_key = device_keys.server_public_key
        device_credentials.device_private_key = device_keys.private_key
        device_credentials.load_certificate(deployment.radius_server.cert_file_path)
    except DeviceAlreadyPairedException as e:
        print 'Credentials not generated: ' + e.message

    # Bundle common cloudlet information.
    print 'Bundling cloudlet information for device.'
    cloudlet = get_cloudlet_instance()
    device_credentials.cloudlet_name = Cloudlet.get_hostname()
    device_credentials.cloudlet_fqdn = Cloudlet.get_fqdn()
    device_credentials.cloudlet_encryption_enabled = cloudlet.api_encrypted
    device_credentials.ssid = cloudlet.ssid

    print 'Returning credentials and cloudlet data.'
    return device_credentials.__dict__
Exemplo n.º 3
0
 def config_setup(self):
     self.cloudlet = get_cloudlet_instance()
     self.radius_server = radius.RadiusServer(self.cloudlet.radius_users_file,
                                              self.cloudlet.radius_certs_folder,
                                              self.cloudlet.radius_eap_conf_file)
     self.server_keys = credentials.ServerCredentials.create_object(self.cloudlet.credentials_type,
                                                                    self.cloudlet.data_folder)
Exemplo n.º 4
0
    def POST_discover(self):
        try:
            secret = request.params.get('secret', None)
            print secret

            # Disable any lingering ad-hoc connections.
            wifi_adhoc.disable_adhoc_mode()

            # Enable ad-hoc mode.
            wifi_adhoc.enable_adhoc_mode(SKA_SERVER_IP)

            # Wait for messages.
            cloudlet = get_cloudlet_instance()
            server = WiFiSKAServer(
                host=SKA_SERVER_IP,
                port=SKA_SERVER_PORT,
                secret=secret,
                files_path=cloudlet.cloudletCredentialsFolder,
                pairing_handler=PairingHandler(),
                fqdn=Cloudlet.get_fqdn())
            server.wait_for_messages()
        except Exception, e:
            message = 'Error setting up connection or receiving data (' + type(
                e).__name__ + '): ' + str(e)
            print message
            return ajaxutils.show_and_return_error_dict(message)
Exemplo n.º 5
0
    def __init__(self, config):
        # One instance of Globals is created during application
        # initialization and is available during requests via the
        # 'pylons.app_globals' variable.

        # Create or get instance of the singleton Cloudlet object.
        self.cloudlet = cloudlet.get_cloudlet_instance(config)

        # Set up the global template manager.
        self.tm = TemplateManager()
Exemplo n.º 6
0
    def __init__(self, config):
        # One instance of Globals is created during application
        # initialization and is available during requests via the
        # 'pylons.app_globals' variable.

        # Create or get instance of the singleton Cloudlet object.
        self.cloudlet = cloudlet.get_cloudlet_instance(config)

        # Set up the global template manager.
        self.tm = TemplateManager()
Exemplo n.º 7
0
    def _setup_network(self):
        # Configure bridged mode if enabled
        c = get_cloudlet_instance()
        print 'Bridge enabled: ', c.network_bridge_enabled
        print 'Network Adapter: ', c.network_adapter
        if c.network_bridge_enabled:
            self.network_mode = "bridged"
            self.adapter = c.network_adapter

            # In bridge mode we need a new MAC in case we are a clone.
            self.mac_address = generate_random_mac()
            print 'Generated new mac address: ' + self.mac_address
        else:
            self.network_mode = "user"
            self.adapter = c.network_adapter
Exemplo n.º 8
0
    def setup_network(self, update_mac_if_needed=True):
        # Configure bridged mode if enabled
        c = get_cloudlet_instance()
        print 'Bridge enabled: ', c.network_bridge_enabled
        print 'Network Adapter: ', c.network_adapter
        if c.network_bridge_enabled:
            self.network_mode = "bridged"
            self.adapter = c.network_adapter

            if update_mac_if_needed:
                # In bridge mode we need a new MAC in case we are a clone.
                self.mac_address = generate_random_mac()
                print 'Generated new mac address: ' + self.mac_address
        else:
            self.network_mode = "user"
            self.adapter = c.network_adapter

        # Generate FQDN.
        self._generate_fqdn()
Exemplo n.º 9
0
    def __new__(mcs, name, bases, attrs):
        new_class = super(MetaObject, mcs).__new__(mcs, name, bases, attrs)

        try:
            meta = getattr(new_class, 'Meta')
            delattr(new_class, 'Meta')
        except:
            meta = None

        # Will be none for Model
        if meta is not None:
            info = MetaInfo(meta)
            info.collection = info.collection or name.lower()

            # Create the collection and add it to the new class
            import pycloud.pycloud.cloudlet as cloudlet
            coll = MongoCollection(cloudlet.get_cloudlet_instance().db, info.collection, obj_class=new_class)
            new_class._collection = coll

            # Create the external attributes list and add it to the new class
            if isinstance(info.external, list):
                #print 'Mapping _external attributes for "%s"' % str(new_class)
                #print info.external
                new_class._external = info.external
            else:
                new_class._external = None

            if isinstance(info.mapping, dict):
                new_class.variable_mapping = info.mapping
            else:
                new_class.variable_mapping = None

            # Setup find and find one static methods
            new_class.find = new_class._collection.find
            new_class.find_one = new_class._collection.find_one
            new_class.find_and_modify = new_class._collection.find_and_modify
            new_class.external = external

        return new_class
Exemplo n.º 10
0
 def _unregister_from_dns(self):
     if get_cloudlet_instance().dns_enabled:
         dns_server = cloudlet_dns.CloudletDNS(
             get_cloudlet_instance().data_folder)
         dns_server.unregister_svm(self.fqdn)
Exemplo n.º 11
0
 def _generate_fqdn(self):
     if get_cloudlet_instance().dns_enabled:
         hostname = self.service_id + '.' + self._id
         self.fqdn = cloudlet_dns.CloudletDNS.generate_fqdn(hostname)