id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequencelengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
sequencelengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
3,600 | juju/juju | state/spaces.go | AddSpace | func (st *State) AddSpace(name string, providerId network.Id, subnets []string, isPublic bool) (newSpace *Space, err error) {
defer errors.DeferredAnnotatef(&err, "adding space %q", name)
if !names.IsValidSpace(name) {
return nil, errors.NewNotValid(nil, "invalid space name")
}
spaceDoc := spaceDoc{
Life: Alive,
Name: name,
IsPublic: isPublic,
ProviderId: string(providerId),
}
newSpace = &Space{doc: spaceDoc, st: st}
ops := []txn.Op{{
C: spacesC,
Id: name,
Assert: txn.DocMissing,
Insert: spaceDoc,
}}
if providerId != "" {
ops = append(ops, st.networkEntityGlobalKeyOp("space", providerId))
}
for _, subnetId := range subnets {
// TODO:(mfoord) once we have refcounting for subnets we should
// also assert that the refcount is zero as moving the space of a
// subnet in use is not permitted.
ops = append(ops, txn.Op{
C: subnetsC,
Id: subnetId,
Assert: bson.D{bson.DocElem{"fan-local-underlay", bson.D{{"$exists", false}}}},
Update: bson.D{{"$set", bson.D{{"space-name", name}}}},
})
}
if err := st.db().RunTransaction(ops); err == txn.ErrAborted {
if _, err := st.Space(name); err == nil {
return nil, errors.AlreadyExistsf("space %q", name)
}
for _, subnetId := range subnets {
subnet, err := st.Subnet(subnetId)
if errors.IsNotFound(err) {
return nil, err
}
if subnet.FanLocalUnderlay() != "" {
return nil, errors.Errorf("Can't set space for FAN subnet %q - it's always inherited from underlay", subnet.CIDR())
}
}
if err := newSpace.Refresh(); err != nil {
if errors.IsNotFound(err) {
return nil, errors.Errorf("ProviderId %q not unique", providerId)
}
return nil, errors.Trace(err)
}
return nil, errors.Trace(err)
} else if err != nil {
return nil, err
}
return newSpace, nil
} | go | func (st *State) AddSpace(name string, providerId network.Id, subnets []string, isPublic bool) (newSpace *Space, err error) {
defer errors.DeferredAnnotatef(&err, "adding space %q", name)
if !names.IsValidSpace(name) {
return nil, errors.NewNotValid(nil, "invalid space name")
}
spaceDoc := spaceDoc{
Life: Alive,
Name: name,
IsPublic: isPublic,
ProviderId: string(providerId),
}
newSpace = &Space{doc: spaceDoc, st: st}
ops := []txn.Op{{
C: spacesC,
Id: name,
Assert: txn.DocMissing,
Insert: spaceDoc,
}}
if providerId != "" {
ops = append(ops, st.networkEntityGlobalKeyOp("space", providerId))
}
for _, subnetId := range subnets {
// TODO:(mfoord) once we have refcounting for subnets we should
// also assert that the refcount is zero as moving the space of a
// subnet in use is not permitted.
ops = append(ops, txn.Op{
C: subnetsC,
Id: subnetId,
Assert: bson.D{bson.DocElem{"fan-local-underlay", bson.D{{"$exists", false}}}},
Update: bson.D{{"$set", bson.D{{"space-name", name}}}},
})
}
if err := st.db().RunTransaction(ops); err == txn.ErrAborted {
if _, err := st.Space(name); err == nil {
return nil, errors.AlreadyExistsf("space %q", name)
}
for _, subnetId := range subnets {
subnet, err := st.Subnet(subnetId)
if errors.IsNotFound(err) {
return nil, err
}
if subnet.FanLocalUnderlay() != "" {
return nil, errors.Errorf("Can't set space for FAN subnet %q - it's always inherited from underlay", subnet.CIDR())
}
}
if err := newSpace.Refresh(); err != nil {
if errors.IsNotFound(err) {
return nil, errors.Errorf("ProviderId %q not unique", providerId)
}
return nil, errors.Trace(err)
}
return nil, errors.Trace(err)
} else if err != nil {
return nil, err
}
return newSpace, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"AddSpace",
"(",
"name",
"string",
",",
"providerId",
"network",
".",
"Id",
",",
"subnets",
"[",
"]",
"string",
",",
"isPublic",
"bool",
")",
"(",
"newSpace",
"*",
"Space",
",",
"err",
"error",
")",
"{",
"defer",
"errors",
".",
"DeferredAnnotatef",
"(",
"&",
"err",
",",
"\"",
"\"",
",",
"name",
")",
"\n",
"if",
"!",
"names",
".",
"IsValidSpace",
"(",
"name",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"NewNotValid",
"(",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"spaceDoc",
":=",
"spaceDoc",
"{",
"Life",
":",
"Alive",
",",
"Name",
":",
"name",
",",
"IsPublic",
":",
"isPublic",
",",
"ProviderId",
":",
"string",
"(",
"providerId",
")",
",",
"}",
"\n",
"newSpace",
"=",
"&",
"Space",
"{",
"doc",
":",
"spaceDoc",
",",
"st",
":",
"st",
"}",
"\n\n",
"ops",
":=",
"[",
"]",
"txn",
".",
"Op",
"{",
"{",
"C",
":",
"spacesC",
",",
"Id",
":",
"name",
",",
"Assert",
":",
"txn",
".",
"DocMissing",
",",
"Insert",
":",
"spaceDoc",
",",
"}",
"}",
"\n\n",
"if",
"providerId",
"!=",
"\"",
"\"",
"{",
"ops",
"=",
"append",
"(",
"ops",
",",
"st",
".",
"networkEntityGlobalKeyOp",
"(",
"\"",
"\"",
",",
"providerId",
")",
")",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"subnetId",
":=",
"range",
"subnets",
"{",
"// TODO:(mfoord) once we have refcounting for subnets we should",
"// also assert that the refcount is zero as moving the space of a",
"// subnet in use is not permitted.",
"ops",
"=",
"append",
"(",
"ops",
",",
"txn",
".",
"Op",
"{",
"C",
":",
"subnetsC",
",",
"Id",
":",
"subnetId",
",",
"Assert",
":",
"bson",
".",
"D",
"{",
"bson",
".",
"DocElem",
"{",
"\"",
"\"",
",",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"false",
"}",
"}",
"}",
"}",
",",
"Update",
":",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"name",
"}",
"}",
"}",
"}",
",",
"}",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"st",
".",
"db",
"(",
")",
".",
"RunTransaction",
"(",
"ops",
")",
";",
"err",
"==",
"txn",
".",
"ErrAborted",
"{",
"if",
"_",
",",
"err",
":=",
"st",
".",
"Space",
"(",
"name",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"AlreadyExistsf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"subnetId",
":=",
"range",
"subnets",
"{",
"subnet",
",",
"err",
":=",
"st",
".",
"Subnet",
"(",
"subnetId",
")",
"\n",
"if",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"subnet",
".",
"FanLocalUnderlay",
"(",
")",
"!=",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"subnet",
".",
"CIDR",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"err",
":=",
"newSpace",
".",
"Refresh",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"if",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"providerId",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"newSpace",
",",
"nil",
"\n",
"}"
] | // AddSpace creates and returns a new space. | [
"AddSpace",
"creates",
"and",
"returns",
"a",
"new",
"space",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/spaces.go#L84-L145 |
3,601 | juju/juju | state/spaces.go | Space | func (st *State) Space(name string) (*Space, error) {
spaces, closer := st.db().GetCollection(spacesC)
defer closer()
var doc spaceDoc
err := spaces.FindId(name).One(&doc)
if err == mgo.ErrNotFound {
return nil, errors.NotFoundf("space %q", name)
}
if err != nil {
return nil, errors.Annotatef(err, "cannot get space %q", name)
}
return &Space{st, doc}, nil
} | go | func (st *State) Space(name string) (*Space, error) {
spaces, closer := st.db().GetCollection(spacesC)
defer closer()
var doc spaceDoc
err := spaces.FindId(name).One(&doc)
if err == mgo.ErrNotFound {
return nil, errors.NotFoundf("space %q", name)
}
if err != nil {
return nil, errors.Annotatef(err, "cannot get space %q", name)
}
return &Space{st, doc}, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"Space",
"(",
"name",
"string",
")",
"(",
"*",
"Space",
",",
"error",
")",
"{",
"spaces",
",",
"closer",
":=",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"spacesC",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n\n",
"var",
"doc",
"spaceDoc",
"\n",
"err",
":=",
"spaces",
".",
"FindId",
"(",
"name",
")",
".",
"One",
"(",
"&",
"doc",
")",
"\n",
"if",
"err",
"==",
"mgo",
".",
"ErrNotFound",
"{",
"return",
"nil",
",",
"errors",
".",
"NotFoundf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"return",
"&",
"Space",
"{",
"st",
",",
"doc",
"}",
",",
"nil",
"\n",
"}"
] | // Space returns a space from state that matches the provided name. An error
// is returned if the space doesn't exist or if there was a problem accessing
// its information. | [
"Space",
"returns",
"a",
"space",
"from",
"state",
"that",
"matches",
"the",
"provided",
"name",
".",
"An",
"error",
"is",
"returned",
"if",
"the",
"space",
"doesn",
"t",
"exist",
"or",
"if",
"there",
"was",
"a",
"problem",
"accessing",
"its",
"information",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/spaces.go#L150-L163 |
3,602 | juju/juju | state/spaces.go | AllSpaces | func (st *State) AllSpaces() ([]*Space, error) {
spacesCollection, closer := st.db().GetCollection(spacesC)
defer closer()
docs := []spaceDoc{}
err := spacesCollection.Find(nil).All(&docs)
if err != nil {
return nil, errors.Annotatef(err, "cannot get all spaces")
}
spaces := make([]*Space, len(docs))
for i, doc := range docs {
spaces[i] = &Space{st: st, doc: doc}
}
return spaces, nil
} | go | func (st *State) AllSpaces() ([]*Space, error) {
spacesCollection, closer := st.db().GetCollection(spacesC)
defer closer()
docs := []spaceDoc{}
err := spacesCollection.Find(nil).All(&docs)
if err != nil {
return nil, errors.Annotatef(err, "cannot get all spaces")
}
spaces := make([]*Space, len(docs))
for i, doc := range docs {
spaces[i] = &Space{st: st, doc: doc}
}
return spaces, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"AllSpaces",
"(",
")",
"(",
"[",
"]",
"*",
"Space",
",",
"error",
")",
"{",
"spacesCollection",
",",
"closer",
":=",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"spacesC",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n\n",
"docs",
":=",
"[",
"]",
"spaceDoc",
"{",
"}",
"\n",
"err",
":=",
"spacesCollection",
".",
"Find",
"(",
"nil",
")",
".",
"All",
"(",
"&",
"docs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"spaces",
":=",
"make",
"(",
"[",
"]",
"*",
"Space",
",",
"len",
"(",
"docs",
")",
")",
"\n",
"for",
"i",
",",
"doc",
":=",
"range",
"docs",
"{",
"spaces",
"[",
"i",
"]",
"=",
"&",
"Space",
"{",
"st",
":",
"st",
",",
"doc",
":",
"doc",
"}",
"\n",
"}",
"\n",
"return",
"spaces",
",",
"nil",
"\n",
"}"
] | // AllSpaces returns all spaces for the model. | [
"AllSpaces",
"returns",
"all",
"spaces",
"for",
"the",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/spaces.go#L166-L180 |
3,603 | juju/juju | state/spaces.go | EnsureDead | func (s *Space) EnsureDead() (err error) {
defer errors.DeferredAnnotatef(&err, "cannot set space %q to dead", s)
if s.doc.Life == Dead {
return nil
}
ops := []txn.Op{{
C: spacesC,
Id: s.doc.Name,
Update: bson.D{{"$set", bson.D{{"life", Dead}}}},
Assert: isAliveDoc,
}}
txnErr := s.st.db().RunTransaction(ops)
if txnErr == nil {
s.doc.Life = Dead
return nil
}
return onAbort(txnErr, spaceNotAliveErr)
} | go | func (s *Space) EnsureDead() (err error) {
defer errors.DeferredAnnotatef(&err, "cannot set space %q to dead", s)
if s.doc.Life == Dead {
return nil
}
ops := []txn.Op{{
C: spacesC,
Id: s.doc.Name,
Update: bson.D{{"$set", bson.D{{"life", Dead}}}},
Assert: isAliveDoc,
}}
txnErr := s.st.db().RunTransaction(ops)
if txnErr == nil {
s.doc.Life = Dead
return nil
}
return onAbort(txnErr, spaceNotAliveErr)
} | [
"func",
"(",
"s",
"*",
"Space",
")",
"EnsureDead",
"(",
")",
"(",
"err",
"error",
")",
"{",
"defer",
"errors",
".",
"DeferredAnnotatef",
"(",
"&",
"err",
",",
"\"",
"\"",
",",
"s",
")",
"\n\n",
"if",
"s",
".",
"doc",
".",
"Life",
"==",
"Dead",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"ops",
":=",
"[",
"]",
"txn",
".",
"Op",
"{",
"{",
"C",
":",
"spacesC",
",",
"Id",
":",
"s",
".",
"doc",
".",
"Name",
",",
"Update",
":",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"Dead",
"}",
"}",
"}",
"}",
",",
"Assert",
":",
"isAliveDoc",
",",
"}",
"}",
"\n\n",
"txnErr",
":=",
"s",
".",
"st",
".",
"db",
"(",
")",
".",
"RunTransaction",
"(",
"ops",
")",
"\n",
"if",
"txnErr",
"==",
"nil",
"{",
"s",
".",
"doc",
".",
"Life",
"=",
"Dead",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"onAbort",
"(",
"txnErr",
",",
"spaceNotAliveErr",
")",
"\n",
"}"
] | // EnsureDead sets the Life of the space to Dead, if it's Alive. If the space is
// already Dead, no error is returned. When the space is no longer Alive or
// already removed, errNotAlive is returned. | [
"EnsureDead",
"sets",
"the",
"Life",
"of",
"the",
"space",
"to",
"Dead",
"if",
"it",
"s",
"Alive",
".",
"If",
"the",
"space",
"is",
"already",
"Dead",
"no",
"error",
"is",
"returned",
".",
"When",
"the",
"space",
"is",
"no",
"longer",
"Alive",
"or",
"already",
"removed",
"errNotAlive",
"is",
"returned",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/spaces.go#L185-L205 |
3,604 | juju/juju | state/spaces.go | Remove | func (s *Space) Remove() (err error) {
defer errors.DeferredAnnotatef(&err, "cannot remove space %q", s)
if s.doc.Life != Dead {
return errors.New("space is not dead")
}
ops := []txn.Op{{
C: spacesC,
Id: s.doc.Name,
Remove: true,
Assert: isDeadDoc,
}}
if s.ProviderId() != "" {
ops = append(ops, s.st.networkEntityGlobalKeyRemoveOp("space", s.ProviderId()))
}
txnErr := s.st.db().RunTransaction(ops)
if txnErr == nil {
return nil
}
return onAbort(txnErr, errors.New("not found or not dead"))
} | go | func (s *Space) Remove() (err error) {
defer errors.DeferredAnnotatef(&err, "cannot remove space %q", s)
if s.doc.Life != Dead {
return errors.New("space is not dead")
}
ops := []txn.Op{{
C: spacesC,
Id: s.doc.Name,
Remove: true,
Assert: isDeadDoc,
}}
if s.ProviderId() != "" {
ops = append(ops, s.st.networkEntityGlobalKeyRemoveOp("space", s.ProviderId()))
}
txnErr := s.st.db().RunTransaction(ops)
if txnErr == nil {
return nil
}
return onAbort(txnErr, errors.New("not found or not dead"))
} | [
"func",
"(",
"s",
"*",
"Space",
")",
"Remove",
"(",
")",
"(",
"err",
"error",
")",
"{",
"defer",
"errors",
".",
"DeferredAnnotatef",
"(",
"&",
"err",
",",
"\"",
"\"",
",",
"s",
")",
"\n\n",
"if",
"s",
".",
"doc",
".",
"Life",
"!=",
"Dead",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"ops",
":=",
"[",
"]",
"txn",
".",
"Op",
"{",
"{",
"C",
":",
"spacesC",
",",
"Id",
":",
"s",
".",
"doc",
".",
"Name",
",",
"Remove",
":",
"true",
",",
"Assert",
":",
"isDeadDoc",
",",
"}",
"}",
"\n",
"if",
"s",
".",
"ProviderId",
"(",
")",
"!=",
"\"",
"\"",
"{",
"ops",
"=",
"append",
"(",
"ops",
",",
"s",
".",
"st",
".",
"networkEntityGlobalKeyRemoveOp",
"(",
"\"",
"\"",
",",
"s",
".",
"ProviderId",
"(",
")",
")",
")",
"\n",
"}",
"\n\n",
"txnErr",
":=",
"s",
".",
"st",
".",
"db",
"(",
")",
".",
"RunTransaction",
"(",
"ops",
")",
"\n",
"if",
"txnErr",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"onAbort",
"(",
"txnErr",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
")",
"\n",
"}"
] | // Remove removes a Dead space. If the space is not Dead or it is already
// removed, an error is returned. | [
"Remove",
"removes",
"a",
"Dead",
"space",
".",
"If",
"the",
"space",
"is",
"not",
"Dead",
"or",
"it",
"is",
"already",
"removed",
"an",
"error",
"is",
"returned",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/spaces.go#L209-L231 |
3,605 | juju/juju | apiserver/common/mocks/upgradeseries.go | NewMockUpgradeSeriesBackend | func NewMockUpgradeSeriesBackend(ctrl *gomock.Controller) *MockUpgradeSeriesBackend {
mock := &MockUpgradeSeriesBackend{ctrl: ctrl}
mock.recorder = &MockUpgradeSeriesBackendMockRecorder{mock}
return mock
} | go | func NewMockUpgradeSeriesBackend(ctrl *gomock.Controller) *MockUpgradeSeriesBackend {
mock := &MockUpgradeSeriesBackend{ctrl: ctrl}
mock.recorder = &MockUpgradeSeriesBackendMockRecorder{mock}
return mock
} | [
"func",
"NewMockUpgradeSeriesBackend",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockUpgradeSeriesBackend",
"{",
"mock",
":=",
"&",
"MockUpgradeSeriesBackend",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockUpgradeSeriesBackendMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] | // NewMockUpgradeSeriesBackend creates a new mock instance | [
"NewMockUpgradeSeriesBackend",
"creates",
"a",
"new",
"mock",
"instance"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/mocks/upgradeseries.go#L28-L32 |
3,606 | juju/juju | apiserver/common/mocks/upgradeseries.go | NewMockUpgradeSeriesMachine | func NewMockUpgradeSeriesMachine(ctrl *gomock.Controller) *MockUpgradeSeriesMachine {
mock := &MockUpgradeSeriesMachine{ctrl: ctrl}
mock.recorder = &MockUpgradeSeriesMachineMockRecorder{mock}
return mock
} | go | func NewMockUpgradeSeriesMachine(ctrl *gomock.Controller) *MockUpgradeSeriesMachine {
mock := &MockUpgradeSeriesMachine{ctrl: ctrl}
mock.recorder = &MockUpgradeSeriesMachineMockRecorder{mock}
return mock
} | [
"func",
"NewMockUpgradeSeriesMachine",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockUpgradeSeriesMachine",
"{",
"mock",
":=",
"&",
"MockUpgradeSeriesMachine",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockUpgradeSeriesMachineMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] | // NewMockUpgradeSeriesMachine creates a new mock instance | [
"NewMockUpgradeSeriesMachine",
"creates",
"a",
"new",
"mock",
"instance"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/mocks/upgradeseries.go#L77-L81 |
3,607 | juju/juju | apiserver/common/mocks/upgradeseries.go | RemoveUpgradeSeriesLock | func (m *MockUpgradeSeriesMachine) RemoveUpgradeSeriesLock() error {
ret := m.ctrl.Call(m, "RemoveUpgradeSeriesLock")
ret0, _ := ret[0].(error)
return ret0
} | go | func (m *MockUpgradeSeriesMachine) RemoveUpgradeSeriesLock() error {
ret := m.ctrl.Call(m, "RemoveUpgradeSeriesLock")
ret0, _ := ret[0].(error)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockUpgradeSeriesMachine",
")",
"RemoveUpgradeSeriesLock",
"(",
")",
"error",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // RemoveUpgradeSeriesLock mocks base method | [
"RemoveUpgradeSeriesLock",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/mocks/upgradeseries.go#L89-L93 |
3,608 | juju/juju | apiserver/common/mocks/upgradeseries.go | RemoveUpgradeSeriesLock | func (mr *MockUpgradeSeriesMachineMockRecorder) RemoveUpgradeSeriesLock() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoveUpgradeSeriesLock", reflect.TypeOf((*MockUpgradeSeriesMachine)(nil).RemoveUpgradeSeriesLock))
} | go | func (mr *MockUpgradeSeriesMachineMockRecorder) RemoveUpgradeSeriesLock() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoveUpgradeSeriesLock", reflect.TypeOf((*MockUpgradeSeriesMachine)(nil).RemoveUpgradeSeriesLock))
} | [
"func",
"(",
"mr",
"*",
"MockUpgradeSeriesMachineMockRecorder",
")",
"RemoveUpgradeSeriesLock",
"(",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockUpgradeSeriesMachine",
")",
"(",
"nil",
")",
".",
"RemoveUpgradeSeriesLock",
")",
")",
"\n",
"}"
] | // RemoveUpgradeSeriesLock indicates an expected call of RemoveUpgradeSeriesLock | [
"RemoveUpgradeSeriesLock",
"indicates",
"an",
"expected",
"call",
"of",
"RemoveUpgradeSeriesLock"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/mocks/upgradeseries.go#L96-L98 |
3,609 | juju/juju | apiserver/common/mocks/upgradeseries.go | Series | func (m *MockUpgradeSeriesMachine) Series() string {
ret := m.ctrl.Call(m, "Series")
ret0, _ := ret[0].(string)
return ret0
} | go | func (m *MockUpgradeSeriesMachine) Series() string {
ret := m.ctrl.Call(m, "Series")
ret0, _ := ret[0].(string)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockUpgradeSeriesMachine",
")",
"Series",
"(",
")",
"string",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"string",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // Series mocks base method | [
"Series",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/mocks/upgradeseries.go#L101-L105 |
3,610 | juju/juju | apiserver/common/mocks/upgradeseries.go | SetUpgradeSeriesStatus | func (m *MockUpgradeSeriesMachine) SetUpgradeSeriesStatus(arg0 model.UpgradeSeriesStatus, arg1 string) error {
ret := m.ctrl.Call(m, "SetUpgradeSeriesStatus", arg0, arg1)
ret0, _ := ret[0].(error)
return ret0
} | go | func (m *MockUpgradeSeriesMachine) SetUpgradeSeriesStatus(arg0 model.UpgradeSeriesStatus, arg1 string) error {
ret := m.ctrl.Call(m, "SetUpgradeSeriesStatus", arg0, arg1)
ret0, _ := ret[0].(error)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockUpgradeSeriesMachine",
")",
"SetUpgradeSeriesStatus",
"(",
"arg0",
"model",
".",
"UpgradeSeriesStatus",
",",
"arg1",
"string",
")",
"error",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
",",
"arg1",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // SetUpgradeSeriesStatus mocks base method | [
"SetUpgradeSeriesStatus",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/mocks/upgradeseries.go#L113-L117 |
3,611 | juju/juju | apiserver/common/mocks/upgradeseries.go | StartUpgradeSeriesUnitCompletion | func (m *MockUpgradeSeriesMachine) StartUpgradeSeriesUnitCompletion(arg0 string) error {
ret := m.ctrl.Call(m, "StartUpgradeSeriesUnitCompletion", arg0)
ret0, _ := ret[0].(error)
return ret0
} | go | func (m *MockUpgradeSeriesMachine) StartUpgradeSeriesUnitCompletion(arg0 string) error {
ret := m.ctrl.Call(m, "StartUpgradeSeriesUnitCompletion", arg0)
ret0, _ := ret[0].(error)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockUpgradeSeriesMachine",
")",
"StartUpgradeSeriesUnitCompletion",
"(",
"arg0",
"string",
")",
"error",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // StartUpgradeSeriesUnitCompletion mocks base method | [
"StartUpgradeSeriesUnitCompletion",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/mocks/upgradeseries.go#L125-L129 |
3,612 | juju/juju | apiserver/common/mocks/upgradeseries.go | UpdateMachineSeries | func (m *MockUpgradeSeriesMachine) UpdateMachineSeries(arg0 string, arg1 bool) error {
ret := m.ctrl.Call(m, "UpdateMachineSeries", arg0, arg1)
ret0, _ := ret[0].(error)
return ret0
} | go | func (m *MockUpgradeSeriesMachine) UpdateMachineSeries(arg0 string, arg1 bool) error {
ret := m.ctrl.Call(m, "UpdateMachineSeries", arg0, arg1)
ret0, _ := ret[0].(error)
return ret0
} | [
"func",
"(",
"m",
"*",
"MockUpgradeSeriesMachine",
")",
"UpdateMachineSeries",
"(",
"arg0",
"string",
",",
"arg1",
"bool",
")",
"error",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
",",
"arg1",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
"\n",
"}"
] | // UpdateMachineSeries mocks base method | [
"UpdateMachineSeries",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/mocks/upgradeseries.go#L150-L154 |
3,613 | juju/juju | apiserver/common/mocks/upgradeseries.go | UpgradeSeriesStatus | func (m *MockUpgradeSeriesMachine) UpgradeSeriesStatus() (model.UpgradeSeriesStatus, error) {
ret := m.ctrl.Call(m, "UpgradeSeriesStatus")
ret0, _ := ret[0].(model.UpgradeSeriesStatus)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockUpgradeSeriesMachine) UpgradeSeriesStatus() (model.UpgradeSeriesStatus, error) {
ret := m.ctrl.Call(m, "UpgradeSeriesStatus")
ret0, _ := ret[0].(model.UpgradeSeriesStatus)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockUpgradeSeriesMachine",
")",
"UpgradeSeriesStatus",
"(",
")",
"(",
"model",
".",
"UpgradeSeriesStatus",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"model",
".",
"UpgradeSeriesStatus",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // UpgradeSeriesStatus mocks base method | [
"UpgradeSeriesStatus",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/mocks/upgradeseries.go#L162-L167 |
3,614 | juju/juju | apiserver/common/mocks/upgradeseries.go | UpgradeSeriesTarget | func (m *MockUpgradeSeriesMachine) UpgradeSeriesTarget() (string, error) {
ret := m.ctrl.Call(m, "UpgradeSeriesTarget")
ret0, _ := ret[0].(string)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockUpgradeSeriesMachine) UpgradeSeriesTarget() (string, error) {
ret := m.ctrl.Call(m, "UpgradeSeriesTarget")
ret0, _ := ret[0].(string)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockUpgradeSeriesMachine",
")",
"UpgradeSeriesTarget",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"string",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // UpgradeSeriesTarget mocks base method | [
"UpgradeSeriesTarget",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/mocks/upgradeseries.go#L175-L180 |
3,615 | juju/juju | apiserver/common/mocks/upgradeseries.go | UpgradeSeriesUnitStatuses | func (m *MockUpgradeSeriesMachine) UpgradeSeriesUnitStatuses() (map[string]state.UpgradeSeriesUnitStatus, error) {
ret := m.ctrl.Call(m, "UpgradeSeriesUnitStatuses")
ret0, _ := ret[0].(map[string]state.UpgradeSeriesUnitStatus)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockUpgradeSeriesMachine) UpgradeSeriesUnitStatuses() (map[string]state.UpgradeSeriesUnitStatus, error) {
ret := m.ctrl.Call(m, "UpgradeSeriesUnitStatuses")
ret0, _ := ret[0].(map[string]state.UpgradeSeriesUnitStatus)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockUpgradeSeriesMachine",
")",
"UpgradeSeriesUnitStatuses",
"(",
")",
"(",
"map",
"[",
"string",
"]",
"state",
".",
"UpgradeSeriesUnitStatus",
",",
"error",
")",
"{",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"map",
"[",
"string",
"]",
"state",
".",
"UpgradeSeriesUnitStatus",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // UpgradeSeriesUnitStatuses mocks base method | [
"UpgradeSeriesUnitStatuses",
"mocks",
"base",
"method"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/mocks/upgradeseries.go#L188-L193 |
3,616 | juju/juju | apiserver/common/mocks/upgradeseries.go | NewMockUpgradeSeriesUnit | func NewMockUpgradeSeriesUnit(ctrl *gomock.Controller) *MockUpgradeSeriesUnit {
mock := &MockUpgradeSeriesUnit{ctrl: ctrl}
mock.recorder = &MockUpgradeSeriesUnitMockRecorder{mock}
return mock
} | go | func NewMockUpgradeSeriesUnit(ctrl *gomock.Controller) *MockUpgradeSeriesUnit {
mock := &MockUpgradeSeriesUnit{ctrl: ctrl}
mock.recorder = &MockUpgradeSeriesUnitMockRecorder{mock}
return mock
} | [
"func",
"NewMockUpgradeSeriesUnit",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockUpgradeSeriesUnit",
"{",
"mock",
":=",
"&",
"MockUpgradeSeriesUnit",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockUpgradeSeriesUnitMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] | // NewMockUpgradeSeriesUnit creates a new mock instance | [
"NewMockUpgradeSeriesUnit",
"creates",
"a",
"new",
"mock",
"instance"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/mocks/upgradeseries.go#L225-L229 |
3,617 | juju/juju | apiserver/common/mocks/upgradeseries.go | UpgradeSeriesStatus | func (mr *MockUpgradeSeriesUnitMockRecorder) UpgradeSeriesStatus() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpgradeSeriesStatus", reflect.TypeOf((*MockUpgradeSeriesUnit)(nil).UpgradeSeriesStatus))
} | go | func (mr *MockUpgradeSeriesUnitMockRecorder) UpgradeSeriesStatus() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpgradeSeriesStatus", reflect.TypeOf((*MockUpgradeSeriesUnit)(nil).UpgradeSeriesStatus))
} | [
"func",
"(",
"mr",
"*",
"MockUpgradeSeriesUnitMockRecorder",
")",
"UpgradeSeriesStatus",
"(",
")",
"*",
"gomock",
".",
"Call",
"{",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockUpgradeSeriesUnit",
")",
"(",
"nil",
")",
".",
"UpgradeSeriesStatus",
")",
")",
"\n",
"}"
] | // UpgradeSeriesStatus indicates an expected call of UpgradeSeriesStatus | [
"UpgradeSeriesStatus",
"indicates",
"an",
"expected",
"call",
"of",
"UpgradeSeriesStatus"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/mocks/upgradeseries.go#L282-L284 |
3,618 | juju/juju | caas/broker.go | RegisterContainerProvider | func RegisterContainerProvider(name string, p ContainerEnvironProvider, alias ...string) (unregister func()) {
if err := environs.GlobalProviderRegistry().RegisterProvider(p, name, alias...); err != nil {
panic(fmt.Errorf("juju: %v", err))
}
return func() {
environs.GlobalProviderRegistry().UnregisterProvider(name)
}
} | go | func RegisterContainerProvider(name string, p ContainerEnvironProvider, alias ...string) (unregister func()) {
if err := environs.GlobalProviderRegistry().RegisterProvider(p, name, alias...); err != nil {
panic(fmt.Errorf("juju: %v", err))
}
return func() {
environs.GlobalProviderRegistry().UnregisterProvider(name)
}
} | [
"func",
"RegisterContainerProvider",
"(",
"name",
"string",
",",
"p",
"ContainerEnvironProvider",
",",
"alias",
"...",
"string",
")",
"(",
"unregister",
"func",
"(",
")",
")",
"{",
"if",
"err",
":=",
"environs",
".",
"GlobalProviderRegistry",
"(",
")",
".",
"RegisterProvider",
"(",
"p",
",",
"name",
",",
"alias",
"...",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
")",
"\n",
"}",
"\n",
"return",
"func",
"(",
")",
"{",
"environs",
".",
"GlobalProviderRegistry",
"(",
")",
".",
"UnregisterProvider",
"(",
"name",
")",
"\n",
"}",
"\n",
"}"
] | // RegisterContainerProvider is used for providers that we want to use for managing 'instances',
// but are not possible sources for 'juju bootstrap'. | [
"RegisterContainerProvider",
"is",
"used",
"for",
"providers",
"that",
"we",
"want",
"to",
"use",
"for",
"managing",
"instances",
"but",
"are",
"not",
"possible",
"sources",
"for",
"juju",
"bootstrap",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/caas/broker.go#L41-L48 |
3,619 | juju/juju | caas/broker.go | Open | func Open(p environs.EnvironProvider, args environs.OpenParams) (Broker, error) {
if envProvider, ok := p.(ContainerEnvironProvider); !ok {
return nil, errors.NotValidf("container environ provider %T", p)
} else {
return envProvider.Open(args)
}
} | go | func Open(p environs.EnvironProvider, args environs.OpenParams) (Broker, error) {
if envProvider, ok := p.(ContainerEnvironProvider); !ok {
return nil, errors.NotValidf("container environ provider %T", p)
} else {
return envProvider.Open(args)
}
} | [
"func",
"Open",
"(",
"p",
"environs",
".",
"EnvironProvider",
",",
"args",
"environs",
".",
"OpenParams",
")",
"(",
"Broker",
",",
"error",
")",
"{",
"if",
"envProvider",
",",
"ok",
":=",
"p",
".",
"(",
"ContainerEnvironProvider",
")",
";",
"!",
"ok",
"{",
"return",
"nil",
",",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
",",
"p",
")",
"\n",
"}",
"else",
"{",
"return",
"envProvider",
".",
"Open",
"(",
"args",
")",
"\n",
"}",
"\n",
"}"
] | // Open creates a Broker instance and errors if the provider is not for
// a container substrate. | [
"Open",
"creates",
"a",
"Broker",
"instance",
"and",
"errors",
"if",
"the",
"provider",
"is",
"not",
"for",
"a",
"container",
"substrate",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/caas/broker.go#L61-L67 |
3,620 | juju/juju | apiserver/facades/client/application/deploy.go | DeployApplication | func DeployApplication(st ApplicationDeployer, args DeployApplicationParams) (Application, error) {
charmConfig, err := args.Charm.Config().ValidateSettings(args.CharmConfig)
if err != nil {
return nil, errors.Trace(err)
}
if args.Charm.Meta().Subordinate {
if args.NumUnits != 0 {
return nil, fmt.Errorf("subordinate application must be deployed without units")
}
if !constraints.IsEmpty(&args.Constraints) {
return nil, fmt.Errorf("subordinate application must be deployed without constraints")
}
}
// TODO(fwereade): transactional State.AddApplication including settings, constraints
// (minimumUnitCount, initialMachineIds?).
effectiveBindings, err := getEffectiveBindingsForCharmMeta(args.Charm.Meta(), args.EndpointBindings)
if err != nil {
return nil, errors.Trace(err)
}
asa := state.AddApplicationArgs{
Name: args.ApplicationName,
Series: args.Series,
Charm: args.Charm,
Channel: args.Channel,
Storage: stateStorageConstraints(args.Storage),
Devices: stateDeviceConstraints(args.Devices),
AttachStorage: args.AttachStorage,
ApplicationConfig: args.ApplicationConfig,
CharmConfig: charmConfig,
NumUnits: args.NumUnits,
Placement: args.Placement,
Resources: args.Resources,
EndpointBindings: effectiveBindings,
}
if !args.Charm.Meta().Subordinate {
asa.Constraints = args.Constraints
}
return st.AddApplication(asa)
} | go | func DeployApplication(st ApplicationDeployer, args DeployApplicationParams) (Application, error) {
charmConfig, err := args.Charm.Config().ValidateSettings(args.CharmConfig)
if err != nil {
return nil, errors.Trace(err)
}
if args.Charm.Meta().Subordinate {
if args.NumUnits != 0 {
return nil, fmt.Errorf("subordinate application must be deployed without units")
}
if !constraints.IsEmpty(&args.Constraints) {
return nil, fmt.Errorf("subordinate application must be deployed without constraints")
}
}
// TODO(fwereade): transactional State.AddApplication including settings, constraints
// (minimumUnitCount, initialMachineIds?).
effectiveBindings, err := getEffectiveBindingsForCharmMeta(args.Charm.Meta(), args.EndpointBindings)
if err != nil {
return nil, errors.Trace(err)
}
asa := state.AddApplicationArgs{
Name: args.ApplicationName,
Series: args.Series,
Charm: args.Charm,
Channel: args.Channel,
Storage: stateStorageConstraints(args.Storage),
Devices: stateDeviceConstraints(args.Devices),
AttachStorage: args.AttachStorage,
ApplicationConfig: args.ApplicationConfig,
CharmConfig: charmConfig,
NumUnits: args.NumUnits,
Placement: args.Placement,
Resources: args.Resources,
EndpointBindings: effectiveBindings,
}
if !args.Charm.Meta().Subordinate {
asa.Constraints = args.Constraints
}
return st.AddApplication(asa)
} | [
"func",
"DeployApplication",
"(",
"st",
"ApplicationDeployer",
",",
"args",
"DeployApplicationParams",
")",
"(",
"Application",
",",
"error",
")",
"{",
"charmConfig",
",",
"err",
":=",
"args",
".",
"Charm",
".",
"Config",
"(",
")",
".",
"ValidateSettings",
"(",
"args",
".",
"CharmConfig",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"args",
".",
"Charm",
".",
"Meta",
"(",
")",
".",
"Subordinate",
"{",
"if",
"args",
".",
"NumUnits",
"!=",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"!",
"constraints",
".",
"IsEmpty",
"(",
"&",
"args",
".",
"Constraints",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"// TODO(fwereade): transactional State.AddApplication including settings, constraints",
"// (minimumUnitCount, initialMachineIds?).",
"effectiveBindings",
",",
"err",
":=",
"getEffectiveBindingsForCharmMeta",
"(",
"args",
".",
"Charm",
".",
"Meta",
"(",
")",
",",
"args",
".",
"EndpointBindings",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"asa",
":=",
"state",
".",
"AddApplicationArgs",
"{",
"Name",
":",
"args",
".",
"ApplicationName",
",",
"Series",
":",
"args",
".",
"Series",
",",
"Charm",
":",
"args",
".",
"Charm",
",",
"Channel",
":",
"args",
".",
"Channel",
",",
"Storage",
":",
"stateStorageConstraints",
"(",
"args",
".",
"Storage",
")",
",",
"Devices",
":",
"stateDeviceConstraints",
"(",
"args",
".",
"Devices",
")",
",",
"AttachStorage",
":",
"args",
".",
"AttachStorage",
",",
"ApplicationConfig",
":",
"args",
".",
"ApplicationConfig",
",",
"CharmConfig",
":",
"charmConfig",
",",
"NumUnits",
":",
"args",
".",
"NumUnits",
",",
"Placement",
":",
"args",
".",
"Placement",
",",
"Resources",
":",
"args",
".",
"Resources",
",",
"EndpointBindings",
":",
"effectiveBindings",
",",
"}",
"\n\n",
"if",
"!",
"args",
".",
"Charm",
".",
"Meta",
"(",
")",
".",
"Subordinate",
"{",
"asa",
".",
"Constraints",
"=",
"args",
".",
"Constraints",
"\n",
"}",
"\n",
"return",
"st",
".",
"AddApplication",
"(",
"asa",
")",
"\n",
"}"
] | // DeployApplication takes a charm and various parameters and deploys it. | [
"DeployApplication",
"takes",
"a",
"charm",
"and",
"various",
"parameters",
"and",
"deploys",
"it",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/deploy.go#L56-L97 |
3,621 | juju/juju | apiserver/facades/client/application/deploy.go | addUnits | func addUnits(
unitAdder UnitAdder,
appName string,
n int,
placement []*instance.Placement,
attachStorage []names.StorageTag,
assignUnits bool,
) ([]Unit, error) {
units := make([]Unit, n)
// Hard code for now till we implement a different approach.
policy := state.AssignCleanEmpty
// TODO what do we do if we fail half-way through this process?
for i := 0; i < n; i++ {
unit, err := unitAdder.AddUnit(state.AddUnitParams{
AttachStorage: attachStorage,
})
if err != nil {
return nil, errors.Annotatef(err, "cannot add unit %d/%d to application %q", i+1, n, appName)
}
units[i] = unit
if !assignUnits {
continue
}
// Are there still placement directives to use?
if i > len(placement)-1 {
if err := unit.AssignWithPolicy(policy); err != nil {
return nil, errors.Trace(err)
}
continue
}
if err := unit.AssignWithPlacement(placement[i]); err != nil {
return nil, errors.Annotatef(err, "acquiring machine to host unit %q", unit.UnitTag().Id())
}
}
return units, nil
} | go | func addUnits(
unitAdder UnitAdder,
appName string,
n int,
placement []*instance.Placement,
attachStorage []names.StorageTag,
assignUnits bool,
) ([]Unit, error) {
units := make([]Unit, n)
// Hard code for now till we implement a different approach.
policy := state.AssignCleanEmpty
// TODO what do we do if we fail half-way through this process?
for i := 0; i < n; i++ {
unit, err := unitAdder.AddUnit(state.AddUnitParams{
AttachStorage: attachStorage,
})
if err != nil {
return nil, errors.Annotatef(err, "cannot add unit %d/%d to application %q", i+1, n, appName)
}
units[i] = unit
if !assignUnits {
continue
}
// Are there still placement directives to use?
if i > len(placement)-1 {
if err := unit.AssignWithPolicy(policy); err != nil {
return nil, errors.Trace(err)
}
continue
}
if err := unit.AssignWithPlacement(placement[i]); err != nil {
return nil, errors.Annotatef(err, "acquiring machine to host unit %q", unit.UnitTag().Id())
}
}
return units, nil
} | [
"func",
"addUnits",
"(",
"unitAdder",
"UnitAdder",
",",
"appName",
"string",
",",
"n",
"int",
",",
"placement",
"[",
"]",
"*",
"instance",
".",
"Placement",
",",
"attachStorage",
"[",
"]",
"names",
".",
"StorageTag",
",",
"assignUnits",
"bool",
",",
")",
"(",
"[",
"]",
"Unit",
",",
"error",
")",
"{",
"units",
":=",
"make",
"(",
"[",
"]",
"Unit",
",",
"n",
")",
"\n",
"// Hard code for now till we implement a different approach.",
"policy",
":=",
"state",
".",
"AssignCleanEmpty",
"\n",
"// TODO what do we do if we fail half-way through this process?",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"n",
";",
"i",
"++",
"{",
"unit",
",",
"err",
":=",
"unitAdder",
".",
"AddUnit",
"(",
"state",
".",
"AddUnitParams",
"{",
"AttachStorage",
":",
"attachStorage",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"i",
"+",
"1",
",",
"n",
",",
"appName",
")",
"\n",
"}",
"\n",
"units",
"[",
"i",
"]",
"=",
"unit",
"\n",
"if",
"!",
"assignUnits",
"{",
"continue",
"\n",
"}",
"\n\n",
"// Are there still placement directives to use?",
"if",
"i",
">",
"len",
"(",
"placement",
")",
"-",
"1",
"{",
"if",
"err",
":=",
"unit",
".",
"AssignWithPolicy",
"(",
"policy",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"continue",
"\n",
"}",
"\n",
"if",
"err",
":=",
"unit",
".",
"AssignWithPlacement",
"(",
"placement",
"[",
"i",
"]",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"unit",
".",
"UnitTag",
"(",
")",
".",
"Id",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"units",
",",
"nil",
"\n",
"}"
] | // addUnits starts n units of the given application using the specified placement
// directives to allocate the machines. | [
"addUnits",
"starts",
"n",
"units",
"of",
"the",
"given",
"application",
"using",
"the",
"specified",
"placement",
"directives",
"to",
"allocate",
"the",
"machines",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/application/deploy.go#L165-L201 |
3,622 | juju/juju | cmd/jujud/agent/bootstrap.go | Info | func (c *BootstrapCommand) Info() *cmd.Info {
return jujucmd.Info(&cmd.Info{
Name: "bootstrap-state",
Purpose: "initialize juju state",
})
} | go | func (c *BootstrapCommand) Info() *cmd.Info {
return jujucmd.Info(&cmd.Info{
Name: "bootstrap-state",
Purpose: "initialize juju state",
})
} | [
"func",
"(",
"c",
"*",
"BootstrapCommand",
")",
"Info",
"(",
")",
"*",
"cmd",
".",
"Info",
"{",
"return",
"jujucmd",
".",
"Info",
"(",
"&",
"cmd",
".",
"Info",
"{",
"Name",
":",
"\"",
"\"",
",",
"Purpose",
":",
"\"",
"\"",
",",
"}",
")",
"\n",
"}"
] | // Info returns a description of the command. | [
"Info",
"returns",
"a",
"description",
"of",
"the",
"command",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/jujud/agent/bootstrap.go#L78-L83 |
3,623 | juju/juju | cmd/jujud/agent/bootstrap.go | SetFlags | func (c *BootstrapCommand) SetFlags(f *gnuflag.FlagSet) {
c.AgentConf.AddFlags(f)
f.DurationVar(&c.Timeout, "timeout", time.Duration(0), "set the bootstrap timeout")
} | go | func (c *BootstrapCommand) SetFlags(f *gnuflag.FlagSet) {
c.AgentConf.AddFlags(f)
f.DurationVar(&c.Timeout, "timeout", time.Duration(0), "set the bootstrap timeout")
} | [
"func",
"(",
"c",
"*",
"BootstrapCommand",
")",
"SetFlags",
"(",
"f",
"*",
"gnuflag",
".",
"FlagSet",
")",
"{",
"c",
".",
"AgentConf",
".",
"AddFlags",
"(",
"f",
")",
"\n",
"f",
".",
"DurationVar",
"(",
"&",
"c",
".",
"Timeout",
",",
"\"",
"\"",
",",
"time",
".",
"Duration",
"(",
"0",
")",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // SetFlags adds the flags for this command to the passed gnuflag.FlagSet. | [
"SetFlags",
"adds",
"the",
"flags",
"for",
"this",
"command",
"to",
"the",
"passed",
"gnuflag",
".",
"FlagSet",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/jujud/agent/bootstrap.go#L86-L89 |
3,624 | juju/juju | cmd/jujud/agent/bootstrap.go | populateTools | func (c *BootstrapCommand) populateTools(st *state.State, env environs.BootstrapEnviron) error {
agentConfig := c.CurrentConfig()
dataDir := agentConfig.DataDir()
hostSeries, err := series.HostSeries()
if err != nil {
return errors.Trace(err)
}
current := version.Binary{
Number: jujuversion.Current,
Arch: arch.HostArch(),
Series: hostSeries,
}
tools, err := agenttools.ReadTools(dataDir, current)
if err != nil {
return errors.Trace(err)
}
data, err := ioutil.ReadFile(filepath.Join(
agenttools.SharedToolsDir(dataDir, current),
"tools.tar.gz",
))
if err != nil {
return errors.Trace(err)
}
toolstorage, err := st.ToolsStorage()
if err != nil {
return errors.Trace(err)
}
defer toolstorage.Close()
var toolsVersions []version.Binary
if strings.HasPrefix(tools.URL, "file://") {
// Tools were uploaded: clone for each series of the same OS.
os, err := series.GetOSFromSeries(tools.Version.Series)
if err != nil {
return errors.Trace(err)
}
osSeries := series.OSSupportedSeries(os)
for _, series := range osSeries {
toolsVersion := tools.Version
toolsVersion.Series = series
toolsVersions = append(toolsVersions, toolsVersion)
}
} else {
// Tools were downloaded from an external source: don't clone.
toolsVersions = []version.Binary{tools.Version}
}
for _, toolsVersion := range toolsVersions {
metadata := binarystorage.Metadata{
Version: toolsVersion.String(),
Size: tools.Size,
SHA256: tools.SHA256,
}
logger.Debugf("Adding agent binaries: %v", toolsVersion)
if err := toolstorage.Add(bytes.NewReader(data), metadata); err != nil {
return errors.Trace(err)
}
}
return nil
} | go | func (c *BootstrapCommand) populateTools(st *state.State, env environs.BootstrapEnviron) error {
agentConfig := c.CurrentConfig()
dataDir := agentConfig.DataDir()
hostSeries, err := series.HostSeries()
if err != nil {
return errors.Trace(err)
}
current := version.Binary{
Number: jujuversion.Current,
Arch: arch.HostArch(),
Series: hostSeries,
}
tools, err := agenttools.ReadTools(dataDir, current)
if err != nil {
return errors.Trace(err)
}
data, err := ioutil.ReadFile(filepath.Join(
agenttools.SharedToolsDir(dataDir, current),
"tools.tar.gz",
))
if err != nil {
return errors.Trace(err)
}
toolstorage, err := st.ToolsStorage()
if err != nil {
return errors.Trace(err)
}
defer toolstorage.Close()
var toolsVersions []version.Binary
if strings.HasPrefix(tools.URL, "file://") {
// Tools were uploaded: clone for each series of the same OS.
os, err := series.GetOSFromSeries(tools.Version.Series)
if err != nil {
return errors.Trace(err)
}
osSeries := series.OSSupportedSeries(os)
for _, series := range osSeries {
toolsVersion := tools.Version
toolsVersion.Series = series
toolsVersions = append(toolsVersions, toolsVersion)
}
} else {
// Tools were downloaded from an external source: don't clone.
toolsVersions = []version.Binary{tools.Version}
}
for _, toolsVersion := range toolsVersions {
metadata := binarystorage.Metadata{
Version: toolsVersion.String(),
Size: tools.Size,
SHA256: tools.SHA256,
}
logger.Debugf("Adding agent binaries: %v", toolsVersion)
if err := toolstorage.Add(bytes.NewReader(data), metadata); err != nil {
return errors.Trace(err)
}
}
return nil
} | [
"func",
"(",
"c",
"*",
"BootstrapCommand",
")",
"populateTools",
"(",
"st",
"*",
"state",
".",
"State",
",",
"env",
"environs",
".",
"BootstrapEnviron",
")",
"error",
"{",
"agentConfig",
":=",
"c",
".",
"CurrentConfig",
"(",
")",
"\n",
"dataDir",
":=",
"agentConfig",
".",
"DataDir",
"(",
")",
"\n\n",
"hostSeries",
",",
"err",
":=",
"series",
".",
"HostSeries",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"current",
":=",
"version",
".",
"Binary",
"{",
"Number",
":",
"jujuversion",
".",
"Current",
",",
"Arch",
":",
"arch",
".",
"HostArch",
"(",
")",
",",
"Series",
":",
"hostSeries",
",",
"}",
"\n",
"tools",
",",
"err",
":=",
"agenttools",
".",
"ReadTools",
"(",
"dataDir",
",",
"current",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"filepath",
".",
"Join",
"(",
"agenttools",
".",
"SharedToolsDir",
"(",
"dataDir",
",",
"current",
")",
",",
"\"",
"\"",
",",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"toolstorage",
",",
"err",
":=",
"st",
".",
"ToolsStorage",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"defer",
"toolstorage",
".",
"Close",
"(",
")",
"\n\n",
"var",
"toolsVersions",
"[",
"]",
"version",
".",
"Binary",
"\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"tools",
".",
"URL",
",",
"\"",
"\"",
")",
"{",
"// Tools were uploaded: clone for each series of the same OS.",
"os",
",",
"err",
":=",
"series",
".",
"GetOSFromSeries",
"(",
"tools",
".",
"Version",
".",
"Series",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"osSeries",
":=",
"series",
".",
"OSSupportedSeries",
"(",
"os",
")",
"\n",
"for",
"_",
",",
"series",
":=",
"range",
"osSeries",
"{",
"toolsVersion",
":=",
"tools",
".",
"Version",
"\n",
"toolsVersion",
".",
"Series",
"=",
"series",
"\n",
"toolsVersions",
"=",
"append",
"(",
"toolsVersions",
",",
"toolsVersion",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"// Tools were downloaded from an external source: don't clone.",
"toolsVersions",
"=",
"[",
"]",
"version",
".",
"Binary",
"{",
"tools",
".",
"Version",
"}",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"toolsVersion",
":=",
"range",
"toolsVersions",
"{",
"metadata",
":=",
"binarystorage",
".",
"Metadata",
"{",
"Version",
":",
"toolsVersion",
".",
"String",
"(",
")",
",",
"Size",
":",
"tools",
".",
"Size",
",",
"SHA256",
":",
"tools",
".",
"SHA256",
",",
"}",
"\n",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"toolsVersion",
")",
"\n",
"if",
"err",
":=",
"toolstorage",
".",
"Add",
"(",
"bytes",
".",
"NewReader",
"(",
"data",
")",
",",
"metadata",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // populateTools stores uploaded tools in provider storage
// and updates the tools metadata. | [
"populateTools",
"stores",
"uploaded",
"tools",
"in",
"provider",
"storage",
"and",
"updates",
"the",
"tools",
"metadata",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/jujud/agent/bootstrap.go#L517-L579 |
3,625 | juju/juju | cmd/jujud/agent/bootstrap.go | populateGUIArchive | func (c *BootstrapCommand) populateGUIArchive(st *state.State, env environs.BootstrapEnviron) error {
agentConfig := c.CurrentConfig()
dataDir := agentConfig.DataDir()
guistorage, err := st.GUIStorage()
if err != nil {
return errors.Trace(err)
}
defer guistorage.Close()
gui, err := agenttools.ReadGUIArchive(dataDir)
if err != nil {
return errors.Annotate(err, "cannot fetch GUI info")
}
f, err := os.Open(filepath.Join(agenttools.SharedGUIDir(dataDir), "gui.tar.bz2"))
if err != nil {
return errors.Annotate(err, "cannot read GUI archive")
}
defer f.Close()
if err := guistorage.Add(f, binarystorage.Metadata{
Version: gui.Version.String(),
Size: gui.Size,
SHA256: gui.SHA256,
}); err != nil {
return errors.Annotate(err, "cannot store GUI archive")
}
if err = st.GUISetVersion(gui.Version); err != nil {
return errors.Annotate(err, "cannot set current GUI version")
}
return nil
} | go | func (c *BootstrapCommand) populateGUIArchive(st *state.State, env environs.BootstrapEnviron) error {
agentConfig := c.CurrentConfig()
dataDir := agentConfig.DataDir()
guistorage, err := st.GUIStorage()
if err != nil {
return errors.Trace(err)
}
defer guistorage.Close()
gui, err := agenttools.ReadGUIArchive(dataDir)
if err != nil {
return errors.Annotate(err, "cannot fetch GUI info")
}
f, err := os.Open(filepath.Join(agenttools.SharedGUIDir(dataDir), "gui.tar.bz2"))
if err != nil {
return errors.Annotate(err, "cannot read GUI archive")
}
defer f.Close()
if err := guistorage.Add(f, binarystorage.Metadata{
Version: gui.Version.String(),
Size: gui.Size,
SHA256: gui.SHA256,
}); err != nil {
return errors.Annotate(err, "cannot store GUI archive")
}
if err = st.GUISetVersion(gui.Version); err != nil {
return errors.Annotate(err, "cannot set current GUI version")
}
return nil
} | [
"func",
"(",
"c",
"*",
"BootstrapCommand",
")",
"populateGUIArchive",
"(",
"st",
"*",
"state",
".",
"State",
",",
"env",
"environs",
".",
"BootstrapEnviron",
")",
"error",
"{",
"agentConfig",
":=",
"c",
".",
"CurrentConfig",
"(",
")",
"\n",
"dataDir",
":=",
"agentConfig",
".",
"DataDir",
"(",
")",
"\n",
"guistorage",
",",
"err",
":=",
"st",
".",
"GUIStorage",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"defer",
"guistorage",
".",
"Close",
"(",
")",
"\n",
"gui",
",",
"err",
":=",
"agenttools",
".",
"ReadGUIArchive",
"(",
"dataDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"filepath",
".",
"Join",
"(",
"agenttools",
".",
"SharedGUIDir",
"(",
"dataDir",
")",
",",
"\"",
"\"",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
":=",
"guistorage",
".",
"Add",
"(",
"f",
",",
"binarystorage",
".",
"Metadata",
"{",
"Version",
":",
"gui",
".",
"Version",
".",
"String",
"(",
")",
",",
"Size",
":",
"gui",
".",
"Size",
",",
"SHA256",
":",
"gui",
".",
"SHA256",
",",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"err",
"=",
"st",
".",
"GUISetVersion",
"(",
"gui",
".",
"Version",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // populateGUIArchive stores the uploaded Juju GUI archive in provider storage,
// updates the GUI metadata and set the current Juju GUI version. | [
"populateGUIArchive",
"stores",
"the",
"uploaded",
"Juju",
"GUI",
"archive",
"in",
"provider",
"storage",
"updates",
"the",
"GUI",
"metadata",
"and",
"set",
"the",
"current",
"Juju",
"GUI",
"version",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/jujud/agent/bootstrap.go#L583-L611 |
3,626 | juju/juju | cmd/jujud/agent/bootstrap.go | saveCustomImageMetadata | func (c *BootstrapCommand) saveCustomImageMetadata(st *state.State, env environs.BootstrapEnviron, imageMetadata []*imagemetadata.ImageMetadata) error {
logger.Debugf("saving custom image metadata")
return storeImageMetadataInState(st, env, "custom", simplestreams.CUSTOM_CLOUD_DATA, imageMetadata)
} | go | func (c *BootstrapCommand) saveCustomImageMetadata(st *state.State, env environs.BootstrapEnviron, imageMetadata []*imagemetadata.ImageMetadata) error {
logger.Debugf("saving custom image metadata")
return storeImageMetadataInState(st, env, "custom", simplestreams.CUSTOM_CLOUD_DATA, imageMetadata)
} | [
"func",
"(",
"c",
"*",
"BootstrapCommand",
")",
"saveCustomImageMetadata",
"(",
"st",
"*",
"state",
".",
"State",
",",
"env",
"environs",
".",
"BootstrapEnviron",
",",
"imageMetadata",
"[",
"]",
"*",
"imagemetadata",
".",
"ImageMetadata",
")",
"error",
"{",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"storeImageMetadataInState",
"(",
"st",
",",
"env",
",",
"\"",
"\"",
",",
"simplestreams",
".",
"CUSTOM_CLOUD_DATA",
",",
"imageMetadata",
")",
"\n",
"}"
] | // saveCustomImageMetadata stores the custom image metadata to the database, | [
"saveCustomImageMetadata",
"stores",
"the",
"custom",
"image",
"metadata",
"to",
"the",
"database"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/jujud/agent/bootstrap.go#L617-L620 |
3,627 | juju/juju | cmd/jujud/agent/bootstrap.go | storeImageMetadataInState | func storeImageMetadataInState(st *state.State, env environs.BootstrapEnviron, source string, priority int, existingMetadata []*imagemetadata.ImageMetadata) error {
if len(existingMetadata) == 0 {
return nil
}
cfg := env.Config()
metadataState := make([]cloudimagemetadata.Metadata, len(existingMetadata))
for i, one := range existingMetadata {
m := cloudimagemetadata.Metadata{
MetadataAttributes: cloudimagemetadata.MetadataAttributes{
Stream: one.Stream,
Region: one.RegionName,
Arch: one.Arch,
VirtType: one.VirtType,
RootStorageType: one.Storage,
Source: source,
Version: one.Version,
},
Priority: priority,
ImageId: one.Id,
}
s, err := seriesFromVersion(one.Version)
if err != nil {
return errors.Annotatef(err, "cannot determine series for version %v", one.Version)
}
m.Series = s
if m.Stream == "" {
m.Stream = cfg.ImageStream()
}
if m.Source == "" {
m.Source = "custom"
}
metadataState[i] = m
}
if err := st.CloudImageMetadataStorage.SaveMetadataNoExpiry(metadataState); err != nil {
return errors.Annotatef(err, "cannot cache image metadata")
}
return nil
} | go | func storeImageMetadataInState(st *state.State, env environs.BootstrapEnviron, source string, priority int, existingMetadata []*imagemetadata.ImageMetadata) error {
if len(existingMetadata) == 0 {
return nil
}
cfg := env.Config()
metadataState := make([]cloudimagemetadata.Metadata, len(existingMetadata))
for i, one := range existingMetadata {
m := cloudimagemetadata.Metadata{
MetadataAttributes: cloudimagemetadata.MetadataAttributes{
Stream: one.Stream,
Region: one.RegionName,
Arch: one.Arch,
VirtType: one.VirtType,
RootStorageType: one.Storage,
Source: source,
Version: one.Version,
},
Priority: priority,
ImageId: one.Id,
}
s, err := seriesFromVersion(one.Version)
if err != nil {
return errors.Annotatef(err, "cannot determine series for version %v", one.Version)
}
m.Series = s
if m.Stream == "" {
m.Stream = cfg.ImageStream()
}
if m.Source == "" {
m.Source = "custom"
}
metadataState[i] = m
}
if err := st.CloudImageMetadataStorage.SaveMetadataNoExpiry(metadataState); err != nil {
return errors.Annotatef(err, "cannot cache image metadata")
}
return nil
} | [
"func",
"storeImageMetadataInState",
"(",
"st",
"*",
"state",
".",
"State",
",",
"env",
"environs",
".",
"BootstrapEnviron",
",",
"source",
"string",
",",
"priority",
"int",
",",
"existingMetadata",
"[",
"]",
"*",
"imagemetadata",
".",
"ImageMetadata",
")",
"error",
"{",
"if",
"len",
"(",
"existingMetadata",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"cfg",
":=",
"env",
".",
"Config",
"(",
")",
"\n",
"metadataState",
":=",
"make",
"(",
"[",
"]",
"cloudimagemetadata",
".",
"Metadata",
",",
"len",
"(",
"existingMetadata",
")",
")",
"\n",
"for",
"i",
",",
"one",
":=",
"range",
"existingMetadata",
"{",
"m",
":=",
"cloudimagemetadata",
".",
"Metadata",
"{",
"MetadataAttributes",
":",
"cloudimagemetadata",
".",
"MetadataAttributes",
"{",
"Stream",
":",
"one",
".",
"Stream",
",",
"Region",
":",
"one",
".",
"RegionName",
",",
"Arch",
":",
"one",
".",
"Arch",
",",
"VirtType",
":",
"one",
".",
"VirtType",
",",
"RootStorageType",
":",
"one",
".",
"Storage",
",",
"Source",
":",
"source",
",",
"Version",
":",
"one",
".",
"Version",
",",
"}",
",",
"Priority",
":",
"priority",
",",
"ImageId",
":",
"one",
".",
"Id",
",",
"}",
"\n",
"s",
",",
"err",
":=",
"seriesFromVersion",
"(",
"one",
".",
"Version",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"one",
".",
"Version",
")",
"\n",
"}",
"\n",
"m",
".",
"Series",
"=",
"s",
"\n",
"if",
"m",
".",
"Stream",
"==",
"\"",
"\"",
"{",
"m",
".",
"Stream",
"=",
"cfg",
".",
"ImageStream",
"(",
")",
"\n",
"}",
"\n",
"if",
"m",
".",
"Source",
"==",
"\"",
"\"",
"{",
"m",
".",
"Source",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"metadataState",
"[",
"i",
"]",
"=",
"m",
"\n",
"}",
"\n",
"if",
"err",
":=",
"st",
".",
"CloudImageMetadataStorage",
".",
"SaveMetadataNoExpiry",
"(",
"metadataState",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // storeImageMetadataInState writes image metadata into state store. | [
"storeImageMetadataInState",
"writes",
"image",
"metadata",
"into",
"state",
"store",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/jujud/agent/bootstrap.go#L623-L660 |
3,628 | juju/juju | worker/terminationworker/worker.go | NewWorker | func NewWorker() worker.Worker {
var w terminationWorker
c := make(chan os.Signal, 1)
signal.Notify(c, TerminationSignal)
w.tomb.Go(func() error {
defer signal.Stop(c)
return w.loop(c)
})
return &w
} | go | func NewWorker() worker.Worker {
var w terminationWorker
c := make(chan os.Signal, 1)
signal.Notify(c, TerminationSignal)
w.tomb.Go(func() error {
defer signal.Stop(c)
return w.loop(c)
})
return &w
} | [
"func",
"NewWorker",
"(",
")",
"worker",
".",
"Worker",
"{",
"var",
"w",
"terminationWorker",
"\n",
"c",
":=",
"make",
"(",
"chan",
"os",
".",
"Signal",
",",
"1",
")",
"\n",
"signal",
".",
"Notify",
"(",
"c",
",",
"TerminationSignal",
")",
"\n",
"w",
".",
"tomb",
".",
"Go",
"(",
"func",
"(",
")",
"error",
"{",
"defer",
"signal",
".",
"Stop",
"(",
"c",
")",
"\n",
"return",
"w",
".",
"loop",
"(",
"c",
")",
"\n",
"}",
")",
"\n",
"return",
"&",
"w",
"\n",
"}"
] | // NewWorker returns a worker that waits for a
// TerminationSignal signal, and then exits
// with worker.ErrTerminateAgent. | [
"NewWorker",
"returns",
"a",
"worker",
"that",
"waits",
"for",
"a",
"TerminationSignal",
"signal",
"and",
"then",
"exits",
"with",
"worker",
".",
"ErrTerminateAgent",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/terminationworker/worker.go#L33-L42 |
3,629 | juju/juju | cmd/juju/storage/list.go | NewListCommand | func NewListCommand() cmd.Command {
cmd := &listCommand{}
cmd.newAPIFunc = func() (StorageListAPI, error) {
return cmd.NewStorageAPI()
}
return modelcmd.Wrap(cmd)
} | go | func NewListCommand() cmd.Command {
cmd := &listCommand{}
cmd.newAPIFunc = func() (StorageListAPI, error) {
return cmd.NewStorageAPI()
}
return modelcmd.Wrap(cmd)
} | [
"func",
"NewListCommand",
"(",
")",
"cmd",
".",
"Command",
"{",
"cmd",
":=",
"&",
"listCommand",
"{",
"}",
"\n",
"cmd",
".",
"newAPIFunc",
"=",
"func",
"(",
")",
"(",
"StorageListAPI",
",",
"error",
")",
"{",
"return",
"cmd",
".",
"NewStorageAPI",
"(",
")",
"\n",
"}",
"\n",
"return",
"modelcmd",
".",
"Wrap",
"(",
"cmd",
")",
"\n",
"}"
] | // NewListCommand returns a command for listing storage instances. | [
"NewListCommand",
"returns",
"a",
"command",
"for",
"listing",
"storage",
"instances",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/storage/list.go#L20-L26 |
3,630 | juju/juju | cmd/juju/storage/list.go | GetCombinedStorageInfo | func GetCombinedStorageInfo(p GetCombinedStorageInfoParams) (*CombinedStorage, error) {
combined := &CombinedStorage{}
if p.WantFilesystems {
filesystems, err := generateListFilesystemsOutput(p.Context, p.APIClient, p.Ids)
if err != nil {
return nil, errors.Trace(err)
}
combined.Filesystems = filesystems
}
if p.WantVolumes {
volumes, err := generateListVolumeOutput(p.Context, p.APIClient, p.Ids)
if err != nil {
return nil, errors.Trace(err)
}
combined.Volumes = volumes
}
if p.WantStorage {
storageInstances, err := generateListStorageOutput(p.Context, p.APIClient)
if err != nil {
return nil, errors.Trace(err)
}
combined.StorageInstances = storageInstances
}
return combined, nil
} | go | func GetCombinedStorageInfo(p GetCombinedStorageInfoParams) (*CombinedStorage, error) {
combined := &CombinedStorage{}
if p.WantFilesystems {
filesystems, err := generateListFilesystemsOutput(p.Context, p.APIClient, p.Ids)
if err != nil {
return nil, errors.Trace(err)
}
combined.Filesystems = filesystems
}
if p.WantVolumes {
volumes, err := generateListVolumeOutput(p.Context, p.APIClient, p.Ids)
if err != nil {
return nil, errors.Trace(err)
}
combined.Volumes = volumes
}
if p.WantStorage {
storageInstances, err := generateListStorageOutput(p.Context, p.APIClient)
if err != nil {
return nil, errors.Trace(err)
}
combined.StorageInstances = storageInstances
}
return combined, nil
} | [
"func",
"GetCombinedStorageInfo",
"(",
"p",
"GetCombinedStorageInfoParams",
")",
"(",
"*",
"CombinedStorage",
",",
"error",
")",
"{",
"combined",
":=",
"&",
"CombinedStorage",
"{",
"}",
"\n",
"if",
"p",
".",
"WantFilesystems",
"{",
"filesystems",
",",
"err",
":=",
"generateListFilesystemsOutput",
"(",
"p",
".",
"Context",
",",
"p",
".",
"APIClient",
",",
"p",
".",
"Ids",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"combined",
".",
"Filesystems",
"=",
"filesystems",
"\n",
"}",
"\n",
"if",
"p",
".",
"WantVolumes",
"{",
"volumes",
",",
"err",
":=",
"generateListVolumeOutput",
"(",
"p",
".",
"Context",
",",
"p",
".",
"APIClient",
",",
"p",
".",
"Ids",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"combined",
".",
"Volumes",
"=",
"volumes",
"\n",
"}",
"\n",
"if",
"p",
".",
"WantStorage",
"{",
"storageInstances",
",",
"err",
":=",
"generateListStorageOutput",
"(",
"p",
".",
"Context",
",",
"p",
".",
"APIClient",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"combined",
".",
"StorageInstances",
"=",
"storageInstances",
"\n",
"}",
"\n",
"return",
"combined",
",",
"nil",
"\n",
"}"
] | // GetCombinedStorageInfo returns a list of StorageInstances, Filesystems and Volumes for juju cmdline display purposes | [
"GetCombinedStorageInfo",
"returns",
"a",
"list",
"of",
"StorageInstances",
"Filesystems",
"and",
"Volumes",
"for",
"juju",
"cmdline",
"display",
"purposes"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/storage/list.go#L123-L147 |
3,631 | juju/juju | cmd/juju/storage/list.go | generateListStorageOutput | func generateListStorageOutput(ctx *cmd.Context, api StorageListAPI) (map[string]StorageInfo, error) {
results, err := api.ListStorageDetails()
if err != nil {
return nil, errors.Trace(err)
}
if len(results) == 0 {
return nil, nil
}
return formatStorageDetails(results)
} | go | func generateListStorageOutput(ctx *cmd.Context, api StorageListAPI) (map[string]StorageInfo, error) {
results, err := api.ListStorageDetails()
if err != nil {
return nil, errors.Trace(err)
}
if len(results) == 0 {
return nil, nil
}
return formatStorageDetails(results)
} | [
"func",
"generateListStorageOutput",
"(",
"ctx",
"*",
"cmd",
".",
"Context",
",",
"api",
"StorageListAPI",
")",
"(",
"map",
"[",
"string",
"]",
"StorageInfo",
",",
"error",
")",
"{",
"results",
",",
"err",
":=",
"api",
".",
"ListStorageDetails",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"results",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"return",
"formatStorageDetails",
"(",
"results",
")",
"\n",
"}"
] | // generateListStorageOutput returns a map of storage details | [
"generateListStorageOutput",
"returns",
"a",
"map",
"of",
"storage",
"details"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/storage/list.go#L158-L167 |
3,632 | juju/juju | cmd/juju/storage/list.go | Empty | func (c *CombinedStorage) Empty() bool {
return len(c.StorageInstances) == 0 && len(c.Filesystems) == 0 && len(c.Volumes) == 0
} | go | func (c *CombinedStorage) Empty() bool {
return len(c.StorageInstances) == 0 && len(c.Filesystems) == 0 && len(c.Volumes) == 0
} | [
"func",
"(",
"c",
"*",
"CombinedStorage",
")",
"Empty",
"(",
")",
"bool",
"{",
"return",
"len",
"(",
"c",
".",
"StorageInstances",
")",
"==",
"0",
"&&",
"len",
"(",
"c",
".",
"Filesystems",
")",
"==",
"0",
"&&",
"len",
"(",
"c",
".",
"Volumes",
")",
"==",
"0",
"\n",
"}"
] | // Empty checks if CombinedStorage is empty. | [
"Empty",
"checks",
"if",
"CombinedStorage",
"is",
"empty",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/storage/list.go#L177-L179 |
3,633 | juju/juju | cmd/juju/storage/list.go | formatListTabularOne | func formatListTabularOne(writer io.Writer, value interface{}) error {
return formatListTabular(writer, value, false)
} | go | func formatListTabularOne(writer io.Writer, value interface{}) error {
return formatListTabular(writer, value, false)
} | [
"func",
"formatListTabularOne",
"(",
"writer",
"io",
".",
"Writer",
",",
"value",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"formatListTabular",
"(",
"writer",
",",
"value",
",",
"false",
")",
"\n",
"}"
] | // formatListTabularOne writes a tabular summary of storage instances or filesystems or volumes. | [
"formatListTabularOne",
"writes",
"a",
"tabular",
"summary",
"of",
"storage",
"instances",
"or",
"filesystems",
"or",
"volumes",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/storage/list.go#L182-L184 |
3,634 | juju/juju | cmd/juju/storage/list.go | FormatListTabularAll | func FormatListTabularAll(writer io.Writer, value interface{}) error {
return formatListTabular(writer, value, true)
} | go | func FormatListTabularAll(writer io.Writer, value interface{}) error {
return formatListTabular(writer, value, true)
} | [
"func",
"FormatListTabularAll",
"(",
"writer",
"io",
".",
"Writer",
",",
"value",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"formatListTabular",
"(",
"writer",
",",
"value",
",",
"true",
")",
"\n",
"}"
] | // FormatListTabularAll writes a tabular summary of storage instances, filesystems and volumes. | [
"FormatListTabularAll",
"writes",
"a",
"tabular",
"summary",
"of",
"storage",
"instances",
"filesystems",
"and",
"volumes",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/storage/list.go#L224-L226 |
3,635 | juju/juju | worker/reboot/manifold.go | Manifold | func Manifold(config ManifoldConfig) dependency.Manifold {
return dependency.Manifold{
Inputs: []string{
config.AgentName,
config.APICallerName,
},
Start: func(context dependency.Context) (worker.Worker, error) {
var agent agent.Agent
if err := context.Get(config.AgentName, &agent); err != nil {
return nil, err
}
var apiCaller base.APICaller
if err := context.Get(config.APICallerName, &apiCaller); err != nil {
return nil, err
}
if config.Clock == nil {
return nil, errors.NotValidf("missing Clock")
}
if config.MachineLock == nil {
return nil, errors.NotValidf("missing MachineLock")
}
return newWorker(agent, apiCaller, config.MachineLock, config.Clock)
},
}
} | go | func Manifold(config ManifoldConfig) dependency.Manifold {
return dependency.Manifold{
Inputs: []string{
config.AgentName,
config.APICallerName,
},
Start: func(context dependency.Context) (worker.Worker, error) {
var agent agent.Agent
if err := context.Get(config.AgentName, &agent); err != nil {
return nil, err
}
var apiCaller base.APICaller
if err := context.Get(config.APICallerName, &apiCaller); err != nil {
return nil, err
}
if config.Clock == nil {
return nil, errors.NotValidf("missing Clock")
}
if config.MachineLock == nil {
return nil, errors.NotValidf("missing MachineLock")
}
return newWorker(agent, apiCaller, config.MachineLock, config.Clock)
},
}
} | [
"func",
"Manifold",
"(",
"config",
"ManifoldConfig",
")",
"dependency",
".",
"Manifold",
"{",
"return",
"dependency",
".",
"Manifold",
"{",
"Inputs",
":",
"[",
"]",
"string",
"{",
"config",
".",
"AgentName",
",",
"config",
".",
"APICallerName",
",",
"}",
",",
"Start",
":",
"func",
"(",
"context",
"dependency",
".",
"Context",
")",
"(",
"worker",
".",
"Worker",
",",
"error",
")",
"{",
"var",
"agent",
"agent",
".",
"Agent",
"\n",
"if",
"err",
":=",
"context",
".",
"Get",
"(",
"config",
".",
"AgentName",
",",
"&",
"agent",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"apiCaller",
"base",
".",
"APICaller",
"\n",
"if",
"err",
":=",
"context",
".",
"Get",
"(",
"config",
".",
"APICallerName",
",",
"&",
"apiCaller",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"config",
".",
"Clock",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"config",
".",
"MachineLock",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"newWorker",
"(",
"agent",
",",
"apiCaller",
",",
"config",
".",
"MachineLock",
",",
"config",
".",
"Clock",
")",
"\n",
"}",
",",
"}",
"\n",
"}"
] | // Manifold returns a dependency manifold that runs a reboot worker,
// using the resource names defined in the supplied config. | [
"Manifold",
"returns",
"a",
"dependency",
"manifold",
"that",
"runs",
"a",
"reboot",
"worker",
"using",
"the",
"resource",
"names",
"defined",
"in",
"the",
"supplied",
"config",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/reboot/manifold.go#L28-L52 |
3,636 | juju/juju | state/distribution.go | ApplicationInstances | func ApplicationInstances(st *State, application string) ([]instance.Id, error) {
units, err := allUnits(st, application)
if err != nil {
return nil, err
}
instanceIds := make([]instance.Id, 0, len(units))
for _, unit := range units {
machineId, err := unit.AssignedMachineId()
if errors.IsNotAssigned(err) {
continue
} else if err != nil {
return nil, err
}
machine, err := st.Machine(machineId)
if err != nil {
return nil, err
}
instanceId, err := machine.InstanceId()
if err == nil {
instanceIds = append(instanceIds, instanceId)
} else if errors.IsNotProvisioned(err) {
continue
} else {
return nil, err
}
}
return instanceIds, nil
} | go | func ApplicationInstances(st *State, application string) ([]instance.Id, error) {
units, err := allUnits(st, application)
if err != nil {
return nil, err
}
instanceIds := make([]instance.Id, 0, len(units))
for _, unit := range units {
machineId, err := unit.AssignedMachineId()
if errors.IsNotAssigned(err) {
continue
} else if err != nil {
return nil, err
}
machine, err := st.Machine(machineId)
if err != nil {
return nil, err
}
instanceId, err := machine.InstanceId()
if err == nil {
instanceIds = append(instanceIds, instanceId)
} else if errors.IsNotProvisioned(err) {
continue
} else {
return nil, err
}
}
return instanceIds, nil
} | [
"func",
"ApplicationInstances",
"(",
"st",
"*",
"State",
",",
"application",
"string",
")",
"(",
"[",
"]",
"instance",
".",
"Id",
",",
"error",
")",
"{",
"units",
",",
"err",
":=",
"allUnits",
"(",
"st",
",",
"application",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"instanceIds",
":=",
"make",
"(",
"[",
"]",
"instance",
".",
"Id",
",",
"0",
",",
"len",
"(",
"units",
")",
")",
"\n",
"for",
"_",
",",
"unit",
":=",
"range",
"units",
"{",
"machineId",
",",
"err",
":=",
"unit",
".",
"AssignedMachineId",
"(",
")",
"\n",
"if",
"errors",
".",
"IsNotAssigned",
"(",
"err",
")",
"{",
"continue",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"machine",
",",
"err",
":=",
"st",
".",
"Machine",
"(",
"machineId",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"instanceId",
",",
"err",
":=",
"machine",
".",
"InstanceId",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"instanceIds",
"=",
"append",
"(",
"instanceIds",
",",
"instanceId",
")",
"\n",
"}",
"else",
"if",
"errors",
".",
"IsNotProvisioned",
"(",
"err",
")",
"{",
"continue",
"\n",
"}",
"else",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"instanceIds",
",",
"nil",
"\n",
"}"
] | // ApplicationInstances returns the instance IDs of provisioned
// machines that are assigned units of the specified application. | [
"ApplicationInstances",
"returns",
"the",
"instance",
"IDs",
"of",
"provisioned",
"machines",
"that",
"are",
"assigned",
"units",
"of",
"the",
"specified",
"application",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/distribution.go#L49-L76 |
3,637 | juju/juju | state/distribution.go | ApplicationMachines | func ApplicationMachines(st *State, application string) ([]string, error) {
machines, err := st.AllMachines()
if err != nil {
return nil, err
}
applicationName := unitAppName(application)
var machineIds []string
for _, machine := range machines {
principalSet := set.NewStrings()
for _, principal := range machine.Principals() {
principalSet.Add(unitAppName(principal))
}
if principalSet.Contains(applicationName) {
machineIds = append(machineIds, machine.Id())
}
}
return machineIds, nil
} | go | func ApplicationMachines(st *State, application string) ([]string, error) {
machines, err := st.AllMachines()
if err != nil {
return nil, err
}
applicationName := unitAppName(application)
var machineIds []string
for _, machine := range machines {
principalSet := set.NewStrings()
for _, principal := range machine.Principals() {
principalSet.Add(unitAppName(principal))
}
if principalSet.Contains(applicationName) {
machineIds = append(machineIds, machine.Id())
}
}
return machineIds, nil
} | [
"func",
"ApplicationMachines",
"(",
"st",
"*",
"State",
",",
"application",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"machines",
",",
"err",
":=",
"st",
".",
"AllMachines",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"applicationName",
":=",
"unitAppName",
"(",
"application",
")",
"\n",
"var",
"machineIds",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"machine",
":=",
"range",
"machines",
"{",
"principalSet",
":=",
"set",
".",
"NewStrings",
"(",
")",
"\n",
"for",
"_",
",",
"principal",
":=",
"range",
"machine",
".",
"Principals",
"(",
")",
"{",
"principalSet",
".",
"Add",
"(",
"unitAppName",
"(",
"principal",
")",
")",
"\n",
"}",
"\n",
"if",
"principalSet",
".",
"Contains",
"(",
"applicationName",
")",
"{",
"machineIds",
"=",
"append",
"(",
"machineIds",
",",
"machine",
".",
"Id",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"machineIds",
",",
"nil",
"\n",
"}"
] | // ApplicationMachines returns the machine IDs of machines which have
// the specified application listed as a principal. | [
"ApplicationMachines",
"returns",
"the",
"machine",
"IDs",
"of",
"machines",
"which",
"have",
"the",
"specified",
"application",
"listed",
"as",
"a",
"principal",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/distribution.go#L80-L97 |
3,638 | juju/juju | network/address.go | NewAddressOnSpace | func NewAddressOnSpace(spaceName string, value string) Address {
addr := NewAddress(value)
addr.SpaceName = SpaceName(spaceName)
return addr
} | go | func NewAddressOnSpace(spaceName string, value string) Address {
addr := NewAddress(value)
addr.SpaceName = SpaceName(spaceName)
return addr
} | [
"func",
"NewAddressOnSpace",
"(",
"spaceName",
"string",
",",
"value",
"string",
")",
"Address",
"{",
"addr",
":=",
"NewAddress",
"(",
"value",
")",
"\n",
"addr",
".",
"SpaceName",
"=",
"SpaceName",
"(",
"spaceName",
")",
"\n",
"return",
"addr",
"\n",
"}"
] | // NewAddressOnSpace creates a new Address, deriving its type and scope from the
// value and associating it with the given spaceName. | [
"NewAddressOnSpace",
"creates",
"a",
"new",
"Address",
"deriving",
"its",
"type",
"and",
"scope",
"from",
"the",
"value",
"and",
"associating",
"it",
"with",
"the",
"given",
"spaceName",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/network/address.go#L169-L173 |
3,639 | juju/juju | network/address.go | NewAddresses | func NewAddresses(inAddresses ...string) (outAddresses []Address) {
outAddresses = make([]Address, len(inAddresses))
for i, address := range inAddresses {
outAddresses[i] = NewAddress(address)
}
return outAddresses
} | go | func NewAddresses(inAddresses ...string) (outAddresses []Address) {
outAddresses = make([]Address, len(inAddresses))
for i, address := range inAddresses {
outAddresses[i] = NewAddress(address)
}
return outAddresses
} | [
"func",
"NewAddresses",
"(",
"inAddresses",
"...",
"string",
")",
"(",
"outAddresses",
"[",
"]",
"Address",
")",
"{",
"outAddresses",
"=",
"make",
"(",
"[",
"]",
"Address",
",",
"len",
"(",
"inAddresses",
")",
")",
"\n",
"for",
"i",
",",
"address",
":=",
"range",
"inAddresses",
"{",
"outAddresses",
"[",
"i",
"]",
"=",
"NewAddress",
"(",
"address",
")",
"\n",
"}",
"\n",
"return",
"outAddresses",
"\n",
"}"
] | // NewAddresses is a convenience function to create addresses from a variable
// number of string arguments. | [
"NewAddresses",
"is",
"a",
"convenience",
"function",
"to",
"create",
"addresses",
"from",
"a",
"variable",
"number",
"of",
"string",
"arguments",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/network/address.go#L177-L183 |
3,640 | juju/juju | network/address.go | NewAddressesOnSpace | func NewAddressesOnSpace(spaceName string, inAddresses ...string) (outAddresses []Address) {
outAddresses = make([]Address, len(inAddresses))
for i, address := range inAddresses {
outAddresses[i] = NewAddressOnSpace(spaceName, address)
}
return outAddresses
} | go | func NewAddressesOnSpace(spaceName string, inAddresses ...string) (outAddresses []Address) {
outAddresses = make([]Address, len(inAddresses))
for i, address := range inAddresses {
outAddresses[i] = NewAddressOnSpace(spaceName, address)
}
return outAddresses
} | [
"func",
"NewAddressesOnSpace",
"(",
"spaceName",
"string",
",",
"inAddresses",
"...",
"string",
")",
"(",
"outAddresses",
"[",
"]",
"Address",
")",
"{",
"outAddresses",
"=",
"make",
"(",
"[",
"]",
"Address",
",",
"len",
"(",
"inAddresses",
")",
")",
"\n",
"for",
"i",
",",
"address",
":=",
"range",
"inAddresses",
"{",
"outAddresses",
"[",
"i",
"]",
"=",
"NewAddressOnSpace",
"(",
"spaceName",
",",
"address",
")",
"\n",
"}",
"\n",
"return",
"outAddresses",
"\n",
"}"
] | // NewAddressesOnSpace is a convenience function to create addresses on the same
// space, from a a variable number of string arguments. | [
"NewAddressesOnSpace",
"is",
"a",
"convenience",
"function",
"to",
"create",
"addresses",
"on",
"the",
"same",
"space",
"from",
"a",
"a",
"variable",
"number",
"of",
"string",
"arguments",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/network/address.go#L187-L193 |
3,641 | juju/juju | network/address.go | DeriveAddressType | func DeriveAddressType(value string) AddressType {
ip := net.ParseIP(value)
switch {
case ip == nil:
// TODO(gz): Check value is a valid hostname
return HostName
case ip.To4() != nil:
return IPv4Address
case ip.To16() != nil:
return IPv6Address
default:
panic("Unknown form of IP address")
}
} | go | func DeriveAddressType(value string) AddressType {
ip := net.ParseIP(value)
switch {
case ip == nil:
// TODO(gz): Check value is a valid hostname
return HostName
case ip.To4() != nil:
return IPv4Address
case ip.To16() != nil:
return IPv6Address
default:
panic("Unknown form of IP address")
}
} | [
"func",
"DeriveAddressType",
"(",
"value",
"string",
")",
"AddressType",
"{",
"ip",
":=",
"net",
".",
"ParseIP",
"(",
"value",
")",
"\n",
"switch",
"{",
"case",
"ip",
"==",
"nil",
":",
"// TODO(gz): Check value is a valid hostname",
"return",
"HostName",
"\n",
"case",
"ip",
".",
"To4",
"(",
")",
"!=",
"nil",
":",
"return",
"IPv4Address",
"\n",
"case",
"ip",
".",
"To16",
"(",
")",
"!=",
"nil",
":",
"return",
"IPv6Address",
"\n",
"default",
":",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
] | // DeriveAddressType attempts to detect the type of address given. | [
"DeriveAddressType",
"attempts",
"to",
"detect",
"the",
"type",
"of",
"address",
"given",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/network/address.go#L196-L209 |
3,642 | juju/juju | network/address.go | deriveScope | func deriveScope(addr Address) Scope {
if addr.Type == HostName {
return addr.Scope
}
ip := net.ParseIP(addr.Value)
if ip == nil {
return addr.Scope
}
if ip.IsLoopback() {
return ScopeMachineLocal
}
if isIPv4PrivateNetworkAddress(addr.Type, ip) ||
isIPv6UniqueLocalAddress(addr.Type, ip) {
return ScopeCloudLocal
}
if isIPv4ReservedEAddress(addr.Type, ip) {
return ScopeFanLocal
}
if ip.IsLinkLocalMulticast() ||
ip.IsLinkLocalUnicast() ||
ip.IsInterfaceLocalMulticast() {
return ScopeLinkLocal
}
if ip.IsGlobalUnicast() {
return ScopePublic
}
return addr.Scope
} | go | func deriveScope(addr Address) Scope {
if addr.Type == HostName {
return addr.Scope
}
ip := net.ParseIP(addr.Value)
if ip == nil {
return addr.Scope
}
if ip.IsLoopback() {
return ScopeMachineLocal
}
if isIPv4PrivateNetworkAddress(addr.Type, ip) ||
isIPv6UniqueLocalAddress(addr.Type, ip) {
return ScopeCloudLocal
}
if isIPv4ReservedEAddress(addr.Type, ip) {
return ScopeFanLocal
}
if ip.IsLinkLocalMulticast() ||
ip.IsLinkLocalUnicast() ||
ip.IsInterfaceLocalMulticast() {
return ScopeLinkLocal
}
if ip.IsGlobalUnicast() {
return ScopePublic
}
return addr.Scope
} | [
"func",
"deriveScope",
"(",
"addr",
"Address",
")",
"Scope",
"{",
"if",
"addr",
".",
"Type",
"==",
"HostName",
"{",
"return",
"addr",
".",
"Scope",
"\n",
"}",
"\n",
"ip",
":=",
"net",
".",
"ParseIP",
"(",
"addr",
".",
"Value",
")",
"\n",
"if",
"ip",
"==",
"nil",
"{",
"return",
"addr",
".",
"Scope",
"\n",
"}",
"\n",
"if",
"ip",
".",
"IsLoopback",
"(",
")",
"{",
"return",
"ScopeMachineLocal",
"\n",
"}",
"\n",
"if",
"isIPv4PrivateNetworkAddress",
"(",
"addr",
".",
"Type",
",",
"ip",
")",
"||",
"isIPv6UniqueLocalAddress",
"(",
"addr",
".",
"Type",
",",
"ip",
")",
"{",
"return",
"ScopeCloudLocal",
"\n",
"}",
"\n",
"if",
"isIPv4ReservedEAddress",
"(",
"addr",
".",
"Type",
",",
"ip",
")",
"{",
"return",
"ScopeFanLocal",
"\n",
"}",
"\n\n",
"if",
"ip",
".",
"IsLinkLocalMulticast",
"(",
")",
"||",
"ip",
".",
"IsLinkLocalUnicast",
"(",
")",
"||",
"ip",
".",
"IsInterfaceLocalMulticast",
"(",
")",
"{",
"return",
"ScopeLinkLocal",
"\n",
"}",
"\n",
"if",
"ip",
".",
"IsGlobalUnicast",
"(",
")",
"{",
"return",
"ScopePublic",
"\n",
"}",
"\n",
"return",
"addr",
".",
"Scope",
"\n",
"}"
] | // deriveScope attempts to derive the network scope from an address's
// type and value, returning the original network scope if no
// deduction can be made. | [
"deriveScope",
"attempts",
"to",
"derive",
"the",
"network",
"scope",
"from",
"an",
"address",
"s",
"type",
"and",
"value",
"returning",
"the",
"original",
"network",
"scope",
"if",
"no",
"deduction",
"can",
"be",
"made",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/network/address.go#L237-L265 |
3,643 | juju/juju | network/address.go | ExactScopeMatch | func ExactScopeMatch(addr Address, addrScopes ...Scope) bool {
for _, scope := range addrScopes {
if addr.Scope == scope {
return true
}
}
return false
} | go | func ExactScopeMatch(addr Address, addrScopes ...Scope) bool {
for _, scope := range addrScopes {
if addr.Scope == scope {
return true
}
}
return false
} | [
"func",
"ExactScopeMatch",
"(",
"addr",
"Address",
",",
"addrScopes",
"...",
"Scope",
")",
"bool",
"{",
"for",
"_",
",",
"scope",
":=",
"range",
"addrScopes",
"{",
"if",
"addr",
".",
"Scope",
"==",
"scope",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // ExactScopeMatch checks if an address exactly matches any of the specified
// scopes. | [
"ExactScopeMatch",
"checks",
"if",
"an",
"address",
"exactly",
"matches",
"any",
"of",
"the",
"specified",
"scopes",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/network/address.go#L269-L276 |
3,644 | juju/juju | network/address.go | SelectAddressesBySpaceNames | func SelectAddressesBySpaceNames(addresses []Address, spaceNames ...SpaceName) ([]Address, bool) {
if len(spaceNames) == 0 {
logger.Errorf("addresses not filtered - no spaces given.")
return addresses, false
}
var selectedAddresses []Address
for _, addr := range addresses {
if spaceNameList(spaceNames).IndexOf(addr.SpaceName) >= 0 {
logger.Debugf("selected %q as an address in space %q", addr.Value, addr.SpaceName)
selectedAddresses = append(selectedAddresses, addr)
}
}
if len(selectedAddresses) > 0 {
return selectedAddresses, true
}
logger.Errorf("no addresses found in spaces %s", spaceNames)
return addresses, false
} | go | func SelectAddressesBySpaceNames(addresses []Address, spaceNames ...SpaceName) ([]Address, bool) {
if len(spaceNames) == 0 {
logger.Errorf("addresses not filtered - no spaces given.")
return addresses, false
}
var selectedAddresses []Address
for _, addr := range addresses {
if spaceNameList(spaceNames).IndexOf(addr.SpaceName) >= 0 {
logger.Debugf("selected %q as an address in space %q", addr.Value, addr.SpaceName)
selectedAddresses = append(selectedAddresses, addr)
}
}
if len(selectedAddresses) > 0 {
return selectedAddresses, true
}
logger.Errorf("no addresses found in spaces %s", spaceNames)
return addresses, false
} | [
"func",
"SelectAddressesBySpaceNames",
"(",
"addresses",
"[",
"]",
"Address",
",",
"spaceNames",
"...",
"SpaceName",
")",
"(",
"[",
"]",
"Address",
",",
"bool",
")",
"{",
"if",
"len",
"(",
"spaceNames",
")",
"==",
"0",
"{",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"addresses",
",",
"false",
"\n",
"}",
"\n\n",
"var",
"selectedAddresses",
"[",
"]",
"Address",
"\n",
"for",
"_",
",",
"addr",
":=",
"range",
"addresses",
"{",
"if",
"spaceNameList",
"(",
"spaceNames",
")",
".",
"IndexOf",
"(",
"addr",
".",
"SpaceName",
")",
">=",
"0",
"{",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"addr",
".",
"Value",
",",
"addr",
".",
"SpaceName",
")",
"\n",
"selectedAddresses",
"=",
"append",
"(",
"selectedAddresses",
",",
"addr",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"selectedAddresses",
")",
">",
"0",
"{",
"return",
"selectedAddresses",
",",
"true",
"\n",
"}",
"\n\n",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"spaceNames",
")",
"\n",
"return",
"addresses",
",",
"false",
"\n",
"}"
] | // SelectAddressesBySpaceNames filters the input slice of Addresses down to
// those in the input space names. | [
"SelectAddressesBySpaceNames",
"filters",
"the",
"input",
"slice",
"of",
"Addresses",
"down",
"to",
"those",
"in",
"the",
"input",
"space",
"names",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/network/address.go#L280-L300 |
3,645 | juju/juju | network/address.go | SelectHostPortsBySpaceNames | func SelectHostPortsBySpaceNames(hps []HostPort, spaceNames ...SpaceName) ([]HostPort, bool) {
if len(spaceNames) == 0 {
logger.Errorf("host ports not filtered - no spaces given.")
return hps, false
}
var selectedHostPorts []HostPort
for _, hp := range hps {
if spaceNameList(spaceNames).IndexOf(hp.SpaceName) >= 0 {
logger.Debugf("selected %q as a hostPort in space %q", hp.Value, hp.SpaceName)
selectedHostPorts = append(selectedHostPorts, hp)
}
}
if len(selectedHostPorts) > 0 {
return selectedHostPorts, true
}
logger.Errorf("no hostPorts found in spaces %s", spaceNames)
return hps, false
} | go | func SelectHostPortsBySpaceNames(hps []HostPort, spaceNames ...SpaceName) ([]HostPort, bool) {
if len(spaceNames) == 0 {
logger.Errorf("host ports not filtered - no spaces given.")
return hps, false
}
var selectedHostPorts []HostPort
for _, hp := range hps {
if spaceNameList(spaceNames).IndexOf(hp.SpaceName) >= 0 {
logger.Debugf("selected %q as a hostPort in space %q", hp.Value, hp.SpaceName)
selectedHostPorts = append(selectedHostPorts, hp)
}
}
if len(selectedHostPorts) > 0 {
return selectedHostPorts, true
}
logger.Errorf("no hostPorts found in spaces %s", spaceNames)
return hps, false
} | [
"func",
"SelectHostPortsBySpaceNames",
"(",
"hps",
"[",
"]",
"HostPort",
",",
"spaceNames",
"...",
"SpaceName",
")",
"(",
"[",
"]",
"HostPort",
",",
"bool",
")",
"{",
"if",
"len",
"(",
"spaceNames",
")",
"==",
"0",
"{",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"hps",
",",
"false",
"\n",
"}",
"\n\n",
"var",
"selectedHostPorts",
"[",
"]",
"HostPort",
"\n",
"for",
"_",
",",
"hp",
":=",
"range",
"hps",
"{",
"if",
"spaceNameList",
"(",
"spaceNames",
")",
".",
"IndexOf",
"(",
"hp",
".",
"SpaceName",
")",
">=",
"0",
"{",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"hp",
".",
"Value",
",",
"hp",
".",
"SpaceName",
")",
"\n",
"selectedHostPorts",
"=",
"append",
"(",
"selectedHostPorts",
",",
"hp",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"selectedHostPorts",
")",
">",
"0",
"{",
"return",
"selectedHostPorts",
",",
"true",
"\n",
"}",
"\n\n",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"spaceNames",
")",
"\n",
"return",
"hps",
",",
"false",
"\n",
"}"
] | // SelectHostPortsBySpaceNames filters the input slice of HostPorts down to
// those in the input space names. | [
"SelectHostPortsBySpaceNames",
"filters",
"the",
"input",
"slice",
"of",
"HostPorts",
"down",
"to",
"those",
"in",
"the",
"input",
"space",
"names",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/network/address.go#L304-L324 |
3,646 | juju/juju | network/address.go | SelectPublicHostPort | func SelectPublicHostPort(hps []HostPort) string {
index := bestAddressIndex(len(hps), func(i int) Address {
return hps[i].Address
}, publicMatch)
if index < 0 {
return ""
}
return hps[index].NetAddr()
} | go | func SelectPublicHostPort(hps []HostPort) string {
index := bestAddressIndex(len(hps), func(i int) Address {
return hps[i].Address
}, publicMatch)
if index < 0 {
return ""
}
return hps[index].NetAddr()
} | [
"func",
"SelectPublicHostPort",
"(",
"hps",
"[",
"]",
"HostPort",
")",
"string",
"{",
"index",
":=",
"bestAddressIndex",
"(",
"len",
"(",
"hps",
")",
",",
"func",
"(",
"i",
"int",
")",
"Address",
"{",
"return",
"hps",
"[",
"i",
"]",
".",
"Address",
"\n",
"}",
",",
"publicMatch",
")",
"\n",
"if",
"index",
"<",
"0",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"hps",
"[",
"index",
"]",
".",
"NetAddr",
"(",
")",
"\n",
"}"
] | // SelectPublicHostPort picks one HostPort from a slice that would be
// appropriate to display as a publicly accessible endpoint. If there
// are no suitable candidates, the empty string is returned. | [
"SelectPublicHostPort",
"picks",
"one",
"HostPort",
"from",
"a",
"slice",
"that",
"would",
"be",
"appropriate",
"to",
"display",
"as",
"a",
"publicly",
"accessible",
"endpoint",
".",
"If",
"there",
"are",
"no",
"suitable",
"candidates",
"the",
"empty",
"string",
"is",
"returned",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/network/address.go#L357-L365 |
3,647 | juju/juju | network/address.go | SelectInternalAddresses | func SelectInternalAddresses(addresses []Address, machineLocal bool) []Address {
indexes := bestAddressIndexes(len(addresses), func(i int) Address {
return addresses[i]
}, internalAddressMatcher(machineLocal))
if len(indexes) == 0 {
return nil
}
out := make([]Address, 0, len(indexes))
for _, index := range indexes {
out = append(out, addresses[index])
}
return out
} | go | func SelectInternalAddresses(addresses []Address, machineLocal bool) []Address {
indexes := bestAddressIndexes(len(addresses), func(i int) Address {
return addresses[i]
}, internalAddressMatcher(machineLocal))
if len(indexes) == 0 {
return nil
}
out := make([]Address, 0, len(indexes))
for _, index := range indexes {
out = append(out, addresses[index])
}
return out
} | [
"func",
"SelectInternalAddresses",
"(",
"addresses",
"[",
"]",
"Address",
",",
"machineLocal",
"bool",
")",
"[",
"]",
"Address",
"{",
"indexes",
":=",
"bestAddressIndexes",
"(",
"len",
"(",
"addresses",
")",
",",
"func",
"(",
"i",
"int",
")",
"Address",
"{",
"return",
"addresses",
"[",
"i",
"]",
"\n",
"}",
",",
"internalAddressMatcher",
"(",
"machineLocal",
")",
")",
"\n",
"if",
"len",
"(",
"indexes",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"out",
":=",
"make",
"(",
"[",
"]",
"Address",
",",
"0",
",",
"len",
"(",
"indexes",
")",
")",
"\n",
"for",
"_",
",",
"index",
":=",
"range",
"indexes",
"{",
"out",
"=",
"append",
"(",
"out",
",",
"addresses",
"[",
"index",
"]",
")",
"\n",
"}",
"\n",
"return",
"out",
"\n",
"}"
] | // SelectInternalAddresses picks the best addresses from a slice that can be
// used as an endpoint for juju internal communication.
// I nil slice is returned if there are no suitable addresses identified. | [
"SelectInternalAddresses",
"picks",
"the",
"best",
"addresses",
"from",
"a",
"slice",
"that",
"can",
"be",
"used",
"as",
"an",
"endpoint",
"for",
"juju",
"internal",
"communication",
".",
"I",
"nil",
"slice",
"is",
"returned",
"if",
"there",
"are",
"no",
"suitable",
"addresses",
"identified",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/network/address.go#L384-L397 |
3,648 | juju/juju | network/address.go | SelectInternalHostPort | func SelectInternalHostPort(hps []HostPort, machineLocal bool) string {
index := bestAddressIndex(len(hps), func(i int) Address {
return hps[i].Address
}, internalAddressMatcher(machineLocal))
if index < 0 {
return ""
}
return hps[index].NetAddr()
} | go | func SelectInternalHostPort(hps []HostPort, machineLocal bool) string {
index := bestAddressIndex(len(hps), func(i int) Address {
return hps[i].Address
}, internalAddressMatcher(machineLocal))
if index < 0 {
return ""
}
return hps[index].NetAddr()
} | [
"func",
"SelectInternalHostPort",
"(",
"hps",
"[",
"]",
"HostPort",
",",
"machineLocal",
"bool",
")",
"string",
"{",
"index",
":=",
"bestAddressIndex",
"(",
"len",
"(",
"hps",
")",
",",
"func",
"(",
"i",
"int",
")",
"Address",
"{",
"return",
"hps",
"[",
"i",
"]",
".",
"Address",
"\n",
"}",
",",
"internalAddressMatcher",
"(",
"machineLocal",
")",
")",
"\n",
"if",
"index",
"<",
"0",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"hps",
"[",
"index",
"]",
".",
"NetAddr",
"(",
")",
"\n",
"}"
] | // SelectInternalHostPort picks one HostPort from a slice that can be
// used as an endpoint for juju internal communication and returns it
// in its NetAddr form. If there are no suitable addresses, the empty
// string is returned. | [
"SelectInternalHostPort",
"picks",
"one",
"HostPort",
"from",
"a",
"slice",
"that",
"can",
"be",
"used",
"as",
"an",
"endpoint",
"for",
"juju",
"internal",
"communication",
"and",
"returns",
"it",
"in",
"its",
"NetAddr",
"form",
".",
"If",
"there",
"are",
"no",
"suitable",
"addresses",
"the",
"empty",
"string",
"is",
"returned",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/network/address.go#L403-L411 |
3,649 | juju/juju | network/address.go | SelectInternalHostPorts | func SelectInternalHostPorts(hps []HostPort, machineLocal bool) []string {
indexes := bestAddressIndexes(len(hps), func(i int) Address {
return hps[i].Address
}, internalAddressMatcher(machineLocal))
out := make([]string, 0, len(indexes))
for _, index := range indexes {
out = append(out, hps[index].NetAddr())
}
return out
} | go | func SelectInternalHostPorts(hps []HostPort, machineLocal bool) []string {
indexes := bestAddressIndexes(len(hps), func(i int) Address {
return hps[i].Address
}, internalAddressMatcher(machineLocal))
out := make([]string, 0, len(indexes))
for _, index := range indexes {
out = append(out, hps[index].NetAddr())
}
return out
} | [
"func",
"SelectInternalHostPorts",
"(",
"hps",
"[",
"]",
"HostPort",
",",
"machineLocal",
"bool",
")",
"[",
"]",
"string",
"{",
"indexes",
":=",
"bestAddressIndexes",
"(",
"len",
"(",
"hps",
")",
",",
"func",
"(",
"i",
"int",
")",
"Address",
"{",
"return",
"hps",
"[",
"i",
"]",
".",
"Address",
"\n",
"}",
",",
"internalAddressMatcher",
"(",
"machineLocal",
")",
")",
"\n\n",
"out",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"indexes",
")",
")",
"\n",
"for",
"_",
",",
"index",
":=",
"range",
"indexes",
"{",
"out",
"=",
"append",
"(",
"out",
",",
"hps",
"[",
"index",
"]",
".",
"NetAddr",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"out",
"\n",
"}"
] | // SelectInternalHostPorts picks the best matching HostPorts from a
// slice that can be used as an endpoint for juju internal
// communication and returns them in NetAddr form. If there are no
// suitable addresses, an empty slice is returned. | [
"SelectInternalHostPorts",
"picks",
"the",
"best",
"matching",
"HostPorts",
"from",
"a",
"slice",
"that",
"can",
"be",
"used",
"as",
"an",
"endpoint",
"for",
"juju",
"internal",
"communication",
"and",
"returns",
"them",
"in",
"NetAddr",
"form",
".",
"If",
"there",
"are",
"no",
"suitable",
"addresses",
"an",
"empty",
"slice",
"is",
"returned",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/network/address.go#L417-L427 |
3,650 | juju/juju | network/address.go | DecimalToIPv4 | func DecimalToIPv4(addr uint32) net.IP {
bytes := make([]byte, 4)
binary.BigEndian.PutUint32(bytes, addr)
return net.IP(bytes)
} | go | func DecimalToIPv4(addr uint32) net.IP {
bytes := make([]byte, 4)
binary.BigEndian.PutUint32(bytes, addr)
return net.IP(bytes)
} | [
"func",
"DecimalToIPv4",
"(",
"addr",
"uint32",
")",
"net",
".",
"IP",
"{",
"bytes",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"4",
")",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint32",
"(",
"bytes",
",",
"addr",
")",
"\n",
"return",
"net",
".",
"IP",
"(",
"bytes",
")",
"\n",
"}"
] | // DecimalToIPv4 converts a decimal to the dotted quad IP address format. | [
"DecimalToIPv4",
"converts",
"a",
"decimal",
"to",
"the",
"dotted",
"quad",
"IP",
"address",
"format",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/network/address.go#L636-L640 |
3,651 | juju/juju | network/address.go | IPv4ToDecimal | func IPv4ToDecimal(ipv4Addr net.IP) (uint32, error) {
ip := ipv4Addr.To4()
if ip == nil {
return 0, errors.Errorf("%q is not a valid IPv4 address", ipv4Addr.String())
}
return binary.BigEndian.Uint32([]byte(ip)), nil
} | go | func IPv4ToDecimal(ipv4Addr net.IP) (uint32, error) {
ip := ipv4Addr.To4()
if ip == nil {
return 0, errors.Errorf("%q is not a valid IPv4 address", ipv4Addr.String())
}
return binary.BigEndian.Uint32([]byte(ip)), nil
} | [
"func",
"IPv4ToDecimal",
"(",
"ipv4Addr",
"net",
".",
"IP",
")",
"(",
"uint32",
",",
"error",
")",
"{",
"ip",
":=",
"ipv4Addr",
".",
"To4",
"(",
")",
"\n",
"if",
"ip",
"==",
"nil",
"{",
"return",
"0",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ipv4Addr",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"binary",
".",
"BigEndian",
".",
"Uint32",
"(",
"[",
"]",
"byte",
"(",
"ip",
")",
")",
",",
"nil",
"\n",
"}"
] | // IPv4ToDecimal converts a dotted quad IP address to its decimal equivalent. | [
"IPv4ToDecimal",
"converts",
"a",
"dotted",
"quad",
"IP",
"address",
"to",
"its",
"decimal",
"equivalent",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/network/address.go#L643-L649 |
3,652 | juju/juju | worker/storageprovisioner/blockdevices.go | machineBlockDevicesChanged | func machineBlockDevicesChanged(ctx *context) error {
volumeTags := make([]names.VolumeTag, 0, len(ctx.incompleteFilesystemParams))
// We must query volumes for both incomplete filesystems
// and incomplete filesystem attachments, because even
// though a filesystem attachment cannot exist without a
// filesystem, the filesystem may be created and attached
// in different sessions, and there is no guarantee that
// the block device will remain attached to the machine
// in between.
for _, params := range ctx.incompleteFilesystemParams {
if params.Volume == (names.VolumeTag{}) {
// Filesystem is not volume-backed.
continue
}
if _, ok := ctx.volumeBlockDevices[params.Volume]; ok {
// Backing-volume's block device is already attached.
continue
}
volumeTags = append(volumeTags, params.Volume)
}
for _, params := range ctx.incompleteFilesystemAttachmentParams {
filesystem, ok := ctx.filesystems[params.Filesystem]
if !ok {
continue
}
if filesystem.Volume == (names.VolumeTag{}) {
// Filesystem is not volume-backed.
continue
}
if _, ok := ctx.volumeBlockDevices[filesystem.Volume]; ok {
// Backing-volume's block device is already attached.
continue
}
var found bool
for _, tag := range volumeTags {
if filesystem.Volume == tag {
found = true
break
}
}
if !found {
volumeTags = append(volumeTags, filesystem.Volume)
}
}
if len(volumeTags) == 0 {
return nil
}
return refreshVolumeBlockDevices(ctx, volumeTags)
} | go | func machineBlockDevicesChanged(ctx *context) error {
volumeTags := make([]names.VolumeTag, 0, len(ctx.incompleteFilesystemParams))
// We must query volumes for both incomplete filesystems
// and incomplete filesystem attachments, because even
// though a filesystem attachment cannot exist without a
// filesystem, the filesystem may be created and attached
// in different sessions, and there is no guarantee that
// the block device will remain attached to the machine
// in between.
for _, params := range ctx.incompleteFilesystemParams {
if params.Volume == (names.VolumeTag{}) {
// Filesystem is not volume-backed.
continue
}
if _, ok := ctx.volumeBlockDevices[params.Volume]; ok {
// Backing-volume's block device is already attached.
continue
}
volumeTags = append(volumeTags, params.Volume)
}
for _, params := range ctx.incompleteFilesystemAttachmentParams {
filesystem, ok := ctx.filesystems[params.Filesystem]
if !ok {
continue
}
if filesystem.Volume == (names.VolumeTag{}) {
// Filesystem is not volume-backed.
continue
}
if _, ok := ctx.volumeBlockDevices[filesystem.Volume]; ok {
// Backing-volume's block device is already attached.
continue
}
var found bool
for _, tag := range volumeTags {
if filesystem.Volume == tag {
found = true
break
}
}
if !found {
volumeTags = append(volumeTags, filesystem.Volume)
}
}
if len(volumeTags) == 0 {
return nil
}
return refreshVolumeBlockDevices(ctx, volumeTags)
} | [
"func",
"machineBlockDevicesChanged",
"(",
"ctx",
"*",
"context",
")",
"error",
"{",
"volumeTags",
":=",
"make",
"(",
"[",
"]",
"names",
".",
"VolumeTag",
",",
"0",
",",
"len",
"(",
"ctx",
".",
"incompleteFilesystemParams",
")",
")",
"\n",
"// We must query volumes for both incomplete filesystems",
"// and incomplete filesystem attachments, because even",
"// though a filesystem attachment cannot exist without a",
"// filesystem, the filesystem may be created and attached",
"// in different sessions, and there is no guarantee that",
"// the block device will remain attached to the machine",
"// in between.",
"for",
"_",
",",
"params",
":=",
"range",
"ctx",
".",
"incompleteFilesystemParams",
"{",
"if",
"params",
".",
"Volume",
"==",
"(",
"names",
".",
"VolumeTag",
"{",
"}",
")",
"{",
"// Filesystem is not volume-backed.",
"continue",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"ctx",
".",
"volumeBlockDevices",
"[",
"params",
".",
"Volume",
"]",
";",
"ok",
"{",
"// Backing-volume's block device is already attached.",
"continue",
"\n",
"}",
"\n",
"volumeTags",
"=",
"append",
"(",
"volumeTags",
",",
"params",
".",
"Volume",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"params",
":=",
"range",
"ctx",
".",
"incompleteFilesystemAttachmentParams",
"{",
"filesystem",
",",
"ok",
":=",
"ctx",
".",
"filesystems",
"[",
"params",
".",
"Filesystem",
"]",
"\n",
"if",
"!",
"ok",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"filesystem",
".",
"Volume",
"==",
"(",
"names",
".",
"VolumeTag",
"{",
"}",
")",
"{",
"// Filesystem is not volume-backed.",
"continue",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"ctx",
".",
"volumeBlockDevices",
"[",
"filesystem",
".",
"Volume",
"]",
";",
"ok",
"{",
"// Backing-volume's block device is already attached.",
"continue",
"\n",
"}",
"\n",
"var",
"found",
"bool",
"\n",
"for",
"_",
",",
"tag",
":=",
"range",
"volumeTags",
"{",
"if",
"filesystem",
".",
"Volume",
"==",
"tag",
"{",
"found",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"found",
"{",
"volumeTags",
"=",
"append",
"(",
"volumeTags",
",",
"filesystem",
".",
"Volume",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"volumeTags",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"refreshVolumeBlockDevices",
"(",
"ctx",
",",
"volumeTags",
")",
"\n",
"}"
] | // machineBlockDevicesChanged is called when the block devices of the scoped
// machine have been seen to have changed. This triggers a refresh of all
// block devices for attached volumes backing pending filesystems. | [
"machineBlockDevicesChanged",
"is",
"called",
"when",
"the",
"block",
"devices",
"of",
"the",
"scoped",
"machine",
"have",
"been",
"seen",
"to",
"have",
"changed",
".",
"This",
"triggers",
"a",
"refresh",
"of",
"all",
"block",
"devices",
"for",
"attached",
"volumes",
"backing",
"pending",
"filesystems",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/storageprovisioner/blockdevices.go#L16-L64 |
3,653 | juju/juju | worker/storageprovisioner/blockdevices.go | processPendingVolumeBlockDevices | func processPendingVolumeBlockDevices(ctx *context) error {
if len(ctx.pendingVolumeBlockDevices) == 0 {
logger.Tracef("no pending volume block devices")
return nil
}
volumeTags := make([]names.VolumeTag, len(ctx.pendingVolumeBlockDevices))
for i, tag := range ctx.pendingVolumeBlockDevices.SortedValues() {
volumeTags[i] = tag.(names.VolumeTag)
}
// Clear out the pending set, so we don't force-refresh again.
ctx.pendingVolumeBlockDevices = names.NewSet()
return refreshVolumeBlockDevices(ctx, volumeTags)
} | go | func processPendingVolumeBlockDevices(ctx *context) error {
if len(ctx.pendingVolumeBlockDevices) == 0 {
logger.Tracef("no pending volume block devices")
return nil
}
volumeTags := make([]names.VolumeTag, len(ctx.pendingVolumeBlockDevices))
for i, tag := range ctx.pendingVolumeBlockDevices.SortedValues() {
volumeTags[i] = tag.(names.VolumeTag)
}
// Clear out the pending set, so we don't force-refresh again.
ctx.pendingVolumeBlockDevices = names.NewSet()
return refreshVolumeBlockDevices(ctx, volumeTags)
} | [
"func",
"processPendingVolumeBlockDevices",
"(",
"ctx",
"*",
"context",
")",
"error",
"{",
"if",
"len",
"(",
"ctx",
".",
"pendingVolumeBlockDevices",
")",
"==",
"0",
"{",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"volumeTags",
":=",
"make",
"(",
"[",
"]",
"names",
".",
"VolumeTag",
",",
"len",
"(",
"ctx",
".",
"pendingVolumeBlockDevices",
")",
")",
"\n",
"for",
"i",
",",
"tag",
":=",
"range",
"ctx",
".",
"pendingVolumeBlockDevices",
".",
"SortedValues",
"(",
")",
"{",
"volumeTags",
"[",
"i",
"]",
"=",
"tag",
".",
"(",
"names",
".",
"VolumeTag",
")",
"\n",
"}",
"\n",
"// Clear out the pending set, so we don't force-refresh again.",
"ctx",
".",
"pendingVolumeBlockDevices",
"=",
"names",
".",
"NewSet",
"(",
")",
"\n",
"return",
"refreshVolumeBlockDevices",
"(",
"ctx",
",",
"volumeTags",
")",
"\n",
"}"
] | // processPendingVolumeBlockDevices is called before waiting for any events,
// to force a block-device query for any volumes for which we have not
// previously observed block devices. | [
"processPendingVolumeBlockDevices",
"is",
"called",
"before",
"waiting",
"for",
"any",
"events",
"to",
"force",
"a",
"block",
"-",
"device",
"query",
"for",
"any",
"volumes",
"for",
"which",
"we",
"have",
"not",
"previously",
"observed",
"block",
"devices",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/storageprovisioner/blockdevices.go#L69-L81 |
3,654 | juju/juju | worker/storageprovisioner/blockdevices.go | refreshVolumeBlockDevices | func refreshVolumeBlockDevices(ctx *context, volumeTags []names.VolumeTag) error {
machineTag, ok := ctx.config.Scope.(names.MachineTag)
if !ok {
// This function should only be called by machine-scoped
// storage provisioners.
logger.Warningf("refresh block devices, expected machine tag, got %v", ctx.config.Scope)
return nil
}
ids := make([]params.MachineStorageId, len(volumeTags))
for i, volumeTag := range volumeTags {
ids[i] = params.MachineStorageId{
MachineTag: machineTag.String(),
AttachmentTag: volumeTag.String(),
}
}
results, err := ctx.config.Volumes.VolumeBlockDevices(ids)
if err != nil {
return errors.Annotate(err, "refreshing volume block devices")
}
for i, result := range results {
if result.Error == nil {
ctx.volumeBlockDevices[volumeTags[i]] = result.Result
for _, params := range ctx.incompleteFilesystemParams {
if params.Volume == volumeTags[i] {
updatePendingFilesystem(ctx, params)
}
}
for id, params := range ctx.incompleteFilesystemAttachmentParams {
filesystem, ok := ctx.filesystems[params.Filesystem]
if !ok {
continue
}
if filesystem.Volume == volumeTags[i] {
updatePendingFilesystemAttachment(ctx, id, params)
}
}
} else if params.IsCodeNotProvisioned(result.Error) || params.IsCodeNotFound(result.Error) {
// Either the volume (attachment) isn't provisioned,
// or the corresponding block device is not yet known.
//
// Neither of these errors is fatal; we just wait for
// the block device watcher to notify us again.
} else {
return errors.Annotatef(
err, "getting block device info for volume attachment %v",
ids[i],
)
}
}
return nil
} | go | func refreshVolumeBlockDevices(ctx *context, volumeTags []names.VolumeTag) error {
machineTag, ok := ctx.config.Scope.(names.MachineTag)
if !ok {
// This function should only be called by machine-scoped
// storage provisioners.
logger.Warningf("refresh block devices, expected machine tag, got %v", ctx.config.Scope)
return nil
}
ids := make([]params.MachineStorageId, len(volumeTags))
for i, volumeTag := range volumeTags {
ids[i] = params.MachineStorageId{
MachineTag: machineTag.String(),
AttachmentTag: volumeTag.String(),
}
}
results, err := ctx.config.Volumes.VolumeBlockDevices(ids)
if err != nil {
return errors.Annotate(err, "refreshing volume block devices")
}
for i, result := range results {
if result.Error == nil {
ctx.volumeBlockDevices[volumeTags[i]] = result.Result
for _, params := range ctx.incompleteFilesystemParams {
if params.Volume == volumeTags[i] {
updatePendingFilesystem(ctx, params)
}
}
for id, params := range ctx.incompleteFilesystemAttachmentParams {
filesystem, ok := ctx.filesystems[params.Filesystem]
if !ok {
continue
}
if filesystem.Volume == volumeTags[i] {
updatePendingFilesystemAttachment(ctx, id, params)
}
}
} else if params.IsCodeNotProvisioned(result.Error) || params.IsCodeNotFound(result.Error) {
// Either the volume (attachment) isn't provisioned,
// or the corresponding block device is not yet known.
//
// Neither of these errors is fatal; we just wait for
// the block device watcher to notify us again.
} else {
return errors.Annotatef(
err, "getting block device info for volume attachment %v",
ids[i],
)
}
}
return nil
} | [
"func",
"refreshVolumeBlockDevices",
"(",
"ctx",
"*",
"context",
",",
"volumeTags",
"[",
"]",
"names",
".",
"VolumeTag",
")",
"error",
"{",
"machineTag",
",",
"ok",
":=",
"ctx",
".",
"config",
".",
"Scope",
".",
"(",
"names",
".",
"MachineTag",
")",
"\n",
"if",
"!",
"ok",
"{",
"// This function should only be called by machine-scoped",
"// storage provisioners.",
"logger",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"ctx",
".",
"config",
".",
"Scope",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"ids",
":=",
"make",
"(",
"[",
"]",
"params",
".",
"MachineStorageId",
",",
"len",
"(",
"volumeTags",
")",
")",
"\n",
"for",
"i",
",",
"volumeTag",
":=",
"range",
"volumeTags",
"{",
"ids",
"[",
"i",
"]",
"=",
"params",
".",
"MachineStorageId",
"{",
"MachineTag",
":",
"machineTag",
".",
"String",
"(",
")",
",",
"AttachmentTag",
":",
"volumeTag",
".",
"String",
"(",
")",
",",
"}",
"\n",
"}",
"\n",
"results",
",",
"err",
":=",
"ctx",
".",
"config",
".",
"Volumes",
".",
"VolumeBlockDevices",
"(",
"ids",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"for",
"i",
",",
"result",
":=",
"range",
"results",
"{",
"if",
"result",
".",
"Error",
"==",
"nil",
"{",
"ctx",
".",
"volumeBlockDevices",
"[",
"volumeTags",
"[",
"i",
"]",
"]",
"=",
"result",
".",
"Result",
"\n",
"for",
"_",
",",
"params",
":=",
"range",
"ctx",
".",
"incompleteFilesystemParams",
"{",
"if",
"params",
".",
"Volume",
"==",
"volumeTags",
"[",
"i",
"]",
"{",
"updatePendingFilesystem",
"(",
"ctx",
",",
"params",
")",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"id",
",",
"params",
":=",
"range",
"ctx",
".",
"incompleteFilesystemAttachmentParams",
"{",
"filesystem",
",",
"ok",
":=",
"ctx",
".",
"filesystems",
"[",
"params",
".",
"Filesystem",
"]",
"\n",
"if",
"!",
"ok",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"filesystem",
".",
"Volume",
"==",
"volumeTags",
"[",
"i",
"]",
"{",
"updatePendingFilesystemAttachment",
"(",
"ctx",
",",
"id",
",",
"params",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"else",
"if",
"params",
".",
"IsCodeNotProvisioned",
"(",
"result",
".",
"Error",
")",
"||",
"params",
".",
"IsCodeNotFound",
"(",
"result",
".",
"Error",
")",
"{",
"// Either the volume (attachment) isn't provisioned,",
"// or the corresponding block device is not yet known.",
"//",
"// Neither of these errors is fatal; we just wait for",
"// the block device watcher to notify us again.",
"}",
"else",
"{",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"ids",
"[",
"i",
"]",
",",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // refreshVolumeBlockDevices refreshes the block devices for the specified
// volumes. | [
"refreshVolumeBlockDevices",
"refreshes",
"the",
"block",
"devices",
"for",
"the",
"specified",
"volumes",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/storageprovisioner/blockdevices.go#L85-L135 |
3,655 | juju/juju | state/binarystorage/layered.go | NewLayeredStorage | func NewLayeredStorage(s ...Storage) (Storage, error) {
if len(s) <= 1 {
return nil, errors.Errorf("expected multiple stores")
}
return layeredStorage(s), nil
} | go | func NewLayeredStorage(s ...Storage) (Storage, error) {
if len(s) <= 1 {
return nil, errors.Errorf("expected multiple stores")
}
return layeredStorage(s), nil
} | [
"func",
"NewLayeredStorage",
"(",
"s",
"...",
"Storage",
")",
"(",
"Storage",
",",
"error",
")",
"{",
"if",
"len",
"(",
"s",
")",
"<=",
"1",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"layeredStorage",
"(",
"s",
")",
",",
"nil",
"\n",
"}"
] | // NewLayeredStorage wraps multiple Storages such all of their metadata
// can be listed and fetched. The later entries in the list have lower
// precedence than the earlier ones. The first entry in the list is always
// used for mutating operations. | [
"NewLayeredStorage",
"wraps",
"multiple",
"Storages",
"such",
"all",
"of",
"their",
"metadata",
"can",
"be",
"listed",
"and",
"fetched",
".",
"The",
"later",
"entries",
"in",
"the",
"list",
"have",
"lower",
"precedence",
"than",
"the",
"earlier",
"ones",
".",
"The",
"first",
"entry",
"in",
"the",
"list",
"is",
"always",
"used",
"for",
"mutating",
"operations",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/binarystorage/layered.go#L19-L24 |
3,656 | juju/juju | state/binarystorage/layered.go | Add | func (s layeredStorage) Add(r io.Reader, m Metadata) error {
return s[0].Add(r, m)
} | go | func (s layeredStorage) Add(r io.Reader, m Metadata) error {
return s[0].Add(r, m)
} | [
"func",
"(",
"s",
"layeredStorage",
")",
"Add",
"(",
"r",
"io",
".",
"Reader",
",",
"m",
"Metadata",
")",
"error",
"{",
"return",
"s",
"[",
"0",
"]",
".",
"Add",
"(",
"r",
",",
"m",
")",
"\n",
"}"
] | // Add implements Storage.Add.
//
// This method operates on the first Storage passed to NewLayeredStorage. | [
"Add",
"implements",
"Storage",
".",
"Add",
".",
"This",
"method",
"operates",
"on",
"the",
"first",
"Storage",
"passed",
"to",
"NewLayeredStorage",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/binarystorage/layered.go#L29-L31 |
3,657 | juju/juju | state/binarystorage/layered.go | Open | func (s layeredStorage) Open(v string) (Metadata, io.ReadCloser, error) {
var m Metadata
var rc io.ReadCloser
var err error
for _, s := range s {
m, rc, err = s.Open(v)
if !errors.IsNotFound(err) {
break
}
}
return m, rc, err
} | go | func (s layeredStorage) Open(v string) (Metadata, io.ReadCloser, error) {
var m Metadata
var rc io.ReadCloser
var err error
for _, s := range s {
m, rc, err = s.Open(v)
if !errors.IsNotFound(err) {
break
}
}
return m, rc, err
} | [
"func",
"(",
"s",
"layeredStorage",
")",
"Open",
"(",
"v",
"string",
")",
"(",
"Metadata",
",",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"var",
"m",
"Metadata",
"\n",
"var",
"rc",
"io",
".",
"ReadCloser",
"\n",
"var",
"err",
"error",
"\n",
"for",
"_",
",",
"s",
":=",
"range",
"s",
"{",
"m",
",",
"rc",
",",
"err",
"=",
"s",
".",
"Open",
"(",
"v",
")",
"\n",
"if",
"!",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"m",
",",
"rc",
",",
"err",
"\n",
"}"
] | // Open implements Storage.Open.
//
// This method calls Open for each Storage passed to NewLayeredStorage in
// the order given, and returns the first result where the error does not
// satisfy errors.IsNotFound. | [
"Open",
"implements",
"Storage",
".",
"Open",
".",
"This",
"method",
"calls",
"Open",
"for",
"each",
"Storage",
"passed",
"to",
"NewLayeredStorage",
"in",
"the",
"order",
"given",
"and",
"returns",
"the",
"first",
"result",
"where",
"the",
"error",
"does",
"not",
"satisfy",
"errors",
".",
"IsNotFound",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/binarystorage/layered.go#L38-L49 |
3,658 | juju/juju | state/binarystorage/layered.go | Metadata | func (s layeredStorage) Metadata(v string) (Metadata, error) {
var m Metadata
var err error
for _, s := range s {
m, err = s.Metadata(v)
if !errors.IsNotFound(err) {
break
}
}
return m, err
} | go | func (s layeredStorage) Metadata(v string) (Metadata, error) {
var m Metadata
var err error
for _, s := range s {
m, err = s.Metadata(v)
if !errors.IsNotFound(err) {
break
}
}
return m, err
} | [
"func",
"(",
"s",
"layeredStorage",
")",
"Metadata",
"(",
"v",
"string",
")",
"(",
"Metadata",
",",
"error",
")",
"{",
"var",
"m",
"Metadata",
"\n",
"var",
"err",
"error",
"\n",
"for",
"_",
",",
"s",
":=",
"range",
"s",
"{",
"m",
",",
"err",
"=",
"s",
".",
"Metadata",
"(",
"v",
")",
"\n",
"if",
"!",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"m",
",",
"err",
"\n",
"}"
] | // Metadata implements Storage.Metadata.
//
// This method calls Metadata for each Storage passed to NewLayeredStorage in
// the order given, and returns the first result where the error does not
// satisfy errors.IsNotFound. | [
"Metadata",
"implements",
"Storage",
".",
"Metadata",
".",
"This",
"method",
"calls",
"Metadata",
"for",
"each",
"Storage",
"passed",
"to",
"NewLayeredStorage",
"in",
"the",
"order",
"given",
"and",
"returns",
"the",
"first",
"result",
"where",
"the",
"error",
"does",
"not",
"satisfy",
"errors",
".",
"IsNotFound",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/binarystorage/layered.go#L56-L66 |
3,659 | juju/juju | state/binarystorage/layered.go | AllMetadata | func (s layeredStorage) AllMetadata() ([]Metadata, error) {
seen := set.NewStrings()
var all []Metadata
for _, s := range s {
sm, err := s.AllMetadata()
if err != nil {
return nil, err
}
for _, m := range sm {
if seen.Contains(m.Version) {
continue
}
all = append(all, m)
seen.Add(m.Version)
}
}
return all, nil
} | go | func (s layeredStorage) AllMetadata() ([]Metadata, error) {
seen := set.NewStrings()
var all []Metadata
for _, s := range s {
sm, err := s.AllMetadata()
if err != nil {
return nil, err
}
for _, m := range sm {
if seen.Contains(m.Version) {
continue
}
all = append(all, m)
seen.Add(m.Version)
}
}
return all, nil
} | [
"func",
"(",
"s",
"layeredStorage",
")",
"AllMetadata",
"(",
")",
"(",
"[",
"]",
"Metadata",
",",
"error",
")",
"{",
"seen",
":=",
"set",
".",
"NewStrings",
"(",
")",
"\n",
"var",
"all",
"[",
"]",
"Metadata",
"\n",
"for",
"_",
",",
"s",
":=",
"range",
"s",
"{",
"sm",
",",
"err",
":=",
"s",
".",
"AllMetadata",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"m",
":=",
"range",
"sm",
"{",
"if",
"seen",
".",
"Contains",
"(",
"m",
".",
"Version",
")",
"{",
"continue",
"\n",
"}",
"\n",
"all",
"=",
"append",
"(",
"all",
",",
"m",
")",
"\n",
"seen",
".",
"Add",
"(",
"m",
".",
"Version",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"all",
",",
"nil",
"\n",
"}"
] | // AllMetadata implements Storage.AllMetadata.
//
// This method calls AllMetadata for each Storage passed to NewLayeredStorage
// in the order given, and accumulates the results. Any results from a Storage
// earlier in the list will take precedence over any others with the same
// version. | [
"AllMetadata",
"implements",
"Storage",
".",
"AllMetadata",
".",
"This",
"method",
"calls",
"AllMetadata",
"for",
"each",
"Storage",
"passed",
"to",
"NewLayeredStorage",
"in",
"the",
"order",
"given",
"and",
"accumulates",
"the",
"results",
".",
"Any",
"results",
"from",
"a",
"Storage",
"earlier",
"in",
"the",
"list",
"will",
"take",
"precedence",
"over",
"any",
"others",
"with",
"the",
"same",
"version",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/binarystorage/layered.go#L74-L91 |
3,660 | juju/juju | state/resources_persistence_staged.go | Unstage | func (staged StagedResource) Unstage() error {
buildTxn := func(attempt int) ([]txn.Op, error) {
if attempt > 0 {
// The op has no assert so we should not get here.
return nil, errors.New("unstaging the resource failed")
}
ops := newRemoveStagedResourceOps(staged.id)
return ops, nil
}
if err := staged.base.Run(buildTxn); err != nil {
return errors.Trace(err)
}
return nil
} | go | func (staged StagedResource) Unstage() error {
buildTxn := func(attempt int) ([]txn.Op, error) {
if attempt > 0 {
// The op has no assert so we should not get here.
return nil, errors.New("unstaging the resource failed")
}
ops := newRemoveStagedResourceOps(staged.id)
return ops, nil
}
if err := staged.base.Run(buildTxn); err != nil {
return errors.Trace(err)
}
return nil
} | [
"func",
"(",
"staged",
"StagedResource",
")",
"Unstage",
"(",
")",
"error",
"{",
"buildTxn",
":=",
"func",
"(",
"attempt",
"int",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"if",
"attempt",
">",
"0",
"{",
"// The op has no assert so we should not get here.",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"ops",
":=",
"newRemoveStagedResourceOps",
"(",
"staged",
".",
"id",
")",
"\n",
"return",
"ops",
",",
"nil",
"\n",
"}",
"\n",
"if",
"err",
":=",
"staged",
".",
"base",
".",
"Run",
"(",
"buildTxn",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Unstage ensures that the resource is removed
// from the staging area. If it isn't in the staging area
// then this is a noop. | [
"Unstage",
"ensures",
"that",
"the",
"resource",
"is",
"removed",
"from",
"the",
"staging",
"area",
".",
"If",
"it",
"isn",
"t",
"in",
"the",
"staging",
"area",
"then",
"this",
"is",
"a",
"noop",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/resources_persistence_staged.go#L50-L64 |
3,661 | juju/juju | state/resources_persistence_staged.go | Activate | func (staged StagedResource) Activate() error {
buildTxn := func(attempt int) ([]txn.Op, error) {
// This is an "upsert".
var ops []txn.Op
switch attempt {
case 0:
ops = newInsertResourceOps(staged.stored)
case 1:
ops = newUpdateResourceOps(staged.stored)
default:
return nil, errors.New("setting the resource failed")
}
if staged.stored.PendingID == "" {
// Only non-pending resources must have an existing application.
ops = append(ops, staged.base.ApplicationExistsOps(staged.stored.ApplicationID)...)
}
// No matter what, we always remove any staging.
ops = append(ops, newRemoveStagedResourceOps(staged.id)...)
// If we are changing the bytes for a resource, we increment the
// CharmModifiedVersion on the application, since resources are integral to
// the high level "version" of the charm.
if staged.stored.PendingID == "" {
hasNewBytes, err := staged.hasNewBytes()
if err != nil {
logger.Errorf("can't read existing resource during activate: %v", errors.Details(err))
return nil, errors.Trace(err)
}
if hasNewBytes {
incOps := staged.base.IncCharmModifiedVersionOps(staged.stored.ApplicationID)
ops = append(ops, incOps...)
}
}
return ops, nil
}
if err := staged.base.Run(buildTxn); err != nil {
return errors.Trace(err)
}
return nil
} | go | func (staged StagedResource) Activate() error {
buildTxn := func(attempt int) ([]txn.Op, error) {
// This is an "upsert".
var ops []txn.Op
switch attempt {
case 0:
ops = newInsertResourceOps(staged.stored)
case 1:
ops = newUpdateResourceOps(staged.stored)
default:
return nil, errors.New("setting the resource failed")
}
if staged.stored.PendingID == "" {
// Only non-pending resources must have an existing application.
ops = append(ops, staged.base.ApplicationExistsOps(staged.stored.ApplicationID)...)
}
// No matter what, we always remove any staging.
ops = append(ops, newRemoveStagedResourceOps(staged.id)...)
// If we are changing the bytes for a resource, we increment the
// CharmModifiedVersion on the application, since resources are integral to
// the high level "version" of the charm.
if staged.stored.PendingID == "" {
hasNewBytes, err := staged.hasNewBytes()
if err != nil {
logger.Errorf("can't read existing resource during activate: %v", errors.Details(err))
return nil, errors.Trace(err)
}
if hasNewBytes {
incOps := staged.base.IncCharmModifiedVersionOps(staged.stored.ApplicationID)
ops = append(ops, incOps...)
}
}
return ops, nil
}
if err := staged.base.Run(buildTxn); err != nil {
return errors.Trace(err)
}
return nil
} | [
"func",
"(",
"staged",
"StagedResource",
")",
"Activate",
"(",
")",
"error",
"{",
"buildTxn",
":=",
"func",
"(",
"attempt",
"int",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"// This is an \"upsert\".",
"var",
"ops",
"[",
"]",
"txn",
".",
"Op",
"\n",
"switch",
"attempt",
"{",
"case",
"0",
":",
"ops",
"=",
"newInsertResourceOps",
"(",
"staged",
".",
"stored",
")",
"\n",
"case",
"1",
":",
"ops",
"=",
"newUpdateResourceOps",
"(",
"staged",
".",
"stored",
")",
"\n",
"default",
":",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"staged",
".",
"stored",
".",
"PendingID",
"==",
"\"",
"\"",
"{",
"// Only non-pending resources must have an existing application.",
"ops",
"=",
"append",
"(",
"ops",
",",
"staged",
".",
"base",
".",
"ApplicationExistsOps",
"(",
"staged",
".",
"stored",
".",
"ApplicationID",
")",
"...",
")",
"\n",
"}",
"\n",
"// No matter what, we always remove any staging.",
"ops",
"=",
"append",
"(",
"ops",
",",
"newRemoveStagedResourceOps",
"(",
"staged",
".",
"id",
")",
"...",
")",
"\n\n",
"// If we are changing the bytes for a resource, we increment the",
"// CharmModifiedVersion on the application, since resources are integral to",
"// the high level \"version\" of the charm.",
"if",
"staged",
".",
"stored",
".",
"PendingID",
"==",
"\"",
"\"",
"{",
"hasNewBytes",
",",
"err",
":=",
"staged",
".",
"hasNewBytes",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"errors",
".",
"Details",
"(",
"err",
")",
")",
"\n",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"hasNewBytes",
"{",
"incOps",
":=",
"staged",
".",
"base",
".",
"IncCharmModifiedVersionOps",
"(",
"staged",
".",
"stored",
".",
"ApplicationID",
")",
"\n",
"ops",
"=",
"append",
"(",
"ops",
",",
"incOps",
"...",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"ops",
",",
"nil",
"\n",
"}",
"\n",
"if",
"err",
":=",
"staged",
".",
"base",
".",
"Run",
"(",
"buildTxn",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Activate makes the staged resource the active resource. | [
"Activate",
"makes",
"the",
"staged",
"resource",
"the",
"active",
"resource",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/resources_persistence_staged.go#L67-L106 |
3,662 | juju/juju | state/action.go | Id | func (a *action) Id() string {
return a.st.localID(a.doc.DocId)
} | go | func (a *action) Id() string {
return a.st.localID(a.doc.DocId)
} | [
"func",
"(",
"a",
"*",
"action",
")",
"Id",
"(",
")",
"string",
"{",
"return",
"a",
".",
"st",
".",
"localID",
"(",
"a",
".",
"doc",
".",
"DocId",
")",
"\n",
"}"
] | // Id returns the local id of the Action. | [
"Id",
"returns",
"the",
"local",
"id",
"of",
"the",
"Action",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/action.go#L117-L119 |
3,663 | juju/juju | state/action.go | Results | func (a *action) Results() (map[string]interface{}, string) {
return a.doc.Results, a.doc.Message
} | go | func (a *action) Results() (map[string]interface{}, string) {
return a.doc.Results, a.doc.Message
} | [
"func",
"(",
"a",
"*",
"action",
")",
"Results",
"(",
")",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"string",
")",
"{",
"return",
"a",
".",
"doc",
".",
"Results",
",",
"a",
".",
"doc",
".",
"Message",
"\n",
"}"
] | // Results returns the structured output of the action and any error. | [
"Results",
"returns",
"the",
"structured",
"output",
"of",
"the",
"action",
"and",
"any",
"error",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/action.go#L161-L163 |
3,664 | juju/juju | state/action.go | Begin | func (a *action) Begin() (Action, error) {
m, err := a.Model()
if err != nil {
return nil, errors.Trace(err)
}
err = m.st.db().RunTransaction([]txn.Op{
{
C: actionsC,
Id: a.doc.DocId,
Assert: bson.D{{"status", ActionPending}},
Update: bson.D{{"$set", bson.D{
{"status", ActionRunning},
{"started", a.st.nowToTheSecond()},
}}},
}})
if err != nil {
return nil, err
}
return m.Action(a.Id())
} | go | func (a *action) Begin() (Action, error) {
m, err := a.Model()
if err != nil {
return nil, errors.Trace(err)
}
err = m.st.db().RunTransaction([]txn.Op{
{
C: actionsC,
Id: a.doc.DocId,
Assert: bson.D{{"status", ActionPending}},
Update: bson.D{{"$set", bson.D{
{"status", ActionRunning},
{"started", a.st.nowToTheSecond()},
}}},
}})
if err != nil {
return nil, err
}
return m.Action(a.Id())
} | [
"func",
"(",
"a",
"*",
"action",
")",
"Begin",
"(",
")",
"(",
"Action",
",",
"error",
")",
"{",
"m",
",",
"err",
":=",
"a",
".",
"Model",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"err",
"=",
"m",
".",
"st",
".",
"db",
"(",
")",
".",
"RunTransaction",
"(",
"[",
"]",
"txn",
".",
"Op",
"{",
"{",
"C",
":",
"actionsC",
",",
"Id",
":",
"a",
".",
"doc",
".",
"DocId",
",",
"Assert",
":",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"ActionPending",
"}",
"}",
",",
"Update",
":",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"ActionRunning",
"}",
",",
"{",
"\"",
"\"",
",",
"a",
".",
"st",
".",
"nowToTheSecond",
"(",
")",
"}",
",",
"}",
"}",
"}",
",",
"}",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"m",
".",
"Action",
"(",
"a",
".",
"Id",
"(",
")",
")",
"\n",
"}"
] | // Begin marks an action as running, and logs the time it was started.
// It asserts that the action is currently pending. | [
"Begin",
"marks",
"an",
"action",
"as",
"running",
"and",
"logs",
"the",
"time",
"it",
"was",
"started",
".",
"It",
"asserts",
"that",
"the",
"action",
"is",
"currently",
"pending",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/action.go#L192-L211 |
3,665 | juju/juju | state/action.go | Finish | func (a *action) Finish(results ActionResults) (Action, error) {
return a.removeAndLog(results.Status, results.Results, results.Message)
} | go | func (a *action) Finish(results ActionResults) (Action, error) {
return a.removeAndLog(results.Status, results.Results, results.Message)
} | [
"func",
"(",
"a",
"*",
"action",
")",
"Finish",
"(",
"results",
"ActionResults",
")",
"(",
"Action",
",",
"error",
")",
"{",
"return",
"a",
".",
"removeAndLog",
"(",
"results",
".",
"Status",
",",
"results",
".",
"Results",
",",
"results",
".",
"Message",
")",
"\n",
"}"
] | // Finish removes action from the pending queue and captures the output
// and end state of the action. | [
"Finish",
"removes",
"action",
"from",
"the",
"pending",
"queue",
"and",
"captures",
"the",
"output",
"and",
"end",
"state",
"of",
"the",
"action",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/action.go#L215-L217 |
3,666 | juju/juju | state/action.go | removeAndLog | func (a *action) removeAndLog(finalStatus ActionStatus, results map[string]interface{}, message string) (Action, error) {
m, err := a.Model()
if err != nil {
return nil, errors.Trace(err)
}
err = m.st.db().RunTransaction([]txn.Op{
{
C: actionsC,
Id: a.doc.DocId,
Assert: bson.D{{"status", bson.D{
{"$nin", []interface{}{
ActionCompleted,
ActionCancelled,
ActionFailed,
}}}}},
Update: bson.D{{"$set", bson.D{
{"status", finalStatus},
{"message", message},
{"results", results},
{"completed", a.st.nowToTheSecond()},
}}},
}, {
C: actionNotificationsC,
Id: m.st.docID(ensureActionMarker(a.Receiver()) + a.Id()),
Remove: true,
}})
if err != nil {
return nil, err
}
return m.Action(a.Id())
} | go | func (a *action) removeAndLog(finalStatus ActionStatus, results map[string]interface{}, message string) (Action, error) {
m, err := a.Model()
if err != nil {
return nil, errors.Trace(err)
}
err = m.st.db().RunTransaction([]txn.Op{
{
C: actionsC,
Id: a.doc.DocId,
Assert: bson.D{{"status", bson.D{
{"$nin", []interface{}{
ActionCompleted,
ActionCancelled,
ActionFailed,
}}}}},
Update: bson.D{{"$set", bson.D{
{"status", finalStatus},
{"message", message},
{"results", results},
{"completed", a.st.nowToTheSecond()},
}}},
}, {
C: actionNotificationsC,
Id: m.st.docID(ensureActionMarker(a.Receiver()) + a.Id()),
Remove: true,
}})
if err != nil {
return nil, err
}
return m.Action(a.Id())
} | [
"func",
"(",
"a",
"*",
"action",
")",
"removeAndLog",
"(",
"finalStatus",
"ActionStatus",
",",
"results",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"message",
"string",
")",
"(",
"Action",
",",
"error",
")",
"{",
"m",
",",
"err",
":=",
"a",
".",
"Model",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"err",
"=",
"m",
".",
"st",
".",
"db",
"(",
")",
".",
"RunTransaction",
"(",
"[",
"]",
"txn",
".",
"Op",
"{",
"{",
"C",
":",
"actionsC",
",",
"Id",
":",
"a",
".",
"doc",
".",
"DocId",
",",
"Assert",
":",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"[",
"]",
"interface",
"{",
"}",
"{",
"ActionCompleted",
",",
"ActionCancelled",
",",
"ActionFailed",
",",
"}",
"}",
"}",
"}",
"}",
",",
"Update",
":",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"finalStatus",
"}",
",",
"{",
"\"",
"\"",
",",
"message",
"}",
",",
"{",
"\"",
"\"",
",",
"results",
"}",
",",
"{",
"\"",
"\"",
",",
"a",
".",
"st",
".",
"nowToTheSecond",
"(",
")",
"}",
",",
"}",
"}",
"}",
",",
"}",
",",
"{",
"C",
":",
"actionNotificationsC",
",",
"Id",
":",
"m",
".",
"st",
".",
"docID",
"(",
"ensureActionMarker",
"(",
"a",
".",
"Receiver",
"(",
")",
")",
"+",
"a",
".",
"Id",
"(",
")",
")",
",",
"Remove",
":",
"true",
",",
"}",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"m",
".",
"Action",
"(",
"a",
".",
"Id",
"(",
")",
")",
"\n",
"}"
] | // removeAndLog takes the action off of the pending queue, and creates
// an actionresult to capture the outcome of the action. It asserts that
// the action is not already completed. | [
"removeAndLog",
"takes",
"the",
"action",
"off",
"of",
"the",
"pending",
"queue",
"and",
"creates",
"an",
"actionresult",
"to",
"capture",
"the",
"outcome",
"of",
"the",
"action",
".",
"It",
"asserts",
"that",
"the",
"action",
"is",
"not",
"already",
"completed",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/action.go#L222-L253 |
3,667 | juju/juju | state/action.go | newAction | func newAction(st *State, adoc actionDoc) Action {
return &action{
st: st,
doc: adoc,
}
} | go | func newAction(st *State, adoc actionDoc) Action {
return &action{
st: st,
doc: adoc,
}
} | [
"func",
"newAction",
"(",
"st",
"*",
"State",
",",
"adoc",
"actionDoc",
")",
"Action",
"{",
"return",
"&",
"action",
"{",
"st",
":",
"st",
",",
"doc",
":",
"adoc",
",",
"}",
"\n",
"}"
] | // newAction builds an Action for the given State and actionDoc. | [
"newAction",
"builds",
"an",
"Action",
"for",
"the",
"given",
"State",
"and",
"actionDoc",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/action.go#L256-L261 |
3,668 | juju/juju | state/action.go | newActionDoc | func newActionDoc(mb modelBackend, receiverTag names.Tag, actionName string, parameters map[string]interface{}) (actionDoc, actionNotificationDoc, error) {
prefix := ensureActionMarker(receiverTag.Id())
actionId, err := NewUUID()
if err != nil {
return actionDoc{}, actionNotificationDoc{}, err
}
actionLogger.Debugf("newActionDoc name: '%s', receiver: '%s', actionId: '%s'", actionName, receiverTag, actionId)
modelUUID := mb.modelUUID()
return actionDoc{
DocId: mb.docID(actionId.String()),
ModelUUID: modelUUID,
Receiver: receiverTag.Id(),
Name: actionName,
Parameters: parameters,
Enqueued: mb.nowToTheSecond(),
Status: ActionPending,
}, actionNotificationDoc{
DocId: mb.docID(prefix + actionId.String()),
ModelUUID: modelUUID,
Receiver: receiverTag.Id(),
ActionID: actionId.String(),
}, nil
} | go | func newActionDoc(mb modelBackend, receiverTag names.Tag, actionName string, parameters map[string]interface{}) (actionDoc, actionNotificationDoc, error) {
prefix := ensureActionMarker(receiverTag.Id())
actionId, err := NewUUID()
if err != nil {
return actionDoc{}, actionNotificationDoc{}, err
}
actionLogger.Debugf("newActionDoc name: '%s', receiver: '%s', actionId: '%s'", actionName, receiverTag, actionId)
modelUUID := mb.modelUUID()
return actionDoc{
DocId: mb.docID(actionId.String()),
ModelUUID: modelUUID,
Receiver: receiverTag.Id(),
Name: actionName,
Parameters: parameters,
Enqueued: mb.nowToTheSecond(),
Status: ActionPending,
}, actionNotificationDoc{
DocId: mb.docID(prefix + actionId.String()),
ModelUUID: modelUUID,
Receiver: receiverTag.Id(),
ActionID: actionId.String(),
}, nil
} | [
"func",
"newActionDoc",
"(",
"mb",
"modelBackend",
",",
"receiverTag",
"names",
".",
"Tag",
",",
"actionName",
"string",
",",
"parameters",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"(",
"actionDoc",
",",
"actionNotificationDoc",
",",
"error",
")",
"{",
"prefix",
":=",
"ensureActionMarker",
"(",
"receiverTag",
".",
"Id",
"(",
")",
")",
"\n",
"actionId",
",",
"err",
":=",
"NewUUID",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"actionDoc",
"{",
"}",
",",
"actionNotificationDoc",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"actionLogger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"actionName",
",",
"receiverTag",
",",
"actionId",
")",
"\n",
"modelUUID",
":=",
"mb",
".",
"modelUUID",
"(",
")",
"\n",
"return",
"actionDoc",
"{",
"DocId",
":",
"mb",
".",
"docID",
"(",
"actionId",
".",
"String",
"(",
")",
")",
",",
"ModelUUID",
":",
"modelUUID",
",",
"Receiver",
":",
"receiverTag",
".",
"Id",
"(",
")",
",",
"Name",
":",
"actionName",
",",
"Parameters",
":",
"parameters",
",",
"Enqueued",
":",
"mb",
".",
"nowToTheSecond",
"(",
")",
",",
"Status",
":",
"ActionPending",
",",
"}",
",",
"actionNotificationDoc",
"{",
"DocId",
":",
"mb",
".",
"docID",
"(",
"prefix",
"+",
"actionId",
".",
"String",
"(",
")",
")",
",",
"ModelUUID",
":",
"modelUUID",
",",
"Receiver",
":",
"receiverTag",
".",
"Id",
"(",
")",
",",
"ActionID",
":",
"actionId",
".",
"String",
"(",
")",
",",
"}",
",",
"nil",
"\n",
"}"
] | // newActionDoc builds the actionDoc with the given name and parameters. | [
"newActionDoc",
"builds",
"the",
"actionDoc",
"with",
"the",
"given",
"name",
"and",
"parameters",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/action.go#L264-L286 |
3,669 | juju/juju | state/action.go | Action | func (m *Model) Action(id string) (Action, error) {
actionLogger.Tracef("Action() %q", id)
st := m.st
actions, closer := st.db().GetCollection(actionsC)
defer closer()
doc := actionDoc{}
err := actions.FindId(id).One(&doc)
if err == mgo.ErrNotFound {
return nil, errors.NotFoundf("action %q", id)
}
if err != nil {
return nil, errors.Annotatef(err, "cannot get action %q", id)
}
actionLogger.Tracef("Action() %q found %+v", id, doc)
return newAction(st, doc), nil
} | go | func (m *Model) Action(id string) (Action, error) {
actionLogger.Tracef("Action() %q", id)
st := m.st
actions, closer := st.db().GetCollection(actionsC)
defer closer()
doc := actionDoc{}
err := actions.FindId(id).One(&doc)
if err == mgo.ErrNotFound {
return nil, errors.NotFoundf("action %q", id)
}
if err != nil {
return nil, errors.Annotatef(err, "cannot get action %q", id)
}
actionLogger.Tracef("Action() %q found %+v", id, doc)
return newAction(st, doc), nil
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"Action",
"(",
"id",
"string",
")",
"(",
"Action",
",",
"error",
")",
"{",
"actionLogger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"id",
")",
"\n",
"st",
":=",
"m",
".",
"st",
"\n",
"actions",
",",
"closer",
":=",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"actionsC",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n\n",
"doc",
":=",
"actionDoc",
"{",
"}",
"\n",
"err",
":=",
"actions",
".",
"FindId",
"(",
"id",
")",
".",
"One",
"(",
"&",
"doc",
")",
"\n",
"if",
"err",
"==",
"mgo",
".",
"ErrNotFound",
"{",
"return",
"nil",
",",
"errors",
".",
"NotFoundf",
"(",
"\"",
"\"",
",",
"id",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"id",
")",
"\n",
"}",
"\n",
"actionLogger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"id",
",",
"doc",
")",
"\n",
"return",
"newAction",
"(",
"st",
",",
"doc",
")",
",",
"nil",
"\n",
"}"
] | // Action returns an Action by Id, which is a UUID. | [
"Action",
"returns",
"an",
"Action",
"by",
"Id",
"which",
"is",
"a",
"UUID",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/action.go#L291-L307 |
3,670 | juju/juju | state/action.go | AllActions | func (m *Model) AllActions() ([]Action, error) {
actionLogger.Tracef("AllActions()")
actions, closer := m.st.db().GetCollection(actionsC)
defer closer()
results := []Action{}
docs := []actionDoc{}
err := actions.Find(nil).All(&docs)
if err != nil {
return nil, errors.Annotatef(err, "cannot get all actions")
}
for _, doc := range docs {
results = append(results, newAction(m.st, doc))
}
return results, nil
} | go | func (m *Model) AllActions() ([]Action, error) {
actionLogger.Tracef("AllActions()")
actions, closer := m.st.db().GetCollection(actionsC)
defer closer()
results := []Action{}
docs := []actionDoc{}
err := actions.Find(nil).All(&docs)
if err != nil {
return nil, errors.Annotatef(err, "cannot get all actions")
}
for _, doc := range docs {
results = append(results, newAction(m.st, doc))
}
return results, nil
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"AllActions",
"(",
")",
"(",
"[",
"]",
"Action",
",",
"error",
")",
"{",
"actionLogger",
".",
"Tracef",
"(",
"\"",
"\"",
")",
"\n",
"actions",
",",
"closer",
":=",
"m",
".",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"actionsC",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n\n",
"results",
":=",
"[",
"]",
"Action",
"{",
"}",
"\n",
"docs",
":=",
"[",
"]",
"actionDoc",
"{",
"}",
"\n",
"err",
":=",
"actions",
".",
"Find",
"(",
"nil",
")",
".",
"All",
"(",
"&",
"docs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"doc",
":=",
"range",
"docs",
"{",
"results",
"=",
"append",
"(",
"results",
",",
"newAction",
"(",
"m",
".",
"st",
",",
"doc",
")",
")",
"\n",
"}",
"\n",
"return",
"results",
",",
"nil",
"\n",
"}"
] | // AllActions returns all Actions. | [
"AllActions",
"returns",
"all",
"Actions",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/action.go#L310-L325 |
3,671 | juju/juju | state/action.go | ActionByTag | func (m *Model) ActionByTag(tag names.ActionTag) (Action, error) {
return m.Action(tag.Id())
} | go | func (m *Model) ActionByTag(tag names.ActionTag) (Action, error) {
return m.Action(tag.Id())
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"ActionByTag",
"(",
"tag",
"names",
".",
"ActionTag",
")",
"(",
"Action",
",",
"error",
")",
"{",
"return",
"m",
".",
"Action",
"(",
"tag",
".",
"Id",
"(",
")",
")",
"\n",
"}"
] | // ActionByTag returns an Action given an ActionTag. | [
"ActionByTag",
"returns",
"an",
"Action",
"given",
"an",
"ActionTag",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/action.go#L328-L330 |
3,672 | juju/juju | state/action.go | FindActionTagsByPrefix | func (m *Model) FindActionTagsByPrefix(prefix string) []names.ActionTag {
actionLogger.Tracef("FindActionTagsByPrefix() %q", prefix)
var results []names.ActionTag
var doc struct {
Id string `bson:"_id"`
}
actions, closer := m.st.db().GetCollection(actionsC)
defer closer()
iter := actions.Find(bson.D{{"_id", bson.D{{"$regex", "^" + m.st.docID(prefix)}}}}).Iter()
defer iter.Close()
for iter.Next(&doc) {
actionLogger.Tracef("FindActionTagsByPrefix() iter doc %+v", doc)
localID := m.st.localID(doc.Id)
if names.IsValidAction(localID) {
results = append(results, names.NewActionTag(localID))
}
}
actionLogger.Tracef("FindActionTagsByPrefix() %q found %+v", prefix, results)
return results
} | go | func (m *Model) FindActionTagsByPrefix(prefix string) []names.ActionTag {
actionLogger.Tracef("FindActionTagsByPrefix() %q", prefix)
var results []names.ActionTag
var doc struct {
Id string `bson:"_id"`
}
actions, closer := m.st.db().GetCollection(actionsC)
defer closer()
iter := actions.Find(bson.D{{"_id", bson.D{{"$regex", "^" + m.st.docID(prefix)}}}}).Iter()
defer iter.Close()
for iter.Next(&doc) {
actionLogger.Tracef("FindActionTagsByPrefix() iter doc %+v", doc)
localID := m.st.localID(doc.Id)
if names.IsValidAction(localID) {
results = append(results, names.NewActionTag(localID))
}
}
actionLogger.Tracef("FindActionTagsByPrefix() %q found %+v", prefix, results)
return results
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"FindActionTagsByPrefix",
"(",
"prefix",
"string",
")",
"[",
"]",
"names",
".",
"ActionTag",
"{",
"actionLogger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"prefix",
")",
"\n",
"var",
"results",
"[",
"]",
"names",
".",
"ActionTag",
"\n",
"var",
"doc",
"struct",
"{",
"Id",
"string",
"`bson:\"_id\"`",
"\n",
"}",
"\n\n",
"actions",
",",
"closer",
":=",
"m",
".",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"actionsC",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n\n",
"iter",
":=",
"actions",
".",
"Find",
"(",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"m",
".",
"st",
".",
"docID",
"(",
"prefix",
")",
"}",
"}",
"}",
"}",
")",
".",
"Iter",
"(",
")",
"\n",
"defer",
"iter",
".",
"Close",
"(",
")",
"\n",
"for",
"iter",
".",
"Next",
"(",
"&",
"doc",
")",
"{",
"actionLogger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"doc",
")",
"\n",
"localID",
":=",
"m",
".",
"st",
".",
"localID",
"(",
"doc",
".",
"Id",
")",
"\n",
"if",
"names",
".",
"IsValidAction",
"(",
"localID",
")",
"{",
"results",
"=",
"append",
"(",
"results",
",",
"names",
".",
"NewActionTag",
"(",
"localID",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"actionLogger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"prefix",
",",
"results",
")",
"\n",
"return",
"results",
"\n",
"}"
] | // FindActionTagsByPrefix finds Actions with ids that share the supplied prefix, and
// returns a list of corresponding ActionTags. | [
"FindActionTagsByPrefix",
"finds",
"Actions",
"with",
"ids",
"that",
"share",
"the",
"supplied",
"prefix",
"and",
"returns",
"a",
"list",
"of",
"corresponding",
"ActionTags",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/action.go#L334-L355 |
3,673 | juju/juju | state/action.go | FindActionsByName | func (m *Model) FindActionsByName(name string) ([]Action, error) {
var results []Action
var doc actionDoc
actions, closer := m.st.db().GetCollection(actionsC)
defer closer()
iter := actions.Find(bson.D{{"name", name}}).Iter()
for iter.Next(&doc) {
results = append(results, newAction(m.st, doc))
}
return results, errors.Trace(iter.Close())
} | go | func (m *Model) FindActionsByName(name string) ([]Action, error) {
var results []Action
var doc actionDoc
actions, closer := m.st.db().GetCollection(actionsC)
defer closer()
iter := actions.Find(bson.D{{"name", name}}).Iter()
for iter.Next(&doc) {
results = append(results, newAction(m.st, doc))
}
return results, errors.Trace(iter.Close())
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"FindActionsByName",
"(",
"name",
"string",
")",
"(",
"[",
"]",
"Action",
",",
"error",
")",
"{",
"var",
"results",
"[",
"]",
"Action",
"\n",
"var",
"doc",
"actionDoc",
"\n\n",
"actions",
",",
"closer",
":=",
"m",
".",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"actionsC",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n\n",
"iter",
":=",
"actions",
".",
"Find",
"(",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"name",
"}",
"}",
")",
".",
"Iter",
"(",
")",
"\n",
"for",
"iter",
".",
"Next",
"(",
"&",
"doc",
")",
"{",
"results",
"=",
"append",
"(",
"results",
",",
"newAction",
"(",
"m",
".",
"st",
",",
"doc",
")",
")",
"\n",
"}",
"\n",
"return",
"results",
",",
"errors",
".",
"Trace",
"(",
"iter",
".",
"Close",
"(",
")",
")",
"\n",
"}"
] | // FindActionsByName finds Actions with the given name. | [
"FindActionsByName",
"finds",
"Actions",
"with",
"the",
"given",
"name",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/action.go#L358-L370 |
3,674 | juju/juju | state/action.go | matchingActions | func (st *State) matchingActions(ar ActionReceiver) ([]Action, error) {
return st.matchingActionsByReceiverId(ar.Tag().Id())
} | go | func (st *State) matchingActions(ar ActionReceiver) ([]Action, error) {
return st.matchingActionsByReceiverId(ar.Tag().Id())
} | [
"func",
"(",
"st",
"*",
"State",
")",
"matchingActions",
"(",
"ar",
"ActionReceiver",
")",
"(",
"[",
"]",
"Action",
",",
"error",
")",
"{",
"return",
"st",
".",
"matchingActionsByReceiverId",
"(",
"ar",
".",
"Tag",
"(",
")",
".",
"Id",
"(",
")",
")",
"\n",
"}"
] | // matchingActions finds actions that match ActionReceiver. | [
"matchingActions",
"finds",
"actions",
"that",
"match",
"ActionReceiver",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/action.go#L421-L423 |
3,675 | juju/juju | state/action.go | matchingActionsByReceiverId | func (st *State) matchingActionsByReceiverId(id string) ([]Action, error) {
var doc actionDoc
var actions []Action
actionsCollection, closer := st.db().GetCollection(actionsC)
defer closer()
iter := actionsCollection.Find(bson.D{{"receiver", id}}).Iter()
for iter.Next(&doc) {
actions = append(actions, newAction(st, doc))
}
return actions, errors.Trace(iter.Close())
} | go | func (st *State) matchingActionsByReceiverId(id string) ([]Action, error) {
var doc actionDoc
var actions []Action
actionsCollection, closer := st.db().GetCollection(actionsC)
defer closer()
iter := actionsCollection.Find(bson.D{{"receiver", id}}).Iter()
for iter.Next(&doc) {
actions = append(actions, newAction(st, doc))
}
return actions, errors.Trace(iter.Close())
} | [
"func",
"(",
"st",
"*",
"State",
")",
"matchingActionsByReceiverId",
"(",
"id",
"string",
")",
"(",
"[",
"]",
"Action",
",",
"error",
")",
"{",
"var",
"doc",
"actionDoc",
"\n",
"var",
"actions",
"[",
"]",
"Action",
"\n\n",
"actionsCollection",
",",
"closer",
":=",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"actionsC",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n\n",
"iter",
":=",
"actionsCollection",
".",
"Find",
"(",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"id",
"}",
"}",
")",
".",
"Iter",
"(",
")",
"\n",
"for",
"iter",
".",
"Next",
"(",
"&",
"doc",
")",
"{",
"actions",
"=",
"append",
"(",
"actions",
",",
"newAction",
"(",
"st",
",",
"doc",
")",
")",
"\n",
"}",
"\n",
"return",
"actions",
",",
"errors",
".",
"Trace",
"(",
"iter",
".",
"Close",
"(",
")",
")",
"\n",
"}"
] | // matchingActionsByReceiverId finds actions that match ActionReceiver name. | [
"matchingActionsByReceiverId",
"finds",
"actions",
"that",
"match",
"ActionReceiver",
"name",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/action.go#L426-L438 |
3,676 | juju/juju | state/action.go | matchingActionsPending | func (st *State) matchingActionsPending(ar ActionReceiver) ([]Action, error) {
completed := bson.D{{"status", ActionPending}}
return st.matchingActionsByReceiverAndStatus(ar.Tag(), completed)
} | go | func (st *State) matchingActionsPending(ar ActionReceiver) ([]Action, error) {
completed := bson.D{{"status", ActionPending}}
return st.matchingActionsByReceiverAndStatus(ar.Tag(), completed)
} | [
"func",
"(",
"st",
"*",
"State",
")",
"matchingActionsPending",
"(",
"ar",
"ActionReceiver",
")",
"(",
"[",
"]",
"Action",
",",
"error",
")",
"{",
"completed",
":=",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"ActionPending",
"}",
"}",
"\n",
"return",
"st",
".",
"matchingActionsByReceiverAndStatus",
"(",
"ar",
".",
"Tag",
"(",
")",
",",
"completed",
")",
"\n",
"}"
] | // matchingActionsPending finds actions that match ActionReceiver and
// that are pending. | [
"matchingActionsPending",
"finds",
"actions",
"that",
"match",
"ActionReceiver",
"and",
"that",
"are",
"pending",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/action.go#L442-L445 |
3,677 | juju/juju | state/action.go | matchingActionsRunning | func (st *State) matchingActionsRunning(ar ActionReceiver) ([]Action, error) {
completed := bson.D{{"status", ActionRunning}}
return st.matchingActionsByReceiverAndStatus(ar.Tag(), completed)
} | go | func (st *State) matchingActionsRunning(ar ActionReceiver) ([]Action, error) {
completed := bson.D{{"status", ActionRunning}}
return st.matchingActionsByReceiverAndStatus(ar.Tag(), completed)
} | [
"func",
"(",
"st",
"*",
"State",
")",
"matchingActionsRunning",
"(",
"ar",
"ActionReceiver",
")",
"(",
"[",
"]",
"Action",
",",
"error",
")",
"{",
"completed",
":=",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"ActionRunning",
"}",
"}",
"\n",
"return",
"st",
".",
"matchingActionsByReceiverAndStatus",
"(",
"ar",
".",
"Tag",
"(",
")",
",",
"completed",
")",
"\n",
"}"
] | // matchingActionsRunning finds actions that match ActionReceiver and
// that are running. | [
"matchingActionsRunning",
"finds",
"actions",
"that",
"match",
"ActionReceiver",
"and",
"that",
"are",
"running",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/action.go#L449-L452 |
3,678 | juju/juju | state/action.go | matchingActionsCompleted | func (st *State) matchingActionsCompleted(ar ActionReceiver) ([]Action, error) {
completed := bson.D{{"$or", []bson.D{
{{"status", ActionCompleted}},
{{"status", ActionCancelled}},
{{"status", ActionFailed}},
}}}
return st.matchingActionsByReceiverAndStatus(ar.Tag(), completed)
} | go | func (st *State) matchingActionsCompleted(ar ActionReceiver) ([]Action, error) {
completed := bson.D{{"$or", []bson.D{
{{"status", ActionCompleted}},
{{"status", ActionCancelled}},
{{"status", ActionFailed}},
}}}
return st.matchingActionsByReceiverAndStatus(ar.Tag(), completed)
} | [
"func",
"(",
"st",
"*",
"State",
")",
"matchingActionsCompleted",
"(",
"ar",
"ActionReceiver",
")",
"(",
"[",
"]",
"Action",
",",
"error",
")",
"{",
"completed",
":=",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"[",
"]",
"bson",
".",
"D",
"{",
"{",
"{",
"\"",
"\"",
",",
"ActionCompleted",
"}",
"}",
",",
"{",
"{",
"\"",
"\"",
",",
"ActionCancelled",
"}",
"}",
",",
"{",
"{",
"\"",
"\"",
",",
"ActionFailed",
"}",
"}",
",",
"}",
"}",
"}",
"\n",
"return",
"st",
".",
"matchingActionsByReceiverAndStatus",
"(",
"ar",
".",
"Tag",
"(",
")",
",",
"completed",
")",
"\n",
"}"
] | // matchingActionsCompleted finds actions that match ActionReceiver and
// that are complete. | [
"matchingActionsCompleted",
"finds",
"actions",
"that",
"match",
"ActionReceiver",
"and",
"that",
"are",
"complete",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/action.go#L456-L463 |
3,679 | juju/juju | state/action.go | matchingActionsByReceiverAndStatus | func (st *State) matchingActionsByReceiverAndStatus(tag names.Tag, statusCondition bson.D) ([]Action, error) {
var doc actionDoc
var actions []Action
actionsCollection, closer := st.db().GetCollection(actionsC)
defer closer()
sel := append(bson.D{{"receiver", tag.Id()}}, statusCondition...)
iter := actionsCollection.Find(sel).Iter()
for iter.Next(&doc) {
actions = append(actions, newAction(st, doc))
}
return actions, errors.Trace(iter.Close())
} | go | func (st *State) matchingActionsByReceiverAndStatus(tag names.Tag, statusCondition bson.D) ([]Action, error) {
var doc actionDoc
var actions []Action
actionsCollection, closer := st.db().GetCollection(actionsC)
defer closer()
sel := append(bson.D{{"receiver", tag.Id()}}, statusCondition...)
iter := actionsCollection.Find(sel).Iter()
for iter.Next(&doc) {
actions = append(actions, newAction(st, doc))
}
return actions, errors.Trace(iter.Close())
} | [
"func",
"(",
"st",
"*",
"State",
")",
"matchingActionsByReceiverAndStatus",
"(",
"tag",
"names",
".",
"Tag",
",",
"statusCondition",
"bson",
".",
"D",
")",
"(",
"[",
"]",
"Action",
",",
"error",
")",
"{",
"var",
"doc",
"actionDoc",
"\n",
"var",
"actions",
"[",
"]",
"Action",
"\n\n",
"actionsCollection",
",",
"closer",
":=",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"actionsC",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n\n",
"sel",
":=",
"append",
"(",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"tag",
".",
"Id",
"(",
")",
"}",
"}",
",",
"statusCondition",
"...",
")",
"\n",
"iter",
":=",
"actionsCollection",
".",
"Find",
"(",
"sel",
")",
".",
"Iter",
"(",
")",
"\n\n",
"for",
"iter",
".",
"Next",
"(",
"&",
"doc",
")",
"{",
"actions",
"=",
"append",
"(",
"actions",
",",
"newAction",
"(",
"st",
",",
"doc",
")",
")",
"\n",
"}",
"\n",
"return",
"actions",
",",
"errors",
".",
"Trace",
"(",
"iter",
".",
"Close",
"(",
")",
")",
"\n",
"}"
] | // matchingActionsByReceiverAndStatus finds actionNotifications that
// match ActionReceiver. | [
"matchingActionsByReceiverAndStatus",
"finds",
"actionNotifications",
"that",
"match",
"ActionReceiver",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/action.go#L467-L481 |
3,680 | juju/juju | api/charms/client.go | CharmInfo | func (c *Client) CharmInfo(charmURL string) (*CharmInfo, error) {
args := params.CharmURL{URL: charmURL}
var info params.CharmInfo
if err := c.facade.FacadeCall("CharmInfo", args, &info); err != nil {
return nil, errors.Trace(err)
}
meta, err := convertCharmMeta(info.Meta)
if err != nil {
return nil, errors.Trace(err)
}
result := &CharmInfo{
Revision: info.Revision,
URL: info.URL,
Config: convertCharmConfig(info.Config),
Meta: meta,
Actions: convertCharmActions(info.Actions),
Metrics: convertCharmMetrics(info.Metrics),
LXDProfile: convertCharmLXDProfile(info.LXDProfile),
}
return result, nil
} | go | func (c *Client) CharmInfo(charmURL string) (*CharmInfo, error) {
args := params.CharmURL{URL: charmURL}
var info params.CharmInfo
if err := c.facade.FacadeCall("CharmInfo", args, &info); err != nil {
return nil, errors.Trace(err)
}
meta, err := convertCharmMeta(info.Meta)
if err != nil {
return nil, errors.Trace(err)
}
result := &CharmInfo{
Revision: info.Revision,
URL: info.URL,
Config: convertCharmConfig(info.Config),
Meta: meta,
Actions: convertCharmActions(info.Actions),
Metrics: convertCharmMetrics(info.Metrics),
LXDProfile: convertCharmLXDProfile(info.LXDProfile),
}
return result, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"CharmInfo",
"(",
"charmURL",
"string",
")",
"(",
"*",
"CharmInfo",
",",
"error",
")",
"{",
"args",
":=",
"params",
".",
"CharmURL",
"{",
"URL",
":",
"charmURL",
"}",
"\n",
"var",
"info",
"params",
".",
"CharmInfo",
"\n",
"if",
"err",
":=",
"c",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"info",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"meta",
",",
"err",
":=",
"convertCharmMeta",
"(",
"info",
".",
"Meta",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"result",
":=",
"&",
"CharmInfo",
"{",
"Revision",
":",
"info",
".",
"Revision",
",",
"URL",
":",
"info",
".",
"URL",
",",
"Config",
":",
"convertCharmConfig",
"(",
"info",
".",
"Config",
")",
",",
"Meta",
":",
"meta",
",",
"Actions",
":",
"convertCharmActions",
"(",
"info",
".",
"Actions",
")",
",",
"Metrics",
":",
"convertCharmMetrics",
"(",
"info",
".",
"Metrics",
")",
",",
"LXDProfile",
":",
"convertCharmLXDProfile",
"(",
"info",
".",
"LXDProfile",
")",
",",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // CharmInfo returns information about the requested charm. | [
"CharmInfo",
"returns",
"information",
"about",
"the",
"requested",
"charm",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/charms/client.go#L51-L71 |
3,681 | juju/juju | cmd/juju/cloud/add.go | NewAddCloudCommand | func NewAddCloudCommand(cloudMetadataStore CloudMetadataStore) cmd.Command {
cloudCallCtx := context.NewCloudCallContext()
store := jujuclient.NewFileClientStore()
c := &AddCloudCommand{
OptionalControllerCommand: modelcmd.OptionalControllerCommand{Store: store},
cloudMetadataStore: cloudMetadataStore,
CloudCallCtx: cloudCallCtx,
// Ping is provider.Ping except in tests where we don't actually want to
// require a valid cloud.
Ping: func(p environs.EnvironProvider, endpoint string) error {
return p.Ping(cloudCallCtx, endpoint)
},
store: store,
}
c.addCloudAPIFunc = c.cloudAPI
return modelcmd.WrapBase(c)
} | go | func NewAddCloudCommand(cloudMetadataStore CloudMetadataStore) cmd.Command {
cloudCallCtx := context.NewCloudCallContext()
store := jujuclient.NewFileClientStore()
c := &AddCloudCommand{
OptionalControllerCommand: modelcmd.OptionalControllerCommand{Store: store},
cloudMetadataStore: cloudMetadataStore,
CloudCallCtx: cloudCallCtx,
// Ping is provider.Ping except in tests where we don't actually want to
// require a valid cloud.
Ping: func(p environs.EnvironProvider, endpoint string) error {
return p.Ping(cloudCallCtx, endpoint)
},
store: store,
}
c.addCloudAPIFunc = c.cloudAPI
return modelcmd.WrapBase(c)
} | [
"func",
"NewAddCloudCommand",
"(",
"cloudMetadataStore",
"CloudMetadataStore",
")",
"cmd",
".",
"Command",
"{",
"cloudCallCtx",
":=",
"context",
".",
"NewCloudCallContext",
"(",
")",
"\n",
"store",
":=",
"jujuclient",
".",
"NewFileClientStore",
"(",
")",
"\n",
"c",
":=",
"&",
"AddCloudCommand",
"{",
"OptionalControllerCommand",
":",
"modelcmd",
".",
"OptionalControllerCommand",
"{",
"Store",
":",
"store",
"}",
",",
"cloudMetadataStore",
":",
"cloudMetadataStore",
",",
"CloudCallCtx",
":",
"cloudCallCtx",
",",
"// Ping is provider.Ping except in tests where we don't actually want to",
"// require a valid cloud.",
"Ping",
":",
"func",
"(",
"p",
"environs",
".",
"EnvironProvider",
",",
"endpoint",
"string",
")",
"error",
"{",
"return",
"p",
".",
"Ping",
"(",
"cloudCallCtx",
",",
"endpoint",
")",
"\n",
"}",
",",
"store",
":",
"store",
",",
"}",
"\n",
"c",
".",
"addCloudAPIFunc",
"=",
"c",
".",
"cloudAPI",
"\n",
"return",
"modelcmd",
".",
"WrapBase",
"(",
"c",
")",
"\n",
"}"
] | // NewAddCloudCommand returns a command to add cloud information. | [
"NewAddCloudCommand",
"returns",
"a",
"command",
"to",
"add",
"cloud",
"information",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/cloud/add.go#L162-L178 |
3,682 | juju/juju | cmd/juju/cloud/add.go | Run | func (c *AddCloudCommand) Run(ctxt *cmd.Context) error {
if c.CloudFile == "" && c.controllerName == "" {
return c.runInteractive(ctxt)
}
var newCloud *jujucloud.Cloud
var err error
if c.CloudFile != "" {
newCloud, err = c.readCloudFromFile(ctxt)
} else {
// No cloud file specified so we try and use a named
// cloud that already has been added to the local cache.
newCloud, err = cloudFromLocal(c.Cloud)
}
if err != nil {
return errors.Trace(err)
}
if c.controllerName == "" {
if !c.Local {
ctxt.Infof(
"There are no controllers running.\nAdding cloud to local cache so you can use it to bootstrap a controller.\n")
}
return addLocalCloud(c.cloudMetadataStore, *newCloud)
}
// A controller has been specified so upload the cloud details
// plus a corresponding credential to the controller.
api, err := c.addCloudAPIFunc()
if err != nil {
return err
}
defer api.Close()
err = api.AddCloud(*newCloud)
if err != nil && params.ErrCode(err) != params.CodeAlreadyExists {
return err
}
// Add a credential for the newly added cloud.
err = c.addCredentialToController(ctxt, *newCloud, api)
if err != nil {
return err
}
ctxt.Infof("Cloud %q added to controller %q.", c.Cloud, c.controllerName)
return nil
} | go | func (c *AddCloudCommand) Run(ctxt *cmd.Context) error {
if c.CloudFile == "" && c.controllerName == "" {
return c.runInteractive(ctxt)
}
var newCloud *jujucloud.Cloud
var err error
if c.CloudFile != "" {
newCloud, err = c.readCloudFromFile(ctxt)
} else {
// No cloud file specified so we try and use a named
// cloud that already has been added to the local cache.
newCloud, err = cloudFromLocal(c.Cloud)
}
if err != nil {
return errors.Trace(err)
}
if c.controllerName == "" {
if !c.Local {
ctxt.Infof(
"There are no controllers running.\nAdding cloud to local cache so you can use it to bootstrap a controller.\n")
}
return addLocalCloud(c.cloudMetadataStore, *newCloud)
}
// A controller has been specified so upload the cloud details
// plus a corresponding credential to the controller.
api, err := c.addCloudAPIFunc()
if err != nil {
return err
}
defer api.Close()
err = api.AddCloud(*newCloud)
if err != nil && params.ErrCode(err) != params.CodeAlreadyExists {
return err
}
// Add a credential for the newly added cloud.
err = c.addCredentialToController(ctxt, *newCloud, api)
if err != nil {
return err
}
ctxt.Infof("Cloud %q added to controller %q.", c.Cloud, c.controllerName)
return nil
} | [
"func",
"(",
"c",
"*",
"AddCloudCommand",
")",
"Run",
"(",
"ctxt",
"*",
"cmd",
".",
"Context",
")",
"error",
"{",
"if",
"c",
".",
"CloudFile",
"==",
"\"",
"\"",
"&&",
"c",
".",
"controllerName",
"==",
"\"",
"\"",
"{",
"return",
"c",
".",
"runInteractive",
"(",
"ctxt",
")",
"\n",
"}",
"\n\n",
"var",
"newCloud",
"*",
"jujucloud",
".",
"Cloud",
"\n",
"var",
"err",
"error",
"\n",
"if",
"c",
".",
"CloudFile",
"!=",
"\"",
"\"",
"{",
"newCloud",
",",
"err",
"=",
"c",
".",
"readCloudFromFile",
"(",
"ctxt",
")",
"\n",
"}",
"else",
"{",
"// No cloud file specified so we try and use a named",
"// cloud that already has been added to the local cache.",
"newCloud",
",",
"err",
"=",
"cloudFromLocal",
"(",
"c",
".",
"Cloud",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"c",
".",
"controllerName",
"==",
"\"",
"\"",
"{",
"if",
"!",
"c",
".",
"Local",
"{",
"ctxt",
".",
"Infof",
"(",
"\"",
"\\n",
"\\n",
"\"",
")",
"\n",
"}",
"\n",
"return",
"addLocalCloud",
"(",
"c",
".",
"cloudMetadataStore",
",",
"*",
"newCloud",
")",
"\n",
"}",
"\n\n",
"// A controller has been specified so upload the cloud details",
"// plus a corresponding credential to the controller.",
"api",
",",
"err",
":=",
"c",
".",
"addCloudAPIFunc",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"api",
".",
"Close",
"(",
")",
"\n",
"err",
"=",
"api",
".",
"AddCloud",
"(",
"*",
"newCloud",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"params",
".",
"ErrCode",
"(",
"err",
")",
"!=",
"params",
".",
"CodeAlreadyExists",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// Add a credential for the newly added cloud.",
"err",
"=",
"c",
".",
"addCredentialToController",
"(",
"ctxt",
",",
"*",
"newCloud",
",",
"api",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"ctxt",
".",
"Infof",
"(",
"\"",
"\"",
",",
"c",
".",
"Cloud",
",",
"c",
".",
"controllerName",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Run executes the add cloud command, adding a cloud based on a passed-in yaml
// file or interactive queries. | [
"Run",
"executes",
"the",
"add",
"cloud",
"command",
"adding",
"a",
"cloud",
"based",
"on",
"a",
"passed",
"-",
"in",
"yaml",
"file",
"or",
"interactive",
"queries",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/cloud/add.go#L281-L325 |
3,683 | juju/juju | cmd/juju/cloud/add.go | addCertificate | func addCertificate(data []byte) (string, []byte, error) {
vals, err := ensureStringMaps(string(data))
if err != nil {
return "", nil, err
}
name, ok := vals[jujucloud.CertFilenameKey]
if !ok {
return "", nil, errors.NotFoundf("yaml has no certificate file")
}
filename := name.(string)
if ok && filename != "" {
out, err := ioutil.ReadFile(filename)
if err != nil {
return filename, nil, err
}
certificate := string(out)
if _, err := cert.ParseCert(certificate); err != nil {
return filename, nil, errors.Annotate(err, "bad cloud CA certificate")
}
vals["ca-certificates"] = []string{certificate}
} else {
return filename, nil, errors.NotFoundf("yaml has no certificate file")
}
alt, err := yaml.Marshal(vals)
return filename, alt, err
} | go | func addCertificate(data []byte) (string, []byte, error) {
vals, err := ensureStringMaps(string(data))
if err != nil {
return "", nil, err
}
name, ok := vals[jujucloud.CertFilenameKey]
if !ok {
return "", nil, errors.NotFoundf("yaml has no certificate file")
}
filename := name.(string)
if ok && filename != "" {
out, err := ioutil.ReadFile(filename)
if err != nil {
return filename, nil, err
}
certificate := string(out)
if _, err := cert.ParseCert(certificate); err != nil {
return filename, nil, errors.Annotate(err, "bad cloud CA certificate")
}
vals["ca-certificates"] = []string{certificate}
} else {
return filename, nil, errors.NotFoundf("yaml has no certificate file")
}
alt, err := yaml.Marshal(vals)
return filename, alt, err
} | [
"func",
"addCertificate",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"string",
",",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"vals",
",",
"err",
":=",
"ensureStringMaps",
"(",
"string",
"(",
"data",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"name",
",",
"ok",
":=",
"vals",
"[",
"jujucloud",
".",
"CertFilenameKey",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\"",
"\"",
",",
"nil",
",",
"errors",
".",
"NotFoundf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"filename",
":=",
"name",
".",
"(",
"string",
")",
"\n",
"if",
"ok",
"&&",
"filename",
"!=",
"\"",
"\"",
"{",
"out",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"filename",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"certificate",
":=",
"string",
"(",
"out",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"cert",
".",
"ParseCert",
"(",
"certificate",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"filename",
",",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"vals",
"[",
"\"",
"\"",
"]",
"=",
"[",
"]",
"string",
"{",
"certificate",
"}",
"\n\n",
"}",
"else",
"{",
"return",
"filename",
",",
"nil",
",",
"errors",
".",
"NotFoundf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"alt",
",",
"err",
":=",
"yaml",
".",
"Marshal",
"(",
"vals",
")",
"\n",
"return",
"filename",
",",
"alt",
",",
"err",
"\n",
"}"
] | // addCertificate reads the cloud certificate file if available and adds the contents
// to the byte slice with the appropriate key. A NotFound error is returned if
// a cloud.CertFilenameKey is not contained in the data, or the value is empty, this is
// not a fatal error. | [
"addCertificate",
"reads",
"the",
"cloud",
"certificate",
"file",
"if",
"available",
"and",
"adds",
"the",
"contents",
"to",
"the",
"byte",
"slice",
"with",
"the",
"appropriate",
"key",
".",
"A",
"NotFound",
"error",
"is",
"returned",
"if",
"a",
"cloud",
".",
"CertFilenameKey",
"is",
"not",
"contained",
"in",
"the",
"data",
"or",
"the",
"value",
"is",
"empty",
"this",
"is",
"not",
"a",
"fatal",
"error",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/cloud/add.go#L459-L485 |
3,684 | juju/juju | cmd/juju/cloud/add.go | addableCloudProviders | func addableCloudProviders() (providers []string, unsupported []string, _ error) {
allproviders := environs.RegisteredProviders()
for _, name := range allproviders {
provider, err := environs.Provider(name)
if err != nil {
// should be impossible
return nil, nil, errors.Trace(err)
}
if provider.CloudSchema() != nil {
providers = append(providers, name)
} else {
unsupported = append(unsupported, name)
}
}
sort.Strings(providers)
return providers, unsupported, nil
} | go | func addableCloudProviders() (providers []string, unsupported []string, _ error) {
allproviders := environs.RegisteredProviders()
for _, name := range allproviders {
provider, err := environs.Provider(name)
if err != nil {
// should be impossible
return nil, nil, errors.Trace(err)
}
if provider.CloudSchema() != nil {
providers = append(providers, name)
} else {
unsupported = append(unsupported, name)
}
}
sort.Strings(providers)
return providers, unsupported, nil
} | [
"func",
"addableCloudProviders",
"(",
")",
"(",
"providers",
"[",
"]",
"string",
",",
"unsupported",
"[",
"]",
"string",
",",
"_",
"error",
")",
"{",
"allproviders",
":=",
"environs",
".",
"RegisteredProviders",
"(",
")",
"\n",
"for",
"_",
",",
"name",
":=",
"range",
"allproviders",
"{",
"provider",
",",
"err",
":=",
"environs",
".",
"Provider",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// should be impossible",
"return",
"nil",
",",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"provider",
".",
"CloudSchema",
"(",
")",
"!=",
"nil",
"{",
"providers",
"=",
"append",
"(",
"providers",
",",
"name",
")",
"\n",
"}",
"else",
"{",
"unsupported",
"=",
"append",
"(",
"unsupported",
",",
"name",
")",
"\n",
"}",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"providers",
")",
"\n",
"return",
"providers",
",",
"unsupported",
",",
"nil",
"\n",
"}"
] | // addableCloudProviders returns the names of providers supported by add-cloud,
// and also the names of those which are not supported. | [
"addableCloudProviders",
"returns",
"the",
"names",
"of",
"providers",
"supported",
"by",
"add",
"-",
"cloud",
"and",
"also",
"the",
"names",
"of",
"those",
"which",
"are",
"not",
"supported",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/cloud/add.go#L561-L578 |
3,685 | juju/juju | cmd/juju/cloud/add.go | nameExists | func nameExists(name string, public map[string]jujucloud.Cloud) (string, error) {
if _, ok := public[name]; ok {
return fmt.Sprintf("%q is the name of a public cloud", name), nil
}
builtin, err := common.BuiltInClouds()
if err != nil {
return "", errors.Trace(err)
}
if _, ok := builtin[name]; ok {
return fmt.Sprintf("%q is the name of a built-in cloud", name), nil
}
return "", nil
} | go | func nameExists(name string, public map[string]jujucloud.Cloud) (string, error) {
if _, ok := public[name]; ok {
return fmt.Sprintf("%q is the name of a public cloud", name), nil
}
builtin, err := common.BuiltInClouds()
if err != nil {
return "", errors.Trace(err)
}
if _, ok := builtin[name]; ok {
return fmt.Sprintf("%q is the name of a built-in cloud", name), nil
}
return "", nil
} | [
"func",
"nameExists",
"(",
"name",
"string",
",",
"public",
"map",
"[",
"string",
"]",
"jujucloud",
".",
"Cloud",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"_",
",",
"ok",
":=",
"public",
"[",
"name",
"]",
";",
"ok",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"name",
")",
",",
"nil",
"\n",
"}",
"\n",
"builtin",
",",
"err",
":=",
"common",
".",
"BuiltInClouds",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"builtin",
"[",
"name",
"]",
";",
"ok",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"name",
")",
",",
"nil",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"nil",
"\n",
"}"
] | // nameExists returns either an empty string if the name does not exist, or a
// non-empty string with an error message if it does exist. | [
"nameExists",
"returns",
"either",
"an",
"empty",
"string",
"if",
"the",
"name",
"does",
"not",
"exist",
"or",
"a",
"non",
"-",
"empty",
"string",
"with",
"an",
"error",
"message",
"if",
"it",
"does",
"exist",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/cloud/add.go#L693-L705 |
3,686 | juju/juju | apiserver/facades/agent/migrationflag/facade.go | New | func New(backend Backend, resources facade.Resources, auth facade.Authorizer) (*Facade, error) {
if !auth.AuthMachineAgent() && !auth.AuthUnitAgent() && !auth.AuthApplicationAgent() {
return nil, common.ErrPerm
}
return &Facade{
backend: backend,
resources: resources,
}, nil
} | go | func New(backend Backend, resources facade.Resources, auth facade.Authorizer) (*Facade, error) {
if !auth.AuthMachineAgent() && !auth.AuthUnitAgent() && !auth.AuthApplicationAgent() {
return nil, common.ErrPerm
}
return &Facade{
backend: backend,
resources: resources,
}, nil
} | [
"func",
"New",
"(",
"backend",
"Backend",
",",
"resources",
"facade",
".",
"Resources",
",",
"auth",
"facade",
".",
"Authorizer",
")",
"(",
"*",
"Facade",
",",
"error",
")",
"{",
"if",
"!",
"auth",
".",
"AuthMachineAgent",
"(",
")",
"&&",
"!",
"auth",
".",
"AuthUnitAgent",
"(",
")",
"&&",
"!",
"auth",
".",
"AuthApplicationAgent",
"(",
")",
"{",
"return",
"nil",
",",
"common",
".",
"ErrPerm",
"\n",
"}",
"\n",
"return",
"&",
"Facade",
"{",
"backend",
":",
"backend",
",",
"resources",
":",
"resources",
",",
"}",
",",
"nil",
"\n",
"}"
] | // New creates a Facade backed by backend and resources. If auth
// doesn't identity the client as a machine agent or a unit agent,
// it will return common.ErrPerm. | [
"New",
"creates",
"a",
"Facade",
"backed",
"by",
"backend",
"and",
"resources",
".",
"If",
"auth",
"doesn",
"t",
"identity",
"the",
"client",
"as",
"a",
"machine",
"agent",
"or",
"a",
"unit",
"agent",
"it",
"will",
"return",
"common",
".",
"ErrPerm",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/migrationflag/facade.go#L34-L42 |
3,687 | juju/juju | apiserver/facades/agent/migrationflag/facade.go | Phase | func (facade *Facade) Phase(entities params.Entities) params.PhaseResults {
count := len(entities.Entities)
results := params.PhaseResults{
Results: make([]params.PhaseResult, count),
}
for i, entity := range entities.Entities {
phase, err := facade.onePhase(entity.Tag)
results.Results[i].Phase = phase
results.Results[i].Error = common.ServerError(err)
}
return results
} | go | func (facade *Facade) Phase(entities params.Entities) params.PhaseResults {
count := len(entities.Entities)
results := params.PhaseResults{
Results: make([]params.PhaseResult, count),
}
for i, entity := range entities.Entities {
phase, err := facade.onePhase(entity.Tag)
results.Results[i].Phase = phase
results.Results[i].Error = common.ServerError(err)
}
return results
} | [
"func",
"(",
"facade",
"*",
"Facade",
")",
"Phase",
"(",
"entities",
"params",
".",
"Entities",
")",
"params",
".",
"PhaseResults",
"{",
"count",
":=",
"len",
"(",
"entities",
".",
"Entities",
")",
"\n",
"results",
":=",
"params",
".",
"PhaseResults",
"{",
"Results",
":",
"make",
"(",
"[",
"]",
"params",
".",
"PhaseResult",
",",
"count",
")",
",",
"}",
"\n",
"for",
"i",
",",
"entity",
":=",
"range",
"entities",
".",
"Entities",
"{",
"phase",
",",
"err",
":=",
"facade",
".",
"onePhase",
"(",
"entity",
".",
"Tag",
")",
"\n",
"results",
".",
"Results",
"[",
"i",
"]",
".",
"Phase",
"=",
"phase",
"\n",
"results",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"results",
"\n",
"}"
] | // Phase returns the current migration phase or an error for every
// supplied entity. | [
"Phase",
"returns",
"the",
"current",
"migration",
"phase",
"or",
"an",
"error",
"for",
"every",
"supplied",
"entity",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/migrationflag/facade.go#L59-L70 |
3,688 | juju/juju | apiserver/facades/agent/migrationflag/facade.go | onePhase | func (facade *Facade) onePhase(tagString string) (string, error) {
if err := facade.auth(tagString); err != nil {
return "", errors.Trace(err)
}
phase, err := facade.backend.MigrationPhase()
if err != nil {
return "", errors.Trace(err)
}
return phase.String(), nil
} | go | func (facade *Facade) onePhase(tagString string) (string, error) {
if err := facade.auth(tagString); err != nil {
return "", errors.Trace(err)
}
phase, err := facade.backend.MigrationPhase()
if err != nil {
return "", errors.Trace(err)
}
return phase.String(), nil
} | [
"func",
"(",
"facade",
"*",
"Facade",
")",
"onePhase",
"(",
"tagString",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"err",
":=",
"facade",
".",
"auth",
"(",
"tagString",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"phase",
",",
"err",
":=",
"facade",
".",
"backend",
".",
"MigrationPhase",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"phase",
".",
"String",
"(",
")",
",",
"nil",
"\n",
"}"
] | // onePhase does auth and lookup for a single entity. | [
"onePhase",
"does",
"auth",
"and",
"lookup",
"for",
"a",
"single",
"entity",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/migrationflag/facade.go#L73-L82 |
3,689 | juju/juju | apiserver/facades/agent/migrationflag/facade.go | Watch | func (facade *Facade) Watch(entities params.Entities) params.NotifyWatchResults {
count := len(entities.Entities)
results := params.NotifyWatchResults{
Results: make([]params.NotifyWatchResult, count),
}
for i, entity := range entities.Entities {
id, err := facade.oneWatch(entity.Tag)
results.Results[i].NotifyWatcherId = id
results.Results[i].Error = common.ServerError(err)
}
return results
} | go | func (facade *Facade) Watch(entities params.Entities) params.NotifyWatchResults {
count := len(entities.Entities)
results := params.NotifyWatchResults{
Results: make([]params.NotifyWatchResult, count),
}
for i, entity := range entities.Entities {
id, err := facade.oneWatch(entity.Tag)
results.Results[i].NotifyWatcherId = id
results.Results[i].Error = common.ServerError(err)
}
return results
} | [
"func",
"(",
"facade",
"*",
"Facade",
")",
"Watch",
"(",
"entities",
"params",
".",
"Entities",
")",
"params",
".",
"NotifyWatchResults",
"{",
"count",
":=",
"len",
"(",
"entities",
".",
"Entities",
")",
"\n",
"results",
":=",
"params",
".",
"NotifyWatchResults",
"{",
"Results",
":",
"make",
"(",
"[",
"]",
"params",
".",
"NotifyWatchResult",
",",
"count",
")",
",",
"}",
"\n",
"for",
"i",
",",
"entity",
":=",
"range",
"entities",
".",
"Entities",
"{",
"id",
",",
"err",
":=",
"facade",
".",
"oneWatch",
"(",
"entity",
".",
"Tag",
")",
"\n",
"results",
".",
"Results",
"[",
"i",
"]",
".",
"NotifyWatcherId",
"=",
"id",
"\n",
"results",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"results",
"\n",
"}"
] | // Watch returns an id for use with the NotifyWatcher facade, or an
// error, for every supplied entity. | [
"Watch",
"returns",
"an",
"id",
"for",
"use",
"with",
"the",
"NotifyWatcher",
"facade",
"or",
"an",
"error",
"for",
"every",
"supplied",
"entity",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/migrationflag/facade.go#L86-L97 |
3,690 | juju/juju | worker/metrics/collect/manifold.go | Manifold | func Manifold(config ManifoldConfig) dependency.Manifold {
return dependency.Manifold{
Inputs: []string{
config.AgentName,
config.MetricSpoolName,
config.CharmDirName,
},
Start: func(context dependency.Context) (worker.Worker, error) {
collector, err := newCollect(config, context)
if err != nil {
return nil, err
}
return spool.NewPeriodicWorker(collector.Do, collector.period, jworker.NewTimer, collector.stop), nil
},
}
} | go | func Manifold(config ManifoldConfig) dependency.Manifold {
return dependency.Manifold{
Inputs: []string{
config.AgentName,
config.MetricSpoolName,
config.CharmDirName,
},
Start: func(context dependency.Context) (worker.Worker, error) {
collector, err := newCollect(config, context)
if err != nil {
return nil, err
}
return spool.NewPeriodicWorker(collector.Do, collector.period, jworker.NewTimer, collector.stop), nil
},
}
} | [
"func",
"Manifold",
"(",
"config",
"ManifoldConfig",
")",
"dependency",
".",
"Manifold",
"{",
"return",
"dependency",
".",
"Manifold",
"{",
"Inputs",
":",
"[",
"]",
"string",
"{",
"config",
".",
"AgentName",
",",
"config",
".",
"MetricSpoolName",
",",
"config",
".",
"CharmDirName",
",",
"}",
",",
"Start",
":",
"func",
"(",
"context",
"dependency",
".",
"Context",
")",
"(",
"worker",
".",
"Worker",
",",
"error",
")",
"{",
"collector",
",",
"err",
":=",
"newCollect",
"(",
"config",
",",
"context",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"spool",
".",
"NewPeriodicWorker",
"(",
"collector",
".",
"Do",
",",
"collector",
".",
"period",
",",
"jworker",
".",
"NewTimer",
",",
"collector",
".",
"stop",
")",
",",
"nil",
"\n",
"}",
",",
"}",
"\n",
"}"
] | // Manifold returns a collect-metrics manifold. | [
"Manifold",
"returns",
"a",
"collect",
"-",
"metrics",
"manifold",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/metrics/collect/manifold.go#L97-L112 |
3,691 | juju/juju | worker/metrics/collect/manifold.go | Do | func (w *collect) Do(stop <-chan struct{}) (err error) {
defer func() {
// See bug https://pad/lv/1733469
// If this function which is run by a PeriodicWorker
// exits with an error, we need to call stop() to
// ensure the listener socket is closed.
if err != nil {
w.stop()
}
}()
config := w.agent.CurrentConfig()
tag := config.Tag()
unitTag, ok := tag.(names.UnitTag)
if !ok {
return errors.Errorf("expected a unit tag, got %v", tag)
}
paths := uniter.NewWorkerPaths(config.DataDir(), unitTag, "metrics-collect")
recorder, err := newRecorder(unitTag, paths, w.metricFactory)
if errors.Cause(err) == errMetricsNotDefined {
logger.Tracef("%v", err)
return nil
} else if err != nil {
return errors.Annotate(err, "failed to instantiate metric recorder")
}
err = w.charmdir.Visit(func() error {
return w.runner.do(recorder)
}, stop)
if err == fortress.ErrAborted {
logger.Tracef("cannot execute collect-metrics: %v", err)
return nil
}
if spool.IsMetricsDataError(err) {
logger.Debugf("cannot record metrics: %v", err)
return nil
}
return err
} | go | func (w *collect) Do(stop <-chan struct{}) (err error) {
defer func() {
// See bug https://pad/lv/1733469
// If this function which is run by a PeriodicWorker
// exits with an error, we need to call stop() to
// ensure the listener socket is closed.
if err != nil {
w.stop()
}
}()
config := w.agent.CurrentConfig()
tag := config.Tag()
unitTag, ok := tag.(names.UnitTag)
if !ok {
return errors.Errorf("expected a unit tag, got %v", tag)
}
paths := uniter.NewWorkerPaths(config.DataDir(), unitTag, "metrics-collect")
recorder, err := newRecorder(unitTag, paths, w.metricFactory)
if errors.Cause(err) == errMetricsNotDefined {
logger.Tracef("%v", err)
return nil
} else if err != nil {
return errors.Annotate(err, "failed to instantiate metric recorder")
}
err = w.charmdir.Visit(func() error {
return w.runner.do(recorder)
}, stop)
if err == fortress.ErrAborted {
logger.Tracef("cannot execute collect-metrics: %v", err)
return nil
}
if spool.IsMetricsDataError(err) {
logger.Debugf("cannot record metrics: %v", err)
return nil
}
return err
} | [
"func",
"(",
"w",
"*",
"collect",
")",
"Do",
"(",
"stop",
"<-",
"chan",
"struct",
"{",
"}",
")",
"(",
"err",
"error",
")",
"{",
"defer",
"func",
"(",
")",
"{",
"// See bug https://pad/lv/1733469",
"// If this function which is run by a PeriodicWorker",
"// exits with an error, we need to call stop() to",
"// ensure the listener socket is closed.",
"if",
"err",
"!=",
"nil",
"{",
"w",
".",
"stop",
"(",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"config",
":=",
"w",
".",
"agent",
".",
"CurrentConfig",
"(",
")",
"\n",
"tag",
":=",
"config",
".",
"Tag",
"(",
")",
"\n",
"unitTag",
",",
"ok",
":=",
"tag",
".",
"(",
"names",
".",
"UnitTag",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tag",
")",
"\n",
"}",
"\n",
"paths",
":=",
"uniter",
".",
"NewWorkerPaths",
"(",
"config",
".",
"DataDir",
"(",
")",
",",
"unitTag",
",",
"\"",
"\"",
")",
"\n\n",
"recorder",
",",
"err",
":=",
"newRecorder",
"(",
"unitTag",
",",
"paths",
",",
"w",
".",
"metricFactory",
")",
"\n",
"if",
"errors",
".",
"Cause",
"(",
"err",
")",
"==",
"errMetricsNotDefined",
"{",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"err",
"=",
"w",
".",
"charmdir",
".",
"Visit",
"(",
"func",
"(",
")",
"error",
"{",
"return",
"w",
".",
"runner",
".",
"do",
"(",
"recorder",
")",
"\n",
"}",
",",
"stop",
")",
"\n",
"if",
"err",
"==",
"fortress",
".",
"ErrAborted",
"{",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"spool",
".",
"IsMetricsDataError",
"(",
"err",
")",
"{",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // Do satisfies the worker.PeriodWorkerCall function type. | [
"Do",
"satisfies",
"the",
"worker",
".",
"PeriodWorkerCall",
"function",
"type",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/metrics/collect/manifold.go#L208-L247 |
3,692 | juju/juju | apiserver/facades/agent/credentialvalidator/credentialvalidator.go | NewCredentialValidatorAPI | func NewCredentialValidatorAPI(ctx facade.Context) (*CredentialValidatorAPI, error) {
return internalNewCredentialValidatorAPI(NewBackend(NewStateShim(ctx.State())), ctx.Resources(), ctx.Auth())
} | go | func NewCredentialValidatorAPI(ctx facade.Context) (*CredentialValidatorAPI, error) {
return internalNewCredentialValidatorAPI(NewBackend(NewStateShim(ctx.State())), ctx.Resources(), ctx.Auth())
} | [
"func",
"NewCredentialValidatorAPI",
"(",
"ctx",
"facade",
".",
"Context",
")",
"(",
"*",
"CredentialValidatorAPI",
",",
"error",
")",
"{",
"return",
"internalNewCredentialValidatorAPI",
"(",
"NewBackend",
"(",
"NewStateShim",
"(",
"ctx",
".",
"State",
"(",
")",
")",
")",
",",
"ctx",
".",
"Resources",
"(",
")",
",",
"ctx",
".",
"Auth",
"(",
")",
")",
"\n",
"}"
] | // NewCredentialValidatorAPI creates a new CredentialValidator API endpoint on server-side. | [
"NewCredentialValidatorAPI",
"creates",
"a",
"new",
"CredentialValidator",
"API",
"endpoint",
"on",
"server",
"-",
"side",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/credentialvalidator/credentialvalidator.go#L53-L55 |
3,693 | juju/juju | apiserver/facades/agent/credentialvalidator/credentialvalidator.go | NewCredentialValidatorAPIv1 | func NewCredentialValidatorAPIv1(ctx facade.Context) (*CredentialValidatorAPIV1, error) {
v2, err := NewCredentialValidatorAPI(ctx)
if err != nil {
return nil, err
}
return &CredentialValidatorAPIV1{v2}, nil
} | go | func NewCredentialValidatorAPIv1(ctx facade.Context) (*CredentialValidatorAPIV1, error) {
v2, err := NewCredentialValidatorAPI(ctx)
if err != nil {
return nil, err
}
return &CredentialValidatorAPIV1{v2}, nil
} | [
"func",
"NewCredentialValidatorAPIv1",
"(",
"ctx",
"facade",
".",
"Context",
")",
"(",
"*",
"CredentialValidatorAPIV1",
",",
"error",
")",
"{",
"v2",
",",
"err",
":=",
"NewCredentialValidatorAPI",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"CredentialValidatorAPIV1",
"{",
"v2",
"}",
",",
"nil",
"\n",
"}"
] | // NewCredentialValidatorAPIv1 creates a new CredentialValidator API endpoint on server-side. | [
"NewCredentialValidatorAPIv1",
"creates",
"a",
"new",
"CredentialValidator",
"API",
"endpoint",
"on",
"server",
"-",
"side",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/credentialvalidator/credentialvalidator.go#L58-L64 |
3,694 | juju/juju | apiserver/facades/agent/credentialvalidator/credentialvalidator.go | WatchCredential | func (api *CredentialValidatorAPI) WatchCredential(tag params.Entity) (params.NotifyWatchResult, error) {
fail := func(failure error) (params.NotifyWatchResult, error) {
return params.NotifyWatchResult{}, common.ServerError(failure)
}
credentialTag, err := names.ParseCloudCredentialTag(tag.Tag)
if err != nil {
return fail(err)
}
// Is credential used by the model that has created this backend?
isUsed, err := api.backend.ModelUsesCredential(credentialTag)
if err != nil {
return fail(err)
}
if !isUsed {
return fail(common.ErrPerm)
}
result := params.NotifyWatchResult{}
watch := api.backend.WatchCredential(credentialTag)
// Consume the initial event. Technically, API calls to Watch
// 'transmit' the initial event in the Watch response. But
// NotifyWatchers have no state to transmit.
if _, ok := <-watch.Changes(); ok {
result.NotifyWatcherId = api.resources.Register(watch)
} else {
err = watcher.EnsureErr(watch)
result.Error = common.ServerError(err)
}
return result, nil
} | go | func (api *CredentialValidatorAPI) WatchCredential(tag params.Entity) (params.NotifyWatchResult, error) {
fail := func(failure error) (params.NotifyWatchResult, error) {
return params.NotifyWatchResult{}, common.ServerError(failure)
}
credentialTag, err := names.ParseCloudCredentialTag(tag.Tag)
if err != nil {
return fail(err)
}
// Is credential used by the model that has created this backend?
isUsed, err := api.backend.ModelUsesCredential(credentialTag)
if err != nil {
return fail(err)
}
if !isUsed {
return fail(common.ErrPerm)
}
result := params.NotifyWatchResult{}
watch := api.backend.WatchCredential(credentialTag)
// Consume the initial event. Technically, API calls to Watch
// 'transmit' the initial event in the Watch response. But
// NotifyWatchers have no state to transmit.
if _, ok := <-watch.Changes(); ok {
result.NotifyWatcherId = api.resources.Register(watch)
} else {
err = watcher.EnsureErr(watch)
result.Error = common.ServerError(err)
}
return result, nil
} | [
"func",
"(",
"api",
"*",
"CredentialValidatorAPI",
")",
"WatchCredential",
"(",
"tag",
"params",
".",
"Entity",
")",
"(",
"params",
".",
"NotifyWatchResult",
",",
"error",
")",
"{",
"fail",
":=",
"func",
"(",
"failure",
"error",
")",
"(",
"params",
".",
"NotifyWatchResult",
",",
"error",
")",
"{",
"return",
"params",
".",
"NotifyWatchResult",
"{",
"}",
",",
"common",
".",
"ServerError",
"(",
"failure",
")",
"\n",
"}",
"\n\n",
"credentialTag",
",",
"err",
":=",
"names",
".",
"ParseCloudCredentialTag",
"(",
"tag",
".",
"Tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fail",
"(",
"err",
")",
"\n",
"}",
"\n",
"// Is credential used by the model that has created this backend?",
"isUsed",
",",
"err",
":=",
"api",
".",
"backend",
".",
"ModelUsesCredential",
"(",
"credentialTag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fail",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"!",
"isUsed",
"{",
"return",
"fail",
"(",
"common",
".",
"ErrPerm",
")",
"\n",
"}",
"\n\n",
"result",
":=",
"params",
".",
"NotifyWatchResult",
"{",
"}",
"\n",
"watch",
":=",
"api",
".",
"backend",
".",
"WatchCredential",
"(",
"credentialTag",
")",
"\n",
"// Consume the initial event. Technically, API calls to Watch",
"// 'transmit' the initial event in the Watch response. But",
"// NotifyWatchers have no state to transmit.",
"if",
"_",
",",
"ok",
":=",
"<-",
"watch",
".",
"Changes",
"(",
")",
";",
"ok",
"{",
"result",
".",
"NotifyWatcherId",
"=",
"api",
".",
"resources",
".",
"Register",
"(",
"watch",
")",
"\n",
"}",
"else",
"{",
"err",
"=",
"watcher",
".",
"EnsureErr",
"(",
"watch",
")",
"\n",
"result",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // WatchCredential returns a NotifyWatcher that observes
// changes to a given cloud credential. | [
"WatchCredential",
"returns",
"a",
"NotifyWatcher",
"that",
"observes",
"changes",
"to",
"a",
"given",
"cloud",
"credential",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/credentialvalidator/credentialvalidator.go#L80-L110 |
3,695 | juju/juju | apiserver/facades/agent/credentialvalidator/credentialvalidator.go | ModelCredential | func (api *CredentialValidatorAPI) ModelCredential() (params.ModelCredential, error) {
c, err := api.backend.ModelCredential()
if err != nil {
return params.ModelCredential{}, common.ServerError(err)
}
return params.ModelCredential{
Model: c.Model.String(),
CloudCredential: c.Credential.String(),
Exists: c.Exists,
Valid: c.Valid,
}, nil
} | go | func (api *CredentialValidatorAPI) ModelCredential() (params.ModelCredential, error) {
c, err := api.backend.ModelCredential()
if err != nil {
return params.ModelCredential{}, common.ServerError(err)
}
return params.ModelCredential{
Model: c.Model.String(),
CloudCredential: c.Credential.String(),
Exists: c.Exists,
Valid: c.Valid,
}, nil
} | [
"func",
"(",
"api",
"*",
"CredentialValidatorAPI",
")",
"ModelCredential",
"(",
")",
"(",
"params",
".",
"ModelCredential",
",",
"error",
")",
"{",
"c",
",",
"err",
":=",
"api",
".",
"backend",
".",
"ModelCredential",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"params",
".",
"ModelCredential",
"{",
"}",
",",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"params",
".",
"ModelCredential",
"{",
"Model",
":",
"c",
".",
"Model",
".",
"String",
"(",
")",
",",
"CloudCredential",
":",
"c",
".",
"Credential",
".",
"String",
"(",
")",
",",
"Exists",
":",
"c",
".",
"Exists",
",",
"Valid",
":",
"c",
".",
"Valid",
",",
"}",
",",
"nil",
"\n",
"}"
] | // ModelCredential returns cloud credential information for a model. | [
"ModelCredential",
"returns",
"cloud",
"credential",
"information",
"for",
"a",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/credentialvalidator/credentialvalidator.go#L113-L125 |
3,696 | juju/juju | apiserver/facades/agent/credentialvalidator/credentialvalidator.go | WatchModelCredential | func (api *CredentialValidatorAPI) WatchModelCredential() (params.NotifyWatchResult, error) {
result := params.NotifyWatchResult{}
watch, err := api.backend.WatchModelCredential()
if err != nil {
return result, common.ServerError(err)
}
// Consume the initial event. Technically, API calls to Watch
// 'transmit' the initial event in the Watch response. But
// NotifyWatchers have no state to transmit.
if _, ok := <-watch.Changes(); ok {
result.NotifyWatcherId = api.resources.Register(watch)
} else {
err = watcher.EnsureErr(watch)
result.Error = common.ServerError(err)
}
return result, nil
} | go | func (api *CredentialValidatorAPI) WatchModelCredential() (params.NotifyWatchResult, error) {
result := params.NotifyWatchResult{}
watch, err := api.backend.WatchModelCredential()
if err != nil {
return result, common.ServerError(err)
}
// Consume the initial event. Technically, API calls to Watch
// 'transmit' the initial event in the Watch response. But
// NotifyWatchers have no state to transmit.
if _, ok := <-watch.Changes(); ok {
result.NotifyWatcherId = api.resources.Register(watch)
} else {
err = watcher.EnsureErr(watch)
result.Error = common.ServerError(err)
}
return result, nil
} | [
"func",
"(",
"api",
"*",
"CredentialValidatorAPI",
")",
"WatchModelCredential",
"(",
")",
"(",
"params",
".",
"NotifyWatchResult",
",",
"error",
")",
"{",
"result",
":=",
"params",
".",
"NotifyWatchResult",
"{",
"}",
"\n",
"watch",
",",
"err",
":=",
"api",
".",
"backend",
".",
"WatchModelCredential",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"result",
",",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"// Consume the initial event. Technically, API calls to Watch",
"// 'transmit' the initial event in the Watch response. But",
"// NotifyWatchers have no state to transmit.",
"if",
"_",
",",
"ok",
":=",
"<-",
"watch",
".",
"Changes",
"(",
")",
";",
"ok",
"{",
"result",
".",
"NotifyWatcherId",
"=",
"api",
".",
"resources",
".",
"Register",
"(",
"watch",
")",
"\n",
"}",
"else",
"{",
"err",
"=",
"watcher",
".",
"EnsureErr",
"(",
"watch",
")",
"\n",
"result",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // WatchModelCredential returns a NotifyWatcher that watches what cloud credential a model uses. | [
"WatchModelCredential",
"returns",
"a",
"NotifyWatcher",
"that",
"watches",
"what",
"cloud",
"credential",
"a",
"model",
"uses",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/credentialvalidator/credentialvalidator.go#L135-L152 |
3,697 | juju/juju | apiserver/facades/controller/caasunitprovisioner/provisioner.go | NewFacade | func NewFacade(
resources facade.Resources,
authorizer facade.Authorizer,
st CAASUnitProvisionerState,
sb StorageBackend,
db DeviceBackend,
storagePoolManager poolmanager.PoolManager,
registry storage.ProviderRegistry,
clock clock.Clock,
) (*Facade, error) {
if !authorizer.AuthController() {
return nil, common.ErrPerm
}
return &Facade{
LifeGetter: common.NewLifeGetter(
st, common.AuthAny(
common.AuthFuncForTagKind(names.ApplicationTagKind),
common.AuthFuncForTagKind(names.UnitTagKind),
),
),
resources: resources,
state: st,
storage: sb,
devices: db,
storagePoolManager: storagePoolManager,
registry: registry,
clock: clock,
}, nil
} | go | func NewFacade(
resources facade.Resources,
authorizer facade.Authorizer,
st CAASUnitProvisionerState,
sb StorageBackend,
db DeviceBackend,
storagePoolManager poolmanager.PoolManager,
registry storage.ProviderRegistry,
clock clock.Clock,
) (*Facade, error) {
if !authorizer.AuthController() {
return nil, common.ErrPerm
}
return &Facade{
LifeGetter: common.NewLifeGetter(
st, common.AuthAny(
common.AuthFuncForTagKind(names.ApplicationTagKind),
common.AuthFuncForTagKind(names.UnitTagKind),
),
),
resources: resources,
state: st,
storage: sb,
devices: db,
storagePoolManager: storagePoolManager,
registry: registry,
clock: clock,
}, nil
} | [
"func",
"NewFacade",
"(",
"resources",
"facade",
".",
"Resources",
",",
"authorizer",
"facade",
".",
"Authorizer",
",",
"st",
"CAASUnitProvisionerState",
",",
"sb",
"StorageBackend",
",",
"db",
"DeviceBackend",
",",
"storagePoolManager",
"poolmanager",
".",
"PoolManager",
",",
"registry",
"storage",
".",
"ProviderRegistry",
",",
"clock",
"clock",
".",
"Clock",
",",
")",
"(",
"*",
"Facade",
",",
"error",
")",
"{",
"if",
"!",
"authorizer",
".",
"AuthController",
"(",
")",
"{",
"return",
"nil",
",",
"common",
".",
"ErrPerm",
"\n",
"}",
"\n",
"return",
"&",
"Facade",
"{",
"LifeGetter",
":",
"common",
".",
"NewLifeGetter",
"(",
"st",
",",
"common",
".",
"AuthAny",
"(",
"common",
".",
"AuthFuncForTagKind",
"(",
"names",
".",
"ApplicationTagKind",
")",
",",
"common",
".",
"AuthFuncForTagKind",
"(",
"names",
".",
"UnitTagKind",
")",
",",
")",
",",
")",
",",
"resources",
":",
"resources",
",",
"state",
":",
"st",
",",
"storage",
":",
"sb",
",",
"devices",
":",
"db",
",",
"storagePoolManager",
":",
"storagePoolManager",
",",
"registry",
":",
"registry",
",",
"clock",
":",
"clock",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewFacade returns a new CAAS unit provisioner Facade facade. | [
"NewFacade",
"returns",
"a",
"new",
"CAAS",
"unit",
"provisioner",
"Facade",
"facade",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/controller/caasunitprovisioner/provisioner.go#L81-L109 |
3,698 | juju/juju | apiserver/facades/controller/caasunitprovisioner/provisioner.go | WatchApplicationsScale | func (f *Facade) WatchApplicationsScale(args params.Entities) (params.NotifyWatchResults, error) {
results := params.NotifyWatchResults{
Results: make([]params.NotifyWatchResult, len(args.Entities)),
}
for i, arg := range args.Entities {
id, err := f.watchApplicationScale(arg.Tag)
if err != nil {
results.Results[i].Error = common.ServerError(err)
continue
}
results.Results[i].NotifyWatcherId = id
}
return results, nil
} | go | func (f *Facade) WatchApplicationsScale(args params.Entities) (params.NotifyWatchResults, error) {
results := params.NotifyWatchResults{
Results: make([]params.NotifyWatchResult, len(args.Entities)),
}
for i, arg := range args.Entities {
id, err := f.watchApplicationScale(arg.Tag)
if err != nil {
results.Results[i].Error = common.ServerError(err)
continue
}
results.Results[i].NotifyWatcherId = id
}
return results, nil
} | [
"func",
"(",
"f",
"*",
"Facade",
")",
"WatchApplicationsScale",
"(",
"args",
"params",
".",
"Entities",
")",
"(",
"params",
".",
"NotifyWatchResults",
",",
"error",
")",
"{",
"results",
":=",
"params",
".",
"NotifyWatchResults",
"{",
"Results",
":",
"make",
"(",
"[",
"]",
"params",
".",
"NotifyWatchResult",
",",
"len",
"(",
"args",
".",
"Entities",
")",
")",
",",
"}",
"\n",
"for",
"i",
",",
"arg",
":=",
"range",
"args",
".",
"Entities",
"{",
"id",
",",
"err",
":=",
"f",
".",
"watchApplicationScale",
"(",
"arg",
".",
"Tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"results",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"results",
".",
"Results",
"[",
"i",
"]",
".",
"NotifyWatcherId",
"=",
"id",
"\n",
"}",
"\n",
"return",
"results",
",",
"nil",
"\n",
"}"
] | // WatchApplicationsScale starts a NotifyWatcher to watch changes
// to the applications' scale. | [
"WatchApplicationsScale",
"starts",
"a",
"NotifyWatcher",
"to",
"watch",
"changes",
"to",
"the",
"applications",
"scale",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/controller/caasunitprovisioner/provisioner.go#L126-L139 |
3,699 | juju/juju | apiserver/facades/controller/caasunitprovisioner/provisioner.go | WatchPodSpec | func (f *Facade) WatchPodSpec(args params.Entities) (params.NotifyWatchResults, error) {
model, err := f.state.Model()
if err != nil {
return params.NotifyWatchResults{}, errors.Trace(err)
}
results := params.NotifyWatchResults{
Results: make([]params.NotifyWatchResult, len(args.Entities)),
}
for i, arg := range args.Entities {
id, err := f.watchPodSpec(model, arg.Tag)
if err != nil {
results.Results[i].Error = common.ServerError(err)
continue
}
results.Results[i].NotifyWatcherId = id
}
return results, nil
} | go | func (f *Facade) WatchPodSpec(args params.Entities) (params.NotifyWatchResults, error) {
model, err := f.state.Model()
if err != nil {
return params.NotifyWatchResults{}, errors.Trace(err)
}
results := params.NotifyWatchResults{
Results: make([]params.NotifyWatchResult, len(args.Entities)),
}
for i, arg := range args.Entities {
id, err := f.watchPodSpec(model, arg.Tag)
if err != nil {
results.Results[i].Error = common.ServerError(err)
continue
}
results.Results[i].NotifyWatcherId = id
}
return results, nil
} | [
"func",
"(",
"f",
"*",
"Facade",
")",
"WatchPodSpec",
"(",
"args",
"params",
".",
"Entities",
")",
"(",
"params",
".",
"NotifyWatchResults",
",",
"error",
")",
"{",
"model",
",",
"err",
":=",
"f",
".",
"state",
".",
"Model",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"params",
".",
"NotifyWatchResults",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"results",
":=",
"params",
".",
"NotifyWatchResults",
"{",
"Results",
":",
"make",
"(",
"[",
"]",
"params",
".",
"NotifyWatchResult",
",",
"len",
"(",
"args",
".",
"Entities",
")",
")",
",",
"}",
"\n",
"for",
"i",
",",
"arg",
":=",
"range",
"args",
".",
"Entities",
"{",
"id",
",",
"err",
":=",
"f",
".",
"watchPodSpec",
"(",
"model",
",",
"arg",
".",
"Tag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"results",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"results",
".",
"Results",
"[",
"i",
"]",
".",
"NotifyWatcherId",
"=",
"id",
"\n",
"}",
"\n",
"return",
"results",
",",
"nil",
"\n",
"}"
] | // WatchPodSpec starts a NotifyWatcher to watch changes to the
// pod spec for specified units in this model. | [
"WatchPodSpec",
"starts",
"a",
"NotifyWatcher",
"to",
"watch",
"changes",
"to",
"the",
"pod",
"spec",
"for",
"specified",
"units",
"in",
"this",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/controller/caasunitprovisioner/provisioner.go#L159-L176 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.