Add opennebula api urls and add delete vm api
This commit is contained in:
		
					parent
					
						
							
								358d70570a
							
						
					
				
			
			
				commit
				
					
						b7e8eceb25
					
				
			
		
					 4 changed files with 19 additions and 13 deletions
				
			
		| 
						 | 
				
			
			@ -12,6 +12,8 @@ import debug_toolbar
 | 
			
		|||
 | 
			
		||||
urlpatterns = [   url(r'^index.html$', LandingView.as_view()),
 | 
			
		||||
                  url(r'^hosting/', include('hosting.urls', namespace="hosting")),
 | 
			
		||||
                  url(r'^open_api/', include('opennebula_api.urls',
 | 
			
		||||
                      namespace='opennebula_api')),
 | 
			
		||||
                  url(r'^railshosting/', RailsHostingView.as_view(), name="rails.hosting"),
 | 
			
		||||
                  url(r'^nodehosting/', NodeJSHostingView.as_view(), name="node.hosting"),
 | 
			
		||||
                  url(r'^djangohosting/', DjangoHostingView.as_view(), name="django.hosting"),
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -213,6 +213,9 @@ class OpenNebulaManager():
 | 
			
		|||
        vm_id = self.oneadmin_client.call(
 | 
			
		||||
                    oca.VmTemplate.METHODS['instantiate'],
 | 
			
		||||
                    template_id,
 | 
			
		||||
                    '',
 | 
			
		||||
                    False,
 | 
			
		||||
                    ''
 | 
			
		||||
                )
 | 
			
		||||
        try:
 | 
			
		||||
            self.oneadmin_client.call(
 | 
			
		||||
| 
						 | 
				
			
			@ -226,8 +229,11 @@ class OpenNebulaManager():
 | 
			
		|||
        return vm_id
 | 
			
		||||
 | 
			
		||||
    def delete_vm(self, vm_id):
 | 
			
		||||
        vm = self._get_vm(vm_id)
 | 
			
		||||
        vm.delete()
 | 
			
		||||
        self.oneadmin_client.call(
 | 
			
		||||
                oca.VirtualMachine.METHODS['action'], 
 | 
			
		||||
                'terminate',
 | 
			
		||||
                vm_id
 | 
			
		||||
                )
 | 
			
		||||
 | 
			
		||||
    def _get_template_pool(self):
 | 
			
		||||
        try:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -98,14 +98,3 @@ class VirtualMachineSerializer(serializers.ModelSerializer):
 | 
			
		|||
    def update(self, instance, validated_data):
 | 
			
		||||
        pass
 | 
			
		||||
 | 
			
		||||
    def delete(self, instance, validated_data):
 | 
			
		||||
        try:
 | 
			
		||||
            owner = instance.owner
 | 
			
		||||
            manager = OpenNebulaManager(email=owner.email,
 | 
			
		||||
                                        password=owner.password[0:20],
 | 
			
		||||
                                        create_user = True)
 | 
			
		||||
            manager.delete_vm(template_id)
 | 
			
		||||
        except OpenNebulaException as err:
 | 
			
		||||
            raise serializers.ValidationError("OpenNebulaException occured. {0}".format(err))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -49,3 +49,12 @@ class VmDetailsView(generics.RetrieveUpdateDestroyAPIView):
 | 
			
		|||
 | 
			
		||||
    queryset = VirtualMachine.objects.all()
 | 
			
		||||
    serializer_class = VirtualMachineSerializer
 | 
			
		||||
 | 
			
		||||
    def perform_destroy(self, instance):
 | 
			
		||||
        owner = instance.owner
 | 
			
		||||
        manager = OpenNebulaManager(email=owner.email,
 | 
			
		||||
                                    password=owner.password[0:20],
 | 
			
		||||
                                    create_user = True)
 | 
			
		||||
        manager.delete_vm(instance.opennebula_id)
 | 
			
		||||
        instance.delete()
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue