Exemplo n.º 1
0
        static void Main(string[] args)
        {
            const string region = "RegionOne";

            // Configure OpenStack.NET
            OpenStackNet.Configure(options => options.DefaultTimeout = TimeSpan.FromSeconds(5));

            // Authenticate
            var identityUrl = new Uri("http://example.com");
            var user        = new CloudIdentityWithProject();
            var identity    = new OpenStackIdentityProvider(identityUrl, user);

            identity.Authenticate();

            // Use legacy and new providers
            var legacyNetworking = new CloudNetworksProvider(null, identity);

            legacyNetworking.ListNetworks();
            var networks = new NetworkingService(identity, region);

            networks.ListNetworks();

            var legacyCompute = new CloudServersProvider(null, identity);

            legacyCompute.ListServers();
            var compute = new ComputeService(identity, region);

            compute.ListServers();
        }
Exemplo n.º 2
0
        public void WhenSerializingEmptyCollection_ItShouldBeIgnored()
        {
            OpenStackNet.Configure();
            var thing = new ExampleThing {
                Messages = new List <string>()
            };

            string json = JsonConvert.SerializeObject(thing);

            Assert.DoesNotContain("messages", json);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Provides thread-safe accesss to Rackspace.NET's global configuration options.
        /// <para>
        /// Can only be called once at application start-up, before instantiating any Rackspace.NET objects.
        /// </para>
        /// </summary>
        /// <param name="configureFlurl">Addtional configuration of Flurl's global settings <seealso cref="FlurlHttp.Configure" />.</param>
        /// <param name="configureJson">Additional configuration of Json.NET's global settings <seealso cref="JsonConvert.DefaultSettings" />.</param>
        /// <param name="configure">Additional configuration of Rackspace.NET's global settings.</param>
        public static void Configure(Action <FlurlHttpConfigurationOptions> configureFlurl = null, Action <JsonSerializerSettings> configureJson = null, Action <RackspaceNetConfigurationOptions> configure = null)
        {
            if (configure != null)
            {
                lock (ConfigureLock) { configure(Configuration); }
            }

            Action <OpenStackNetConfigurationOptions> configureOpenStackNet = options =>
            {
                Configuration.Apply(options);
            };

            OpenStackNet.Configure(configureFlurl, configureJson, configureOpenStackNet);
        }
Exemplo n.º 4
0
        public void WhenDeserializingNullCollection_ItShouldUseAnEmptyCollection()
        {
            OpenStackNet.Configure();
            var thing = new ExampleThing {
                Messages = null
            };
            string json = JsonConvert.SerializeObject(thing);

            Assert.DoesNotContain("messages", json);

            var result = JsonConvert.DeserializeObject <ExampleThing>(json);

            Assert.NotNull(result.Messages);
            Assert.Empty(result.Messages);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Provides thread-safe accesss to Rackspace.NET's global configuration options.
        /// <para>
        /// Can only be called once at application start-up, before instantiating any Rackspace.NET objects.
        /// </para>
        /// </summary>
        /// <param name="configureFlurl">Addtional configuration of Flurl's global settings <seealso cref="FlurlHttp.Configure" />.</param>
        /// <param name="configureJson">Additional configuration of Json.NET's global settings <seealso cref="JsonConvert.DefaultSettings" />.</param>
        /// <param name="configure">Additional configuration of Rackspace.NET's global settings.</param>
        public static void Configure(Action <FlurlHttpConfigurationOptions> configureFlurl = null, Action <JsonSerializerSettings> configureJson = null, Action <RackspaceNetConfigurationOptions> configure = null)
        {
            lock (ConfigureLock)
            {
                if (_isConfigured)
                {
                    return;
                }

                OpenStackNet.Configure(configureFlurl, configureJson);

                configure?.Invoke(Configuration);
                Configuration.Apply(OpenStackNet.Configuration);

                _isConfigured = true;
            }
        }
Exemplo n.º 6
0
        public async Task UseBothOpenStackAndRackspace_RackspaceConfiguredFirst()
        {
            using (var httpTest = new HttpTest())
            {
                RackspaceNet.Configure();
                OpenStackNet.Configure();

                await "http://api.com".GetAsync();

                var userAgent = httpTest.CallLog[0].Request.Headers.UserAgent.ToString();

                var rackspaceMatches = new Regex("rackspace").Matches(userAgent);
                Assert.Equal(1, rackspaceMatches.Count);

                var openstackMatches = new Regex("openstack").Matches(userAgent);
                Assert.Equal(1, openstackMatches.Count);
            }
        }
        public void OpenStackNet_UsesDHCPOptionConverter()
        {
            OpenStackNet.Configure();

            var port = new Port
            {
                DHCPOptions = new Dictionary <string, string>
                {
                    { "a", "stuff" }
                }
            };

            var json   = JsonConvert.SerializeObject(port);
            var result = JsonConvert.DeserializeObject <Port>(json);

            Assert.NotNull(result.DHCPOptions);
            Assert.Equal(1, result.DHCPOptions.Count);
        }
 public RootWrapperConverterTests()
 {
     OpenStackNet.Configure();
 }