implement shutdown
authorTony Mack <tmack@paris.CS.Princeton.EDU>
Fri, 24 Aug 2012 14:57:16 +0000 (10:57 -0400)
committerTony Mack <tmack@paris.CS.Princeton.EDU>
Fri, 24 Aug 2012 14:57:16 +0000 (10:57 -0400)
sfa/managers/aggregate_manager.py
sfa/methods/Shutdown.py
sfa/openstack/nova_driver.py
sfa/planetlab/pldriver.py

index f8948fd..d947c3f 100644 (file)
@@ -153,6 +153,16 @@ class AggregateManager:
         call_id = options.get('call_id')
         if Callids().already_handled(call_id): return True
         return self.driver.renew(xrns, expiration_time, options)
+
+    def PerformOperationalAction(self, api, xrns, action, options={}):
+        call_id = options.get('call_id')
+        if Callids().already_handled(call_id): return True
+        return self.driver.performOperationalAction(xrns, action, options) 
+
+    def Shutdown(self, api, xrn, options={}):
+        call_id = options.get('call_id')
+        if Callids().already_handled(call_id): return True
+        return self.driver.shutdown(xrn, options) 
     
     def GetTicket(self, api, xrn, creds, rspec, users, options):
     
index 273b991..17c6636 100644 (file)
@@ -1,8 +1,8 @@
 from sfa.storage.parameter import Parameter
+from sfa.trust.credential import Credential
+from sfa.util.method import Method
 
-from sfa.methods.Stop import Stop
-
-class Shutdown(Stop):
+class Shutdown(Method):
     """
     Perform an emergency shut down of a sliver. This operation is intended for administrative use. 
     The sliver is shut down but remains available for further forensics.
@@ -17,7 +17,12 @@ class Shutdown(Stop):
         ]
     returns = Parameter(bool, "Success or Failure")
 
-    def call(self, slice_xrn, creds):
+    def call(self, xrn, creds):
+
+        valid_creds = self.api.auth.checkCredentials(creds, 'stopslice', xrn)
+        #log the call
+        origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
+        self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, xrn, self.name))
 
-        return Stop.call(self, slice_xrn, creds)
+        return self.api.manager.Shutdown(self.api, xrn, creds)
     
index 7a84c2e..56f0334 100644 (file)
@@ -375,11 +375,18 @@ class NovaDriver(Driver):
         return True
 
     def perform_operational_action  (self, urns, action, options):
-        tenant_name = OSXrn(xrn=slice_hrn, type='slice').get_tenant_name()
-        name = OSXrn(xrn=slice_urn).name
-        aggregate = OSAggregate(self)
-        return aggregate.stop_instances(name, tenant_name) 
-
+        pass
+
+    def shutdown(self, xrn, options):
+        xrn = OSXrn(xrn=xrn, type='slice')
+        tenant_name = xrn.get_tenant_name()
+        name = xrn.get_slicename()
+        self.driver.shell.nova_manager.connect(tenant=tenant_name)
+        instances = self.driver.shell.nova_manager.servers.findall(name=name)
+        for instance in instances:
+            self.driver.shell.nova_manager.servers.shutdown(instance)
+        return True
     # xxx this code is quite old and has not run for ages
     # it is obviously totally broken and needs a rewrite
     def get_ticket (self, slice_urn, slice_hrn, creds, rspec_string, options):
index d4f1243..25d16f4 100644 (file)
@@ -760,22 +760,10 @@ class PlDriver (Driver):
         except:
             return False
 
-    # remove the 'enabled' tag 
-    def start_slice (self, slice_urn, slice_hrn, creds):
-        slicename = hrn_to_pl_slicename(slice_hrn)
-        slices = self.shell.GetSlices({'name': slicename}, ['slice_id'])
-        if not slices:
-            raise RecordNotFound(slice_hrn)
-        slice_id = slices[0]['slice_id']
-        slice_tags = self.shell.GetSliceTags({'slice_id': slice_id, 'tagname': 'enabled'}, ['slice_tag_id'])
-        # just remove the tag if it exists
-        if slice_tags:
-            self.shell.DeleteSliceTag(slice_tags[0]['slice_tag_id'])
-        return 1
-
     # set the 'enabled' tag to 0
-    def stop_slice (self, slice_urn, slice_hrn, creds):
-        slicename = hrn_to_pl_slicename(slice_hrn)
+    def shutdown (self, xrn, options):
+        xrn = PlXrn(xrn=xrn, type='slice')
+        slicename = xrn.pl_slicename()
         slices = self.shell.GetSlices({'name': slicename}, ['slice_id'])
         if not slices:
             raise RecordNotFound(slice_hrn)
@@ -788,9 +776,6 @@ class PlDriver (Driver):
             self.shell.UpdateSliceTag(tag_id, '0')
         return 1
     
-    def reset_slice (self, slice_urn, slice_hrn, creds):
-        raise SfaNotImplemented ("reset_slice not available at this interface")
-    
     # xxx this code is quite old and has not run for ages
     # it is obviously totally broken and needs a rewrite
     def get_ticket (self, slice_urn, slice_hrn, creds, rspec_string, options):