Provisioning a VDB via the API and adding a post script to it

  • 0
  • 1
  • Question
  • Updated 2 years ago
  • Answered
Hi
Is it possible to provision a DB via the API
/resources/json/delphix/database/provision
and also set up the new VDB to have a post script automatically?

What I'm trying to do is get all developer created VDBs to be done via the API and each one automatically has a post script that runs against their newly created DB.  I don't want this to be optional to the devs, all the VDBs must run this script on creation/refresh.
We have created a powershell module which provisions the VDBs via the API and I'm not sure if we can add post script at provision time.

Our code is something like this 

private dynamic ProvisionDatabase()        {
            var targetEnvironment = new Environment(this.Session).GetEnvironment(this.TargetServerName);
            var targetRepository = new Repository(this.Session).GetRepository(targetEnvironment.reference.Value);
            var snapshot = new Snapshot(this.Session);

            this.Log.Info(targetRepository.reference.Value);

            dynamic json = new ExpandoObject();
            json.type = "MSSqlProvisionParameters";

            json.container = new ExpandoObject();
            json.container.type = "MSSqlDatabaseContainer";
            json.container.name = this.TargetVirtualSourceName;
            json.container.group = this.TargetGroup;

            json.source = new ExpandoObject();
            json.source.type = "MSSqlVirtualSource";

            json.sourceConfig = new ExpandoObject();
            json.sourceConfig.type = "MSSqlSIConfig";
            json.sourceConfig.repository = targetRepository.reference.Value;
            json.sourceConfig.databaseName = this.TargetPhysicalDatabaseName;
            json.sourceConfig.instance = new ExpandoObject();
            json.sourceConfig.instance.type = "MSSqlInstanceConfig";
            json.sourceConfig.instance.host = targetEnvironment.host;

            json.timeflowPointParameters = new ExpandoObject();
            json.timeflowPointParameters.type = "TimeflowPointSemantic";
            json.timeflowPointParameters.container = this.DatabaseResult.reference.Value;
            json.timeflowPointParameters.location = "LATEST_SNAPSHOT";
            

            var result = this.DoPost(json, "/resources/json/delphix/database/provision");
            this.Log.Debug(result);
            return result;
        }
Photo of Mark Hayter

Mark Hayter

  • 744 Points 500 badge 2x thumb

Posted 2 years ago

  • 0
  • 1
Photo of Scott MacDonald

Scott MacDonald, Support Engineer

  • 2,332 Points 2k badge 2x thumb
Official Response
Hi Mark,

Yep, the hooks are defined in the MSSqlVirtualSource object (as type String), such as:

json.source.postScript

described in the API docs under <SERVER>/api/#MSSqlVirtualSource

Hope that helps,

Regards,

Scott.