Beispiel #1
0
        /// <summary>
        /// Takes a hashmap of string -> hashmap (ie XenAPI ref -> record)
        ///
        /// Internally convert record to an S (ie a Proxy_VM etc) then uses
        /// that to create a new T (ie a VM) via UpdateFrom
        ///
        /// returns ie a dict ((ref VM) -> VM)
        /// </summary>
        /// <typeparam name="S"></typeparam>
        /// <param name="o">May not be null.</param>
        /// <returns></returns>
        public static Dictionary <XenRef <T>, T> Create <S>(Object o)
        {
            if (o == null)
            {
                throw new ArgumentNullException("o");
            }

            Hashtable dict = (Hashtable)o;

            Dictionary <XenRef <T>, T> result = new Dictionary <XenRef <T>, T>();

            foreach (Object key in dict.Keys)
            {
                XenRef <T> t_ref    = new XenRef <T>((String)key);
                Hashtable  t_record = (Hashtable)dict[key];
                result[t_ref] = (T)Marshalling.convertStruct(typeof(T), t_record);
            }

            return(result);
        }
Beispiel #2
0
 /// <summary>
 /// Given a Hashtable with field-value pairs, it updates the fields of this Probe_result
 /// with the values listed in the Hashtable. Note that only the fields contained
 /// in the Hashtable will be updated and the rest will remain the same.
 /// </summary>
 /// <param name="table"></param>
 public void UpdateFrom(Hashtable table)
 {
     if (table.ContainsKey("configuration"))
     {
         configuration = Maps.convert_from_proxy_string_string(Marshalling.ParseHashTable(table, "configuration"));
     }
     if (table.ContainsKey("complete"))
     {
         complete = Marshalling.ParseBool(table, "complete");
     }
     if (table.ContainsKey("sr"))
     {
         sr = (Sr_stat)Marshalling.convertStruct(typeof(Sr_stat), Marshalling.ParseHashTable(table, "sr"));
     }
     ;
     if (table.ContainsKey("extra_info"))
     {
         extra_info = Maps.convert_from_proxy_string_string(Marshalling.ParseHashTable(table, "extra_info"));
     }
 }
        /// <summary>
        /// Returns null if we get an event we're not interested in, or an unparseable event (e.g. for an object type we don't know about).
        /// </summary>
        /// <param name="proxyEvent"></param>
        /// <returns></returns>
        private static ObjectChange ProcessEvent(Proxy_Event proxyEvent)
        {
            switch (proxyEvent.class_.ToLowerInvariant())
            {
            case "session":
            case "event":
            case "vtpm":
            case "user":
            case "secret":
                // We don't track events on these objects
                return(null);

            default:
                Type typ = Marshalling.GetXenAPIType(proxyEvent.class_);

                if (typ == null)
                {
                    log.DebugFormat("Unknown {0} event for class {1}.", proxyEvent.operation, proxyEvent.class_);
                    return(null);
                }

                switch (proxyEvent.operation)
                {
                case "add":
                case "mod":
                    return(new ObjectChange(typ, proxyEvent.opaqueRef, Marshalling.convertStruct(typ, (Hashtable)proxyEvent.snapshot)));

                case "del":
                    return(new ObjectChange(typ, proxyEvent.opaqueRef, null));

                default:
                    log.DebugFormat("Unknown event operation {0} for opaque ref {1}", proxyEvent.operation, proxyEvent.opaqueRef);
                    return(null);
                }
            }
        }