Exemplo n.º 1
0
 def list_objects(self):
     provider = view_helpers.get_cloud_provider(self)
     ips = []
     for ip in provider.networking.networks.floating_ips:
         if not ip.in_use():
             ips.append({'ip': ip.public_ip})
     return ips
Exemplo n.º 2
0
 def create(self, validated_data):
     provider = view_helpers.get_cloud_provider(self.context.get('view'))
     net_id = self.context.get('view').kwargs.get('network_pk')
     return provider.network.subnets.create(
         net_id,
         validated_data.get('cidr_block'),
         name=validated_data.get('name'))
Exemplo n.º 3
0
 def get_provider_object(self, pk):
     provider = view_helpers.get_cloud_provider(self.context.get('view'))
     zones = [zone for zone in provider.compute.regions.current.zones
              if zone.id == pk]
     if zones:
         return zones[0]
     else:
         return ObjectDoesNotExist()
Exemplo n.º 4
0
 def list_objects(self):
     provider = view_helpers.get_cloud_provider(self)
     region_pk = self.kwargs.get("region_pk")
     region = provider.compute.regions.get(region_pk)
     if region:
         return region.zones
     else:
         raise Http404
Exemplo n.º 5
0
 def get_provider_object(self, pk):
     provider = view_helpers.get_cloud_provider(self.context.get('view'))
     obj = util.getattrd(
         provider, self.queryset + '.get')(pk)
     if obj:
         return obj
     else:
         return ObjectDoesNotExist()
Exemplo n.º 6
0
 def list_objects(self):
     provider = view_helpers.get_cloud_provider(self)
     region_pk = self.kwargs.get("region_pk")
     region = provider.compute.regions.get(region_pk)
     if region:
         return region.zones
     else:
         raise Http404
Exemplo n.º 7
0
 def list_objects(self):
     provider = view_helpers.get_cloud_provider(self)
     sg_pk = self.kwargs.get("security_group_pk")
     sg = provider.security.security_groups.get(sg_pk)
     if sg:
         return sg.rules
     else:
         raise Http404
Exemplo n.º 8
0
 def get_object(self):
     provider = view_helpers.get_cloud_provider(self)
     bucket_pk = self.kwargs.get("bucket_pk")
     bucket = provider.object_store.get(bucket_pk)
     if bucket:
         return bucket.get(self.kwargs["pk"])
     else:
         raise Http404
Exemplo n.º 9
0
 def get_object(self):
     provider = view_helpers.get_cloud_provider(self)
     bucket_pk = self.kwargs.get("bucket_pk")
     bucket = provider.object_store.get(bucket_pk)
     if bucket:
         return bucket.get(self.kwargs["pk"])
     else:
         raise Http404
Exemplo n.º 10
0
 def list_objects(self):
     provider = view_helpers.get_cloud_provider(self)
     sg_pk = self.kwargs.get("security_group_pk")
     sg = provider.security.security_groups.get(sg_pk)
     if sg:
         return sg.rules
     else:
         raise Http404
Exemplo n.º 11
0
 def create(self, validated_data):
     provider = view_helpers.get_cloud_provider(self.context.get('view'))
     try:
         return provider.block_store.snapshots.create(
             validated_data.get('name'),
             validated_data.get('volume_id'),
             description=validated_data.get('description'))
     except Exception as e:
         raise serializers.ValidationError("{0}".format(e))
Exemplo n.º 12
0
 def get_object(self):
     provider = view_helpers.get_cloud_provider(self)
     sg_pk = self.kwargs.get("security_group_pk")
     sg = provider.security.security_groups.get(sg_pk)
     if not sg:
         raise Http404
     else:
         pk = self.kwargs.get("pk")
         for rule in sg.rules:
             if rule.id == pk:
                 return rule
         raise Http404
Exemplo n.º 13
0
 def get_object(self):
     provider = view_helpers.get_cloud_provider(self)
     sg_pk = self.kwargs.get("security_group_pk")
     sg = provider.security.security_groups.get(sg_pk)
     if not sg:
         raise Http404
     else:
         pk = self.kwargs.get("pk")
         for rule in sg.rules:
             if rule.id == pk:
                 return rule
         raise Http404
Exemplo n.º 14
0
    def get_saved_clusters(self, obj):
        """
        Fetch a list of saved CloudMan clusters from AWS.

        This only fetches saved clusters that used AWS since it appears that
        was the only place this feature was actively used.
        """
        provider = view_helpers.get_cloud_provider(self.context.get('view'))
        if provider.cloud_type != 'aws':
            return []
        # Since we're only working with the AWS, there's no need to specify
        # the cloud argument as it defaults to AWS in BioBlend.
        cml = CloudManLauncher(provider.a_key, provider.s_key, None)
        return cml.get_clusters_pd().get('clusters', [])
Exemplo n.º 15
0
 def create(self, validated_data):
     view = self.context.get('view')
     provider = view_helpers.get_cloud_provider(view)
     sg_pk = view.kwargs.get('security_group_pk')
     if sg_pk:
         sg = provider.security.security_groups.get(sg_pk)
         if sg and validated_data.get('group'):
             return sg.add_rule(src_group=validated_data.get('group'))
         elif sg:
             return sg.add_rule(validated_data.get('ip_protocol'),
                                validated_data.get('from_port'),
                                validated_data.get('to_port'),
                                validated_data.get('cidr_ip'))
     return None
Exemplo n.º 16
0
 def create(self, validated_data):
     provider = view_helpers.get_cloud_provider(self.context.get('view'))
     name = validated_data.get('name')
     image_id = validated_data.get('image_id')
     instance_type = validated_data.get('instance_type_id')
     kp_name = validated_data.get('key_pair_name')
     zone_id = validated_data.get('zone_id')
     security_group_ids = validated_data.get('security_group_ids')
     user_data = validated_data.get('user_data')
     try:
         return provider.compute.instances.create(
             name, image_id, instance_type, zone=zone_id, key_pair=kp_name,
             security_groups=security_group_ids, user_data=user_data)
     except Exception as e:
         raise serializers.ValidationError("{0}".format(e))
Exemplo n.º 17
0
 def create(self, validated_data):
     provider = view_helpers.get_cloud_provider(self.context.get('view'))
     bucket_id = self.context.get('view').kwargs.get('bucket_pk')
     bucket = provider.object_store.get(bucket_id)
     try:
         name = validated_data.get('name')
         content = validated_data.get('upload_content')
         if name:
             object = bucket.create_object(name)
         else:
             object = bucket.create_object(content.name)
         if content:
             object.upload(content.file.getvalue())
         return object
     except Exception as e:
         raise serializers.ValidationError("{0}".format(e))
Exemplo n.º 18
0
    def create(self, validated_data):
        """
        Create a new ApplicationDeployment object.

        Called automatically by the DRF following a POST request.
        """
        name = validated_data.get("name")
        cloud = validated_data.get("target_cloud")
        version = validated_data.get("application_version")
        cloud_version_config = models.ApplicationVersionCloudConfig.objects.get(
            application_version=version.id, cloud=cloud.slug)
        default_combined_config = cloud_version_config.compute_merged_config()
        request = self.context.get('view').request
        provider = view_helpers.get_cloud_provider(
            self.context.get('view'), cloud_id=cloud.slug)
        credentials = view_helpers.get_credentials(cloud, request)
        try:
            handler = util.import_class(version.backend_component_name)()
            app_config = validated_data.get("config_app", {})

            merged_config = jsonmerge.merge(default_combined_config, app_config)
            cloud_config = util.serialize_cloud_config(cloud_version_config)
            final_ud_config = handler.process_app_config(
                provider, name, cloud_config, merged_config)
            sanitised_app_config = handler.sanitise_app_config(merged_config)
            async_result = tasks.launch_appliance.delay(
                name, cloud_version_config, credentials, merged_config,
                final_ud_config)

            del validated_data['application']
            del validated_data['config_app']
            validated_data['owner_id'] = request.user.id
            validated_data['application_config'] = json.dumps(merged_config)
            app_deployment = super(DeploymentSerializer, self).create(validated_data)
            self.log_usage(cloud_version_config, app_deployment, sanitised_app_config, request.user)
            models.ApplicationDeploymentTask.objects.create(
                action=models.ApplicationDeploymentTask.LAUNCH,
                deployment=app_deployment, celery_id=async_result.task_id)
            return app_deployment
        except serializers.ValidationError as ve:
            raise ve
        except Exception as e:
            raise serializers.ValidationError({ "error" : str(e) })
Exemplo n.º 19
0
 def list_objects(self):
     provider = view_helpers.get_cloud_provider(self)
     return provider.object_store.list()
Exemplo n.º 20
0
 def get_object(self):
     provider = view_helpers.get_cloud_provider(self)
     obj = provider.object_store.get(self.kwargs["pk"])
     return obj
Exemplo n.º 21
0
 def get_object(self):
     provider = view_helpers.get_cloud_provider(self)
     obj = provider.compute.images.get(self.kwargs["pk"])
     return obj
Exemplo n.º 22
0
 def list_objects(self):
     provider = view_helpers.get_cloud_provider(self)
     return provider.network.subnets.list(network=self.kwargs["network_pk"])
Exemplo n.º 23
0
 def create(self, validated_data):
     provider = view_helpers.get_cloud_provider(self.context.get('view'))
     return provider.security.security_groups.create(
         validated_data.get('name'), validated_data.get('description'))
Exemplo n.º 24
0
 def list_objects(self):
     provider = view_helpers.get_cloud_provider(self)
     return provider.network.subnets.list(network=self.kwargs["network_pk"])
Exemplo n.º 25
0
 def list_objects(self):
     provider = view_helpers.get_cloud_provider(self)
     return provider.network.list()
Exemplo n.º 26
0
 def get_object(self):
     provider = view_helpers.get_cloud_provider(self)
     obj = provider.block_store.snapshots.get(self.kwargs["pk"])
     return obj
Exemplo n.º 27
0
 def get_object(self):
     provider = view_helpers.get_cloud_provider(self)
     return provider.compute.instance_types.get(self.kwargs.get('pk'))
Exemplo n.º 28
0
 def list_objects(self):
     provider = view_helpers.get_cloud_provider(self)
     return provider.block_store.snapshots.list()
Exemplo n.º 29
0
 def list_objects(self):
     provider = view_helpers.get_cloud_provider(self)
     return provider.security.security_groups.list()
Exemplo n.º 30
0
 def get_object(self):
     provider = view_helpers.get_cloud_provider(self)
     obj = provider.object_store.get(self.kwargs["pk"])
     return obj
Exemplo n.º 31
0
 def get_object(self):
     provider = view_helpers.get_cloud_provider(self)
     return provider.network.subnets.get(self.kwargs["pk"])
Exemplo n.º 32
0
 def get_queryset(self):
     provider = view_helpers.get_cloud_provider(self.context.get('view'))
     return provider.compute.regions.current.zones
Exemplo n.º 33
0
 def list_objects(self):
     provider = view_helpers.get_cloud_provider(self)
     return provider.network.list()
Exemplo n.º 34
0
 def list_objects(self):
     provider = view_helpers.get_cloud_provider(self)
     return provider.compute.instances.list()
Exemplo n.º 35
0
 def create(self, validated_data):
     provider = view_helpers.get_cloud_provider(self.context.get('view'))
     return provider.network.create(name=validated_data.get('name'))
Exemplo n.º 36
0
 def create(self, validated_data):
     provider = view_helpers.get_cloud_provider(self.context.get('view'))
     return provider.security.key_pairs.create(validated_data.get('name'))
Exemplo n.º 37
0
 def create(self, validated_data):
     provider = view_helpers.get_cloud_provider(self.context.get('view'))
     try:
         return provider.object_store.create(validated_data.get('name'))
     except Exception as e:
         raise serializers.ValidationError("{0}".format(e))
Exemplo n.º 38
0
 def get_queryset(self):
     provider = view_helpers.get_cloud_provider(self.context.get('view'))
     return util.getattrd(provider, self.queryset + '.list')()
Exemplo n.º 39
0
 def get_object(self):
     provider = view_helpers.get_cloud_provider(self)
     obj = provider.compute.instances.get(self.kwargs["pk"])
     return obj
Exemplo n.º 40
0
 def list_objects(self):
     provider = view_helpers.get_cloud_provider(self)
     return provider.compute.images.list()
Exemplo n.º 41
0
 def list_objects(self):
     provider = view_helpers.get_cloud_provider(self)
     return provider.block_store.snapshots.list()
Exemplo n.º 42
0
 def get_object(self):
     provider = view_helpers.get_cloud_provider(self)
     obj = provider.block_store.snapshots.get(self.kwargs["pk"])
     return obj
Exemplo n.º 43
0
 def get_object(self):
     provider = view_helpers.get_cloud_provider(self)
     return provider.compute.instance_types.get(self.kwargs.get('pk'))
Exemplo n.º 44
0
 def list_objects(self):
     provider = view_helpers.get_cloud_provider(self)
     return provider.object_store.list()
Exemplo n.º 45
0
 def get_object(self):
     provider = view_helpers.get_cloud_provider(self)
     return provider.network.subnets.get(self.kwargs["pk"])
Exemplo n.º 46
0
 def get_object(self):
     provider = view_helpers.get_cloud_provider(self)
     obj = provider.security.security_groups.get(self.kwargs["pk"])
     return obj