def check_instance_state(vm_state=None, task_state=(None,), must_have_launched=True):
 if ((vm_state is not None) and (not isinstance(vm_state, set))):
  vm_state = set(vm_state)
 if ((task_state is not None) and (not isinstance(task_state, set))):
  task_state = set(task_state)
 def outer(f):
  @six.wraps(f)
  def inner(self, context, instance, *args, **kw):
   if ((vm_state is not None) and (instance.vm_state not in vm_state)):
    raise exception.InstanceInvalidState(attr='vm_state', instance_uuid=instance.uuid, state=instance.vm_state, method=f.__name__)
   if ((task_state is not None) and (instance.task_state not in task_state)):
    raise exception.InstanceInvalidState(attr='task_state', instance_uuid=instance.uuid, state=instance.task_state, method=f.__name__)
   if (must_have_launched and (not instance.launched_at)):
    raise exception.InstanceInvalidState(attr='launched_at', instance_uuid=instance.uuid, state=instance.launched_at, method=f.__name__)
   return f(self, context, instance, *args, **kw)
  return inner
 return outer

def check_instance_state ( vm_state = None , task_state = ( None , ) , must_have_launched = True ) : if ( ( vm_state is not None ) and ( not isinstance ( vm_state , set ) ) ) : vm_state = set ( vm_state ) if ( ( task_state is not None ) and ( not isinstance ( task_state , set ) ) ) : task_state = set ( task_state ) def outer ( f ) : @ six . wraps ( f ) def inner ( self , context , instance , * args , ** kw ) : if ( ( vm_state is not None ) and ( instance . vm_state not in vm_state ) ) : raise exception . InstanceInvalidState ( attr = 'vm_state' , instance_uuid = instance . uuid , state = instance . vm_state , method = f . __name__ ) if ( ( task_state is not None ) and ( instance . task_state not in task_state ) ) : raise exception . InstanceInvalidState ( attr = 'task_state' , instance_uuid = instance . uuid , state = instance . task_state , method = f . __name__ ) if ( must_have_launched and ( not instance . launched_at ) ) : raise exception . InstanceInvalidState ( attr = 'launched_at' , instance_uuid = instance . uuid , state = instance . launched_at , method = f . __name__ ) return f ( self , context , instance , * args , ** kw ) return inner return outer
decorator to check vm and/or task state before entry to api functions .