Пример #1
0
        public override void Run()
        {
            // Login
            VapiAuthHelper           = new VapiAuthenticationHelper();
            VimAuthHelper            = new VimAuthenticationHelper();
            SessionStubConfiguration =
                VapiAuthHelper.LoginByUsernameAndPassword(
                    Server, UserName, Password);
            VimAuthHelper.LoginByUsernameAndPassword(
                Server, UserName, Password);

            // Get the cluster
            ManagedObjectReference clusterMoRef =
                VimHelper.GetCluster(ClusterName, VimAuthHelper);

            this.clusterId = new DynamicID();
            this.clusterId.SetType((string)clusterMoRef.type);
            this.clusterId.SetId((string)clusterMoRef.Value);


            this.tagName = RandomIdGenerator.GetRandomString("Tag-");
            var tagDesc = "Sample tag";

            this.categoryName = RandomIdGenerator.GetRandomString("Cat-");
            var categoryDesc = "Sample category";

            // create services
            this.tagService = VapiAuthHelper.StubFactory.CreateStub <cis.tagging.Tag>(
                SessionStubConfiguration);
            this.categoryService =
                VapiAuthHelper.StubFactory.CreateStub <Category>(
                    SessionStubConfiguration);
            this.tagAssociation =
                VapiAuthHelper.StubFactory.CreateStub <TagAssociation>(
                    SessionStubConfiguration);

            // create a category
            this.categoryId = CreateCategory(categoryService, categoryName,
                                             categoryDesc, CategoryModel.Cardinality.MULTIPLE);
            Console.WriteLine("Created category '{0}'", categoryName);

            // create a tag
            this.tagId = CreateTag(
                this.tagService, this.tagName, tagDesc, this.categoryId);
            Console.WriteLine("Created tag '{0}'", this.tagName);

            // update the category
            var newCategoryDesc = "Tag category updated at " + DateTime.Now;

            UpdateCategoryDesc(this.categoryService, this.categoryId,
                               newCategoryDesc);
            Console.WriteLine("Updated category description to '{0}'",
                              newCategoryDesc);

            // update the tag
            var newTagDesc = "Tag updated at " + DateTime.Now;

            UpdateTagDesc(tagService, tagId, newTagDesc);
            Console.WriteLine("Updated tag description to '{0}'", newTagDesc);

            // tag the Cluster with the newely created tag
            this.tagAssociation.Attach(this.tagId, this.clusterId);
            if (this.tagAssociation.ListAttachedTags(
                    this.clusterId).Contains(this.tagId))
            {
                Console.WriteLine("Cluster '{0}' tagged with '{1}'",
                                  ClusterName, tagName);
                this.tagAttached = true;
            }
            else
            {
                throw new Exception(string.Format(
                                        "Could not tag Cluster '{0}' with '{1}'",
                                        ClusterName, tagName));
            }
        }