Managing Multiple Environments¶
Sooner or later, you’re likely to find yourself needing multiple Genvid MILE SDK cloud environments. It may be as simple as having separate debug and production environments, or you might have different setups for multiple products.
This section covers handling multiple environments using profiles and how to customize your own tools to work with them.
In This Section
Custom Environment Profiles¶
When managing multiple environments, it can be tedious to ensure the environment is properly set when switching from one to another. To simplify this, the Genvid MILE SDK supports named profiles.
For example, say you want to adjust the verbosity of the tools depending on
whether you’re in the debug or production environment. You can do this by
writing your own profiles in ~/.genvid/profile
.
profile "production" {
GENVID_TOOLBOX_LOGLEVEL = "INFO"
}
profile "debug" {
GENVID_TOOLBOX_LOGLEVEL = "DEBUG"
}
Now you can set GENVID_PROFILE
to either production or
debug and it will update the environment accordingly.
$ export GENVID_PROFILE="debug"
$ genvid-bastion env
> [...]
> GENVID_TOOLBOX_LOGLEVEL="DEBUG"
> [...]
$ export GENVID_PROFILE="production"
$ genvid-bastion env
> [...]
> GENVID_TOOLBOX_LOGLEVEL="INFO"
> [...]
The genvid-bastion env subcommand shows the environment currently in use by the tools. You can review the differences between the default profiles for suggestions on how to create your own.
Warning
If you set a profile name, it must exist.
See also
Customizing Profile Files Location¶
To search for a profile, the toolbox parses each path defined in
GENVID_PROFILES_PATH
until it finds the desired profile.
It can be set to a list of paths separated by os.pathsep
where
each path is either a normal file or a directory that will be searched
recursively. Feel free to store your profiles in a structure that makes sense
for your needs.
Warning
There cannot be conflicting profile names under the same path.
Making Custom Tools Compatible With Profiles¶
If you decide to use profiles in your own script, you will want it to
interoperate with profiles like the rest of the toolbox. You can do that by
creating a Profile
object into your script and
calling the apply()
method before creating
your instance of BaseTool
instance of one of its children.
Then you pass the profile instance to the main()
method
of your tool.
def main():
profile = Profile()
profile.apply()
os.environ.setdefault("GENVID_TOOLBOX_LOGLEVEL", "INFO")
tool = WebSample()
return tool.main(profile=profile)
This code does three things:
The constructor for
Profile
finds and loads the active profile into memory.profile.apply()
gives a default value to every environment variable defined in the active profile. Note that it must be called before setting any default environment variables or creating theBaseTool
instance.Finally, the code passes the applied profile to
main()
for diagnosis purposes.
See Profile
for more information about integrating profiles with your
custom tools.