56
SERVICE_NAME_PREFIX = 'service-'
59
def make_service_name():
60
"""Generate a long, random service name."""
61
characters = string.ascii_lowercase
62
suffix = ''.join([random.choice(characters) for x in xrange(20)])
63
return SERVICE_NAME_PREFIX + suffix
67
charm, options=None, force_machine=None, charm_source=None,
56
charm_name, service_name=None, options=None, force_machine=None,
57
charm_source=None, series='precise'):
69
58
"""Deploy and expose the charm. Return the first unit's public address.
71
60
Also wait until the service is exposed and the first unit started.
62
If service_name is None, use the name of the charm.
72
63
If options are provided, they will be used when deploying the charm.
73
64
If force_machine is not None, create the unit in the specified machine.
74
65
If charm_source is None, dynamically retrieve the charm source directory.
67
# Note: this function is used by both the functional tests and
68
# "make deploy": see the "if main" section below.
76
69
if charm_source is None:
77
70
# Dynamically retrieve the charm source based on the path of this file.
78
71
charm_source = os.path.join(os.path.dirname(__file__), '..')
79
repo = setup_repository(charm, charm_source, series=series)
72
logging.debug('setting up the charms repository')
73
repo = setup_repository(charm_name, charm_source, series=series)
80
74
args = ['deploy', '--repository', repo]
81
service_name = make_service_name()
75
if service_name is None:
76
service_name = charm_name
82
77
if options is not None:
83
78
config_file = make_charm_config_file({service_name: options})
84
79
args.extend(['--config', config_file.name])
85
80
if force_machine is not None:
86
81
args.extend(['--to', str(force_machine)])
87
args.append('local:{}/{}'.format(series, charm))
82
charm_url = 'local:{}/{}'.format(series, charm_name)
83
args.append(charm_url)
88
84
args.append(service_name)
85
logging.debug('deploying {} from the repository in {}'.format(
88
logging.debug('exposing {}'.format(service_name))
90
89
juju('expose', service_name)
91
return wait_for_unit(service_name), service_name
90
logging.debug('waiting for the unit to be ready')
91
return wait_for_unit(service_name)
94
94
if __name__ == '__main__':
95
logging.getLogger().setLevel(logging.DEBUG)
95
96
unit = juju_deploy('juju-gui')
96
97
print(json.dumps(unit, indent=2))