예제 #1
0
def run():
    ApigeeURL = 'https://api.enterprise.apigee.com'
    Username = None
    Password = None
    Organization = None
    Environment = None
    Name = None
    Revision = None
    Options = 'o:n:r:e:u:p:l:h'

    opts = getopt.getopt(sys.argv[2:], Options)[0]

    for o in opts:
        if o[0] == '-n':
            Name = o[1]
        elif o[0] == '-o':
            Organization = o[1]
        elif o[0] == '-e':
            Environment = o[1]
        elif o[0] == '-r':
            Revision = o[1]
        elif o[0] == '-u':
            Username = o[1]
        elif o[0] == '-p':
            Password = o[1]
        elif o[0] == '-l':
            ApigeeURL = o[1]
        elif o[0] == '-h':
            printUsage()
            sys.exit(0)

    if Username == None or Password == None or Organization == None or Name == None:
        printUsage()
        sys.exit(1)

    httptools.setup(ApigeeURL, Username, Password)

    if ((Environment == None) and (Revision == None)):
        deployments = deploytools.getAndParseDeployments(Organization, Name)
        for dep in deployments:
            deploytools.undeploy(Organization, dep['environment'], Name,
                                 dep['revision'])
        deploytools.getAndPrintDeployments(Organization, Name)

    elif (Environment == None):
        deployments = deploytools.getAndParseDeployments(Organization, Name)
        for dep in deployments:
            if (dep['revision'] == Revision):
                deploytools.undeploy(Organization, dep['environment'], Name,
                                     dep['revision'])
        deploytools.getAndPrintDeployments(Organization, Name)

    else:
        deployments = deploytools.getAndParseEnvDeployments(
            Organization, Environment)
        for dep in deployments:
            if (dep['name'] == Name):
                deploytools.undeploy(Organization, Environment, Name,
                                     dep['revision'])
        deploytools.getAndPrintEnvDeployments(Organization, Environment)
def run():
  ApigeeURL = 'https://api.enterprise.apigee.com'
  Username = None
  Password = None
  Organization = None
  Environment = None
  Name = None
  Options = 'o:n:e:u:p:l:h'

  opts = getopt.getopt(sys.argv[2:], Options)[0]

  for o in opts:
    if o[0] == '-n':
      Name = o[1]
    elif o[0] == '-o':
      Organization = o[1]
    elif o[0] == '-e':
      Environment = o[1]
    elif o[0] == '-u':
      Username = o[1]
    elif o[0] == '-p':
      Password = o[1]
    elif o[0] == '-l':
      ApigeeURL = o[1]
    elif o[0] == '-h':
      printUsage()
      sys.exit(0)

  if not Password:
    Password = getpass.getpass()

  if not Username or not Password or not Organization:
    printUsage();
    sys.exit(1)

  httptools.setup(ApigeeURL, Username, Password)


  if ((Environment == None) and (Name != None)):
    deploytools.getAndPrintDeployments(Organization, Name)

  elif ((Environment != None) and (Name == None)):
    deploytools.getAndPrintEnvDeployments(Organization, Environment)

  else:
    printUsage()
    sys.exit(1)
def run():  
  ApigeeURL = 'https://api.enterprise.apigee.com'
  Username = None
  Password = None
  Organization = None
  Environment = None
  Name = None
  Options = 'o:n:e:u:p:l:h'
  
  opts = getopt.getopt(sys.argv[2:], Options)[0]
  
  for o in opts:
    if o[0] == '-n':
      Name = o[1]
    elif o[0] == '-o':
      Organization = o[1]
    elif o[0] == '-e':
      Environment = o[1]
    elif o[0] == '-u':
      Username = o[1]
    elif o[0] == '-p':
      Password = o[1]
    elif o[0] == '-l':
      ApigeeURL = o[1]
    elif o[0] == '-h':
      printUsage()
      sys.exit(1)
      
    
  if Username == None or Password == None or Organization == None:
    printUsage();
    sys.exit(1)
  
  
  httptools.setup(ApigeeURL, Username, Password)
      
      
  if ((Environment == None) and (Name != None)):
    deploytools.getAndPrintDeployments(Organization, Name)
      
  elif ((Environment != None) and (Name == None)):
    deploytools.getAndPrintEnvDeployments(Organization, Environment)
    
  else:
    printUsage()
    sys.exit(1)
예제 #4
0
def run():  
  ApigeeURL = 'https://api.enterprise.apigee.com'
  Username = None
  Password = None
  Organization = None
  Environment = None
  Name = None
  Revision = None
  Options = 'o:n:r:e:u:p:l:h'
  
  opts = getopt.getopt(sys.argv[2:], Options)[0]
  
  for o in opts:
    if o[0] == '-n':
      Name = o[1]
    elif o[0] == '-o':
      Organization = o[1]
    elif o[0] == '-e':
      Environment = o[1]
    elif o[0] == '-r':
      Revision = o[1]
    elif o[0] == '-u':
      Username = o[1]
    elif o[0] == '-p':
      Password = o[1]
    elif o[0] == '-l':
      ApigeeURL = o[1]
    elif o[0] == '-h':
      printUsage()
      sys.exit(1)
      
    
  if Username == None or Password == None or Organization == None or Name == None:
    printUsage();
    sys.exit(1)
  
  
  httptools.setup(ApigeeURL, Username, Password)
      
  if ((Environment == None) and (Revision == None)):
    deployments = deploytools.getAndParseDeployments(Organization, Name)
    for dep in deployments:
      deploytools.undeploy(Organization, dep['environment'],
                           Name, dep['revision'])
    deploytools.getAndPrintDeployments(Organization, Name)

  elif (Environment == None):
    deployments = deploytools.getAndParseDeployments(Organization, Name)
    for dep in deployments:
      if (dep['revision'] == Revision):
        deploytools.undeploy(Organization, dep['environment'],
                             Name, dep['revision'])
    deploytools.getAndPrintDeployments(Organization, Name)
  
  else:
    deployments = deploytools.getAndParseEnvDeployments(Organization, Environment)
    for dep in deployments:
      if (dep['name'] == Name):
        deploytools.undeploy(Organization, Environment,
                             Name, dep['revision'])
    deploytools.getAndPrintEnvDeployments(Organization, Environment)
예제 #5
0
def run():
    ApigeeURL = 'https://api.enterprise.apigee.com'
    Username = None
    Password = None
    Directory = None
    Organization = None
    Environment = None
    Name = None
    BasePath = '/'
    ShouldDeploy = True
    ZipFile = None

    Options = 'o:e:n:d:u:p:b:l:z:ih'

    opts = getopt.getopt(sys.argv[2:], Options)[0]

    for o in opts:
        if o[0] == '-n':
            Name = o[1]
        elif o[0] == '-o':
            Organization = o[1]
        elif o[0] == '-d':
            Directory = o[1]
        elif o[0] == '-e':
            Environment = o[1]
        elif o[0] == '-b':
            BasePath = o[1]
        elif o[0] == '-u':
            Username = o[1]
        elif o[0] == '-p':
            Password = o[1]
        elif o[0] == '-l':
            ApigeeURL = o[1]
        elif o[0] == '-z':
            ZipFile = o[1]
        elif o[0] == '-i':
            ShouldDeploy = False
        elif o[0] == '-h':
            printUsage()
            sys.exit(0)

    if not Password:
        Password = getpass.getpass()

    if not Username or not Password or not Directory or \
       not Environment or not Name or not Organization:
        printUsage()
        sys.exit(1)

    httptools.setup(ApigeeURL, Username, Password)

    # Return TRUE if any component of the file path contains a directory name that
    # starts with a "." like '.svn', but not '.' or '..'
    def pathContainsDot(p):
        c = re.compile('\.\w+')
        for pc in p.split('/'):
            if c.match(pc) != None:
                return True
        return False

    # Construct a ZIPped copy of the bundle in memory
    tf = StringIO.StringIO()
    zipout = zipfile.ZipFile(tf, 'w')

    dirList = os.walk(Directory)
    for dirEntry in dirList:
        if not pathContainsDot(dirEntry[0]):
            for fileEntry in dirEntry[2]:
                if not fileEntry.endswith('~'):
                    fn = os.path.join(dirEntry[0], fileEntry)
                    en = os.path.join(os.path.relpath(dirEntry[0], Directory),
                                      fileEntry)
                    zipout.write(fn, en)
    zipout.close()

    if (ZipFile != None):
        tzf = open(ZipFile, 'w')
        tzf.write(tf.getvalue())
        tzf.close()

    revision = deploytools.importBundle(Organization, Name, tf.getvalue())
    if (revision < 0):
        sys.exit(2)

    print 'Imported new proxy revision %i' % revision

    if ShouldDeploy:
        status = deploytools.deployWithoutConflict(Organization, Environment,
                                                   Name, BasePath, revision)
        if status == False:
            sys.exit(2)

    response = httptools.httpCall(
        'GET', '/v1/o/%s/apis/%s/deployments' % (Organization, Name))
    deps = deploytools.parseAppDeployments(Organization, response, Name)
    deploytools.printDeployments(deps)
예제 #6
0
def run():
  ApigeeURL = 'https://api.enterprise.apigee.com'
  Username = None
  Password = None
  Directory = None
  Organization = None
  Environment = None
  Name = None
  BasePath = '/'
  ShouldDeploy = True
  ZipFile = None
    
  Options = 'o:e:n:d:u:p:b:l:z:ih'
  
  opts = getopt.getopt(sys.argv[2:], Options)[0]
  
  for o in opts:
    if o[0] == '-n':
      Name = o[1]
    elif o[0] == '-o':
      Organization = o[1]
    elif o[0] == '-d':
      Directory =o[1]
    elif o[0] == '-e':
      Environment =o[1]
    elif o[0] == '-b':
      BasePath = o[1]
    elif o[0] == '-u':
      Username = o[1]
    elif o[0] == '-p':
      Password = o[1]
    elif o[0] == '-l':
      ApigeeURL = o[1]
    elif o[0] == '-z':
      ZipFile = o[1]
    elif o[0] == '-i':
      ShouldDeploy = False
    elif o[0] == '-h':
      printUsage()
      sys.exit(0)
  
  if Username == None or Password == None or Directory == None or \
     Environment == None or Name == None or Organization == None:
    printUsage()
    sys.exit(1)
  
  httptools.setup(ApigeeURL, Username, Password)
  
  # Return TRUE if any component of the file path contains a directory name that
  # starts with a "." like '.svn', but not '.' or '..'
  def pathContainsDot(p):
    c = re.compile('\.\w+')
    for pc in p.split('/'):
      if c.match(pc) != None:
        return True
    return False
  
  # Construct a ZIPped copy of the bundle in memory
  tf = StringIO.StringIO()
  zipout = zipfile.ZipFile(tf, 'w')
  
  dirList = os.walk(Directory)
  for dirEntry in dirList:
    if not pathContainsDot(dirEntry[0]):
      for fileEntry in dirEntry[2]:
        if not fileEntry.endswith('~'):
          fn = os.path.join(dirEntry[0], fileEntry)
          en = os.path.join(os.path.relpath(dirEntry[0], Directory), fileEntry)
          zipout.write(fn, en)
  zipout.close()
  
  if (ZipFile != None):
    tzf = open(ZipFile, 'w')
    tzf.write(tf.getvalue())
    tzf.close()
    
  revision = deploytools.importBundle(Organization, Name, tf.getvalue())
  if (revision < 0):
    sys.exit(2)
  
  print 'Imported new proxy revision %i' % revision
  
  if ShouldDeploy:
    status = deploytools.deployWithoutConflict(Organization, Environment, Name, BasePath, revision)
    if status == False:
      sys.exit(2)
  
  response = httptools.httpCall('GET', 
      '/v1/o/%s/apis/%s/deployments' % (Organization, Name))
  deps = deploytools.parseAppDeployments(Organization, response, Name)
  deploytools.printDeployments(deps)
def run():    
  ApigeeURL = 'https://api.enterprise.apigee.com'
  Username = None
  Password = None
  Directory = None
  MainScript = None
  Organization = None
  Environment = None
  Name = None
  BasePath = '/'
  ShouldDeploy = True
  ZipFile = None
    
  Options = 'o:e:n:d:m:u:p:b:l:z:ih'
  
  opts = getopt.getopt(sys.argv[2:], Options)[0]
  
  for o in opts:
    if o[0] == '-o':
      Organization = o[1]
    elif o[0] == '-e':
      Environment =o[1]
    elif o[0] == '-n':
      Name = o[1]
    elif o[0] == '-d':
      Directory =o[1]
    elif o[0] == '-m':
      MainScript = o[1]
    elif o[0] == '-u':
      Username = o[1]
    elif o[0] == '-p':
      Password = o[1]
    elif o[0] == '-b':
      BasePath = o[1]
    elif o[0] == '-l':
      ApigeeURL = o[1]
    elif o[0] == '-z':
      ZipFile = o[1]
    elif o[0] == '-i':
      ShouldDeploy = False
    elif o[0] == '-h':
      printUsage()
      sys.exit(1)
  
  BadUsage = False
  if Username == None:
    BadUsage = True
    print '-u is required'    
  if Password == None:
    BadUsage = True
    print '-p is required'
  if Directory == None:
    BadUsage = True
    print '-d is required'
  if Environment == None:
    BadUsage = True
    print '-e is required'
  if Name == None:
    BadUsage = True
    print '-n is required'
  if Organization == None:
    BadUsage = True
    print '-o is required'
  if MainScript == None:
    BadUsage = True
    print '-m is required'
    
  if BadUsage:  
    printUsage()
    sys.exit(1)
  
  httptools.setup(ApigeeURL, Username, Password)
  
  def makeApplication():
    return '<APIProxy name="%s"/>' % Name
    
  def makeProxy():
    return '<ProxyEndpoint name="default">\
      <HTTPProxyConnection>\
      <BasePath>%s</BasePath>\
      <VirtualHost>default</VirtualHost>\
      </HTTPProxyConnection>\
      <RouteRule name="default">\
      <TargetEndpoint>default</TargetEndpoint>\
      </RouteRule>\
      </ProxyEndpoint>' % BasePath
      
  def makeTarget():
    return '<TargetEndpoint name="default">\
      <ScriptTarget>\
      <ResourceURL>node://%s</ResourceURL>\
      </ScriptTarget>\
      </TargetEndpoint>' % MainScript
  
  # Return TRUE if any component of the file path contains a directory name that
  # starts with a "." like '.svn', but not '.' or '..'
  def pathContainsDot(p):
    c = re.compile('\.\w+')
    for pc in p.split('/'):
      if c.match(pc) != None:
        return True
    return False
  
  # ZIP a whole directory into a stream and return the result so that it
  # can be nested into the top-level ZIP
  
  def zipDirectory(dir, pfx):
    ret = StringIO.StringIO()
    tzip = zipfile.ZipFile(ret, 'w')
    dirList = os.walk(dir)
    for dirEntry in dirList:
      for fileEntry in dirEntry[2]:
        if not fileEntry.endswith('~'):
          fn = os.path.join(dirEntry[0], fileEntry)
          en = os.path.join(pfx, os.path.relpath(dirEntry[0], dir), fileEntry)
          if (os.path.isfile(fn)):
            tzip.write(fn, en)
    tzip.close()
    return ret.getvalue()
  
  # Construct a ZIPped copy of the bundle in memory
  tf = StringIO.StringIO()
  zipout = zipfile.ZipFile(tf, 'w')
  
  zipout.writestr('apiproxy/%s.xml' % Name, makeApplication())
  zipout.writestr('apiproxy/proxies/default.xml', makeProxy())
  zipout.writestr('apiproxy/targets/default.xml', makeTarget())
  
  for topName in os.listdir(Directory):
    if not pathContainsDot(topName):
      fn = os.path.join(Directory, topName)
      if (os.path.isdir(fn)):
        contents = zipDirectory(fn, topName)
        en = 'apiproxy/resources/node/%s.zip' % topName
        zipout.writestr(en, contents)
      else:
        en = 'apiproxy/resources/node/%s' % topName
        zipout.write(fn, en)
  zipout.close()
  
  if (ZipFile != None):
    tzf = open(ZipFile, 'w')
    tzf.write(tf.getvalue())
    tzf.close()
  
  revision = deploytools.importBundle(Organization, Name, tf.getvalue())
  if (revision < 0):
    sys.exit(2)
  
  print 'Imported new app revision %i' % revision
  
  if ShouldDeploy:
    status = deploytools.deployWithoutConflict(Organization, Environment, Name, '/', revision)
    if status == False:
      sys.exit(2)
  
  response = httptools.httpCall('GET', 
      '/v1/o/%s/apis/%s/deployments' % (Organization, Name))
  deps = deploytools.parseAppDeployments(Organization, response, Name)
  deploytools.printDeployments(deps)
예제 #8
0
def run():
    ApigeeURL = 'https://api.enterprise.apigee.com'
    Username = None
    Password = None
    Directory = None
    MainScript = None
    Organization = None
    Environment = None
    Name = None
    BasePath = '/'
    ShouldDeploy = True
    ZipFile = None

    Options = 'o:e:n:d:m:u:p:b:l:z:ih'

    opts = getopt.getopt(sys.argv[2:], Options)[0]

    for o in opts:
        if o[0] == '-o':
            Organization = o[1]
        elif o[0] == '-e':
            Environment = o[1]
        elif o[0] == '-n':
            Name = o[1]
        elif o[0] == '-d':
            Directory = o[1]
        elif o[0] == '-m':
            MainScript = o[1]
        elif o[0] == '-u':
            Username = o[1]
        elif o[0] == '-p':
            Password = o[1]
        elif o[0] == '-b':
            BasePath = o[1]
        elif o[0] == '-l':
            ApigeeURL = o[1]
        elif o[0] == '-z':
            ZipFile = o[1]
        elif o[0] == '-i':
            ShouldDeploy = False
        elif o[0] == '-h':
            printUsage()
            sys.exit(0)

    BadUsage = False
    if Username == None:
        BadUsage = True
        print '-u is required'
    if Password == None:
        BadUsage = True
        print '-p is required'
    if Directory == None:
        BadUsage = True
        print '-d is required'
    if Environment == None:
        BadUsage = True
        print '-e is required'
    if Name == None:
        BadUsage = True
        print '-n is required'
    if Organization == None:
        BadUsage = True
        print '-o is required'
    if MainScript == None:
        BadUsage = True
        print '-m is required'

    if BadUsage:
        printUsage()
        sys.exit(1)

    httptools.setup(ApigeeURL, Username, Password)

    def makeApplication():
        return '<APIProxy name="%s"/>' % Name

    def makeProxy():
        return '<ProxyEndpoint name="default">\
      <HTTPProxyConnection>\
      <BasePath>%s</BasePath>\
      <VirtualHost>default</VirtualHost>\
      </HTTPProxyConnection>\
      <RouteRule name="default">\
      <TargetEndpoint>default</TargetEndpoint>\
      </RouteRule>\
      </ProxyEndpoint>' % BasePath

    def makeTarget():
        return '<TargetEndpoint name="default">\
      <ScriptTarget>\
      <ResourceURL>node://%s</ResourceURL>\
      </ScriptTarget>\
      </TargetEndpoint>' % MainScript

    # Return TRUE if any component of the file path contains a directory name that
    # starts with a "." like '.svn', but not '.' or '..'
    def pathContainsDot(p):
        c = re.compile('\.\w+')
        for pc in p.split('/'):
            if c.match(pc) != None:
                return True
        return False

    # ZIP a whole directory into a stream and return the result so that it
    # can be nested into the top-level ZIP

    def zipDirectory(dir, pfx):
        ret = StringIO.StringIO()
        tzip = zipfile.ZipFile(ret, 'w')
        dirList = os.walk(dir)
        for dirEntry in dirList:
            for fileEntry in dirEntry[2]:
                if not fileEntry.endswith('~'):
                    fn = os.path.join(dirEntry[0], fileEntry)
                    en = os.path.join(pfx, os.path.relpath(dirEntry[0], dir),
                                      fileEntry)
                    if (os.path.isfile(fn)):
                        tzip.write(fn, en)
        tzip.close()
        return ret.getvalue()

    # Construct a ZIPped copy of the bundle in memory
    tf = StringIO.StringIO()
    zipout = zipfile.ZipFile(tf, 'w')

    zipout.writestr('apiproxy/%s.xml' % Name, makeApplication())
    zipout.writestr('apiproxy/proxies/default.xml', makeProxy())
    zipout.writestr('apiproxy/targets/default.xml', makeTarget())

    for topName in os.listdir(Directory):
        if not pathContainsDot(topName):
            fn = os.path.join(Directory, topName)
            if (os.path.isdir(fn)):
                contents = zipDirectory(fn, topName)
                en = 'apiproxy/resources/node/%s.zip' % topName
                zipout.writestr(en, contents)
            else:
                en = 'apiproxy/resources/node/%s' % topName
                zipout.write(fn, en)
    zipout.close()

    if (ZipFile != None):
        tzf = open(ZipFile, 'w')
        tzf.write(tf.getvalue())
        tzf.close()

    revision = deploytools.importBundle(Organization, Name, tf.getvalue())
    if (revision < 0):
        sys.exit(2)

    print 'Imported new app revision %i' % revision

    if ShouldDeploy:
        status = deploytools.deployWithoutConflict(Organization, Environment,
                                                   Name, '/', revision)
        if status == False:
            sys.exit(2)

    response = httptools.httpCall(
        'GET', '/v1/o/%s/apis/%s/deployments' % (Organization, Name))
    deps = deploytools.parseAppDeployments(Organization, response, Name)
    deploytools.printDeployments(deps)