'Main execution path.'

def __init__(self):

    self.inventory = {}
    self.index = {}
    self.host_metadata = {}
    cache_dir = os.path.expanduser('~')
    self.cache_path_cache = os.path.join(cache_dir, '.ansible-azure.cache')
    self.cache_path_index = os.path.join(cache_dir, '.ansible-azure.index')
    self.cache_max_age = 0
    self.read_settings()
    self.read_environment()
    self.parse_cli_args()
    self.sms = ServiceManagementService(self.subscription_id, self.cert_path)
    if self.args.refresh_cache:
        self.do_api_calls_update_cache()
    elif (not self.is_cache_valid()):
        self.do_api_calls_update_cache()
    if self.args.list_images:
        data_to_print = self.json_format_dict(self.get_images(), True)
    elif (self.args.list or self.args.host):
        if (len(self.inventory) == 0):
            data = json.loads(self.get_inventory_from_cache())
        else:
            data = self.inventory
        if self.args.host:
            data_to_print = self.get_host(self.args.host)
        else:
            hostvars = {}
            if (len(data) > 0):
                for host in set([h for hosts in data.values() for h in hosts if h]):
                    hostvars[host] = self.get_host(host, jsonify=False)
            data['_meta'] = {'hostvars': hostvars}
            data_to_print = self.json_format_dict(data, pretty=True)
    print data_to_print
